{"record":{"id":"9e5ad95c5b9b4d59","repo":"microsoft/garnet","slug":"max-inline-key-size-is-1-logsettings-kmaxstrin","errorCode":null,"errorMessage":"Max inline key size is {1 << LogSettings.kMaxStringSizeBits}","messagePattern":"Max inline key size is (.+?)","errorType":"exception","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/Allocator/SpanByteAllocatorImpl.cs","lineNumber":187,"sourceCode":"                    HasETag = false,\n                    HasExpiration = false\n                }\n            };\n            PopulateRecordSizeInfo(ref sizeInfo);\n            return sizeInfo;\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public void PopulateRecordSizeInfo(ref RecordSizeInfo sizeInfo)\n        {\n            Debug.Assert(sizeInfo.word == 0, \"RecordSizeInfo should not be reused\");\n\n            // For SpanByteAllocator, we are always inline.\n            // Key\n            sizeInfo.SetKeyIsInline();\n            var keySize = sizeInfo.FieldInfo.KeySize;\n            if (keySize > 1 << LogSettings.kMaxStringSizeBits)\n                throw new TsavoriteException($\"Max inline key size is {1 << LogSettings.kMaxStringSizeBits}\");\n\n            // Value\n            sizeInfo.MaxInlineValueSize = int.MaxValue; // Not currently doing out-of-line for SpanByteAllocator\n            sizeInfo.SetValueIsInline();\n            var valueSize = sizeInfo.FieldInfo.ValueSize;\n\n            // Record\n            sizeInfo.CalculateSizes(keySize, valueSize);\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        internal void OnDispose(ref LogRecord logRecord, DisposeReason disposeReason)\n        {\n            if (logRecord.IsSet)\n            {\n                storeFunctions.OnDispose(ref logRecord, disposeReason);\n\n                logRecord.ClearOptionals();","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/SpanByteAllocatorImpl.cs#L169-L205","documentation":"SpanByteAllocator stores keys inline (no overflow key storage). PopulateRecordSizeInfo enforces keySize <= 1 << LogSettings.kMaxStringSizeBits, where kMaxStringSizeBits is 29 (512 MB). This is a hard sanity ceiling on an inline SpanByte key; in practice it only trips for a pathologically large key.","triggerScenarios":"Inserting/Upserting a SpanByte key whose length exceeds 512 MB, or a record-size computation that yields such a keySize due to a miscomputed length field.","commonSituations":"Bug that feeds the wrong (huge) field as the key — e.g. a full document/blob used as a key; unbounded key concatenation; corrupted keySize read from a malformed record header; integer underflow producing an enormous keySize.","solutions":["Ensure keys are genuinely small identifiers (hash, GUID, fixed-width id); never use a large blob as the key.","Validate key.Length against your expected maximum before the Upsert and reject oversized keys early.","If keySize looks wrong relative to the bytes you supplied, suspect header/length-field corruption upstream.","Reconsider the data model if you legitimately need very large keys."],"exampleFix":"// before\nsession.Upsert(spanByteKey, value);\n\n// after\nconst int MaxKeyBytes = 1 << 20;\nif (spanByteKey.Length > MaxKeyBytes)\n    throw new ArgumentException($\"key too large: {spanByteKey.Length}\");\nsession.Upsert(spanByteKey, value);","handlingStrategy":"validation","validationCode":"const int MaxInlineKey = 1 << LogSettings.kMaxStringSizeBits; // 512 MB sanity ceiling\nif (key.Length > MaxInlineKey)\n    throw new ArgumentException($\"key length {key.Length} exceeds inline ceiling {MaxInlineKey}\");\nsession.Upsert(key, value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use small, fixed-width identifiers as keys; never a large blob.","Enforce an application-level key-size maximum far below the 512 MB ceiling.","If a key length looks implausible, suspect header/length corruption upstream."],"tags":["tsavorite","key-size","spanbyte","limits"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}