{"record":{"id":"66ede4b457428fb8","repo":"microsoft/garnet","slug":"advancing-position-by-size-n-bytes-exceeds-maxim","errorCode":null,"errorMessage":"Advancing position by {size:N} bytes exceeds maximum object log segment.","messagePattern":"Advancing position by (.+?) bytes exceeds maximum object log segment\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/Allocator/ObjectSerialization/ObjectLogFilePositionInfo.cs","lineNumber":147,"sourceCode":"        }\n\n        public void Advance(ulong size)\n        {\n            // Does it fit in the current segment?\n            var remaining = SegmentSize - Offset;\n            if (size < remaining)\n            {\n                Offset += size;\n                return;\n            }\n\n            // Note: If size == remaining, we will advance to the start of the next segment.\n            size -= remaining;\n\n            // Move to the next segment(s).\n            long nextSegmentId = SegmentId + (int)(size / SegmentSize) + 1;\n            if (nextSegmentId > MaxSegmentId)\n                throw new InvalidDataException($\"Advancing position by {size:N} bytes exceeds maximum object log segment.\");\n\n            SegmentId = (int)nextSegmentId;\n            Offset += size & (SegmentSize - 1);\n        }\n\n        public void AdvanceToNextSegment()\n        {\n            long nextSegmentId = SegmentId + 1;\n            if (nextSegmentId > MaxSegmentId)\n                throw new InvalidDataException($\"Advancing to next segment exceeds maximum object log segment.\");\n            SegmentId = (int)nextSegmentId;\n            Offset = 0;\n        }\n\n        public readonly ulong CurrentAddress => ((ulong)SegmentId << SegmentSizeBits) | Offset;\n\n        public static ulong operator -(ObjectLogFilePositionInfo left, ObjectLogFilePositionInfo right)\n        {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/ObjectSerialization/ObjectLogFilePositionInfo.cs#L129-L165","documentation":"Thrown by ObjectLogFilePositionInfo.Advance when advancing the object-log file position by 'size' bytes would move the segment id past MaxSegmentId. MaxSegmentId is derived from the number of segment-and-offset bits (a 64-bit-ish address word) minus SegmentSizeBits, so the object-log address space is exhausted. This is a structural capacity ceiling, not a transient condition.","triggerScenarios":"Serializing/writing object-log data such that the running file position crosses into a segment beyond the addressable range; typically a runaway write of an enormous object or an incorrectly huge size argument. Also possible if SegmentSizeBits is configured very large, shrinking the number of available segment bits.","commonSituations":"A corrupt or absurdly large object length being copied through the object log; misconfigured ObjectLogSegmentSizeBits near kMaxSegmentSizeBits (62) leaving almost no segment ids; a bug producing an oversized Advance argument.","solutions":["Reduce ObjectLogSegmentSizeBits so more segment ids fit in the address word (more total capacity), while staying >= 22.","Investigate the source of the oversized write: the {size:N} value in the message shows how many bytes were requested.","Cap individual object sizes well below the segment capacity and chunk very large values."],"exampleFix":"// before\nlogSettings.ObjectLogSegmentSizeBits = 60; // leaves only a handful of segment ids\n// after\nlogSettings.ObjectLogSegmentSizeBits = 33; // default 8GB segments, many segment ids available","handlingStrategy":"validation","validationCode":"// Sanity-check configured segment bits leave usable segment capacity\nconst int addressBits = 64;\nvar maxSegments = (1L << (addressBits - logSettings.ObjectLogSegmentSizeBits));\nif (maxSegments < 1024) logger.LogWarning(\"ObjectLogSegmentSizeBits={Bits} leaves only {N} segment ids\", logSettings.ObjectLogSegmentSizeBits, maxSegments);","typeGuard":null,"tryCatchPattern":"try { /* object-log write */ }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"exceeds maximum object log segment\"))\n{\n    logger.LogError(ex, \"Object-log segment capacity exhausted; lower ObjectLogSegmentSizeBits\");\n    throw;\n}","preventionTips":["Keep ObjectLogSegmentSizeBits at a moderate value (e.g. 33) to maximize segment count.","Cap individual object sizes and reject pathologically large writes upstream."],"tags":["object-log","capacity","segment","serialization"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}