{"record":{"id":"9f9d3bb852b4a8e9","repo":"microsoft/garnet","slug":"nameof-logsettings-maxinlinekeysize-must-be-bet","errorCode":null,"errorMessage":"{nameof(logSettings.MaxInlineKeySize)} must be between {LogSettings.MinMaxInlineSize} and {LogSettings.MaxInlineKeySizeLimit}","messagePattern":"(.+?) must be between (.+?) and (.+?)","errorType":"validation","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs","lineNumber":581,"sourceCode":"            if (logSettings.ReadCacheSettings is not null)\n            {\n                var rcs = logSettings.ReadCacheSettings;\n                if (rcs.PageCount == 0 && rcs.MemorySize == 0)\n                    throw new TsavoriteException($\"{nameof(rcs.PageCount)} or {nameof(rcs.MemorySize)} must be specified\");\n                if (rcs.PageSizeBits < LogSettings.kMinPageSizeBits || rcs.PageSizeBits > LogSettings.kMaxPageSizeBits)\n                    throw new TsavoriteException($\"{nameof(rcs.PageSizeBits)} must be between {LogSettings.kMinPageSizeBits} and {LogSettings.kMaxPageSizeBits}\");\n                if (rcs.PageCount > MemoryUtils.ArrayMaxLength)\n                    throw new TsavoriteException($\"{nameof(rcs.PageCount)} must be less than or equal to the maximum array length ({MemoryUtils.ArrayMaxLength})\");\n                if (rcs.MemorySize != 0 && (rcs.MemorySize < 1L << LogSettings.kMinMemorySizeBits || rcs.MemorySize > 1L << LogSettings.kMaxMemorySizeBits))\n                    throw new TsavoriteException($\"{nameof(rcs.MemorySize)} must be between {1L << LogSettings.kMinMemorySizeBits} and {1L << LogSettings.kMaxMemorySizeBits}\");\n                if ((rcs.MemorySize != 0) && (rcs.MemorySize < (1L << rcs.PageSizeBits) * 2))\n                    throw new TsavoriteException($\"{nameof(logSettings.MemorySize)} must be at least twice the page size ({1L << rcs.PageSizeBits})\");\n                if (rcs.SecondChanceFraction < 0.0 || rcs.SecondChanceFraction > 1.0)\n                    throw new TsavoriteException($\"{rcs.SecondChanceFraction} must be >= 0.0 and <= 1.0\");\n            }\n\n            if (logSettings.MaxInlineKeySize < LogSettings.MinMaxInlineSize || logSettings.MaxInlineKeySize > LogSettings.MaxInlineKeySizeLimit)\n                throw new TsavoriteException($\"{nameof(logSettings.MaxInlineKeySize)} must be between {LogSettings.MinMaxInlineSize} and {LogSettings.MaxInlineKeySizeLimit}\");\n            if (logSettings.MaxInlineValueSize < LogSettings.MinMaxInlineSize || logSettings.MaxInlineValueSize > LogSettings.MaxInlineValueSizeLimit)\n                throw new TsavoriteException($\"{nameof(logSettings.MaxInlineValueSize)} must be between {LogSettings.MinMaxInlineSize} and {LogSettings.MaxInlineValueSizeLimit}\");\n\n            this.logger = logger;\n            if (logSettings.LogDevice == null)\n                throw new TsavoriteException(\"LogSettings.LogDevice needs to be specified (e.g., use Devices.CreateLogDevice, AzureStorageDevice, or NullDevice)\");\n\n            EvictCallback = evictCallback;\n\n            FlushCallback = flushCallback;\n            PreallocateLog = logSettings.PreallocateLog;\n            flushEvent.Initialize();\n\n            IsNullDevice = logSettings.LogDevice is NullDevice;\n\n            if (epoch == null)\n            {\n                this.epoch = new LightEpoch();","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs#L563-L599","documentation":"Constructor validation: logSettings.MaxInlineKeySize must be in [MinMaxInlineSize, MaxInlineKeySizeLimit] = [0, (1<<RecordDataHeader.kKeyLengthBits)-2] = [0, 1022]. Keys up to this many bytes are stored inline in the in-memory record; larger keys go to overflow. The upper limit is dictated by the 10-bit KeyLength field of RecordDataHeader. Default is 128.","triggerScenarios":"Setting MaxInlineKeySize > 1022 (e.g. 2048 hoping for bigger inline keys) or below 0.","commonSituations":"Trying to inline larger keys for latency reasons and exceeding the 10-bit header field width; negative value from an unset config sentinel.","solutions":["Keep MaxInlineKeySize within [0, 1022]; leave the default 128 unless measured.","For keys larger than 1022 bytes, rely on the overflow path (do not raise MaxInlineKeySize).","For a pure object store, 0 is allowed (MinMaxInlineSize)."],"exampleFix":"// before\nlogSettings.MaxInlineKeySize = 2048;  // exceeds 1022 (10-bit field)\n// after\nlogSettings.MaxInlineKeySize = 1022;  // field maximum; larger keys overflow","handlingStrategy":"validation","validationCode":"const int MaxInlineKey = (1 << 10) - 2; // MaxInlineKeySizeLimit = 1022 (10-bit KeyLength field)\nif (logSettings.MaxInlineKeySize < 0 || logSettings.MaxInlineKeySize > MaxInlineKey)\n    logSettings.MaxInlineKeySize = Math.Clamp(logSettings.MaxInlineKeySize, 0, MaxInlineKey);","typeGuard":null,"tryCatchPattern":"try { new TsavoriteKV<K,V>(logSettings, ...); }\ncatch (TsavoriteException ex) when (ex.Message.Contains(\"MaxInlineKeySize\"))\n{ /* clamp to [0,1022]; let larger keys overflow */ }","preventionTips":["Do not raise MaxInlineKeySize above 1022; rely on the overflow path for bigger keys.","Keep the default 128 unless measurement shows benefit.","Surface key-size config with explicit clamping in your settings loader."],"tags":["storage","configuration","log-settings","inline-size","key"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}