{"record":{"id":"066da62c3b7e6038","repo":"microsoft/garnet","slug":"advancing-to-next-segment-exceeds-maximum-object-l","errorCode":null,"errorMessage":"Advancing to next segment exceeds maximum object log segment.","messagePattern":"Advancing to next segment 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":157,"sourceCode":"            }\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        {\n            Debug.Assert(left.SegmentSizeBits == right.SegmentSizeBits, \"Segment size bits must match to compute distance\");\n            Debug.Assert((left.word & SegmentAndOffsetMask) >= (right.word & SegmentAndOffsetMask), \"comparison position must be greater\");\n            var segmentDiff = (ulong)(left.SegmentId - right.SegmentId);\n            if (segmentDiff == 0)\n                return left.Offset - right.Offset;\n            return ((segmentDiff - 1) * left.SegmentSize) + (left.SegmentSize - right.Offset) + left.Offset;\n        }\n\n        public readonly ulong SegmentSize => 1UL << SegmentSizeBits;\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/ObjectSerialization/ObjectLogFilePositionInfo.cs#L139-L175","documentation":"Thrown by ObjectLogFilePositionInfo.AdvanceToNextSegment when incrementing the current segment id by one would exceed MaxSegmentId. This is the segment-at-a-time variant of the capacity check: the object-log file position has reached the last addressable segment and cannot open another.","triggerScenarios":"Object-log writing/flushing that fills segments until SegmentId == MaxSegmentId, then needs a new segment (segment boundary reached). Triggered on segment rollover during WriteRecordObjects / OnBufferComplete flush paths.","commonSituations":"Long-lived store that has written enough object-log data to exhaust segment ids; large ObjectLogSegmentSizeBits (fewer, bigger segments) accelerating id exhaustion; a runaway write loop.","solutions":["Lower ObjectLogSegmentSizeBits (within [22,62]) to increase the number of segment ids and total capacity.","Recycle/compact the object log if the store supports it, reducing the live segment range.","Investigate abnormally fast segment growth (e.g. repeated large-object writes)."],"exampleFix":"// before\nlogSettings.ObjectLogSegmentSizeBits = 58; // few segment ids\n// after\nlogSettings.ObjectLogSegmentSizeBits = 33; // default, many segment ids","handlingStrategy":"validation","validationCode":"var maxSegments = 1L << (64 - logSettings.ObjectLogSegmentSizeBits);\nif (maxSegments < 1024) logger.LogWarning(\"Few object-log segment ids available; consider lowering ObjectLogSegmentSizeBits\");","typeGuard":null,"tryCatchPattern":"try { /* flush/write that may cross segment boundary */ }\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"exceeds maximum object log segment\"))\n{\n    logger.LogError(ex, \"Segment id exhausted during segment advance\");\n    throw;\n}","preventionTips":["Monitor live segment id growth and compact/recycle before exhaustion.","Avoid setting ObjectLogSegmentSizeBits near kMaxSegmentSizeBits (62)."],"tags":["object-log","capacity","segment","flush"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}