Skip to content

Honor configured AOF segment size in TsavoriteLogSettings#1798

Merged
badrishc merged 5 commits into
mainfrom
copilot/fix-aof-truncation-segment-size
May 13, 2026
Merged

Honor configured AOF segment size in TsavoriteLogSettings#1798
badrishc merged 5 commits into
mainfrom
copilot/fix-aof-truncation-segment-size

Conversation

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor

Fix: AOF truncation ignores configured segment size (always uses default 1 GB granularity).

GarnetServerOptions.GetAofSettings() was constructing TsavoriteLogSettings without setting SegmentSizeBits, so the AOF always used Tsavorite's default 1 GB segment, preventing file-level truncation at smaller AofSizeLimit values.

  • Add a new AofSegmentSize option (default 1g, preserving existing behavior).
  • Plumb AofSegmentSize into TsavoriteLogSettings.SegmentSizeBits in GetAofSettings(), with page-size <= segment-size validation.
  • Update defaults.conf and website configuration docs.
  • Add AofSegmentSizeFlowsToTsavoriteLogSettings test covering default, override, and validation.
  • Address review feedback: validate AOF page/memory/segment size relationships before allocating GetAofDevice so a validation failure cannot leak file handles. (Also fixes the same pre-existing pattern for the page-vs-memory check.)
  • Address review feedback: in the test, dispose LogCommitManager (also IDisposable) in addition to LogDevice, and use try/finally so disposal runs even if an assertion fails.
  • Validate: targeted config tests + all 28 RespAofTests pass.

Copilot AI changed the title [WIP] Fix AOF truncation to respect configured SegmentSize Honor configured AOF segment size in TsavoriteLogSettings May 13, 2026
Copilot AI requested a review from badrishc May 13, 2026 05:23
@badrishc badrishc marked this pull request as ready for review May 13, 2026 14:33
Copilot AI review requested due to automatic review settings May 13, 2026 14:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes AOF file segmentation honor server configuration by introducing an explicit AofSegmentSize option and plumbing it into the TsavoriteLogSettings used for AOF. This aligns AOF truncation/rollover behavior with configured limits by allowing smaller on-disk segment (file) granularity than Tsavorite’s prior implicit default.

Changes:

  • Add new AofSegmentSize server option (default 1g), including defaults and documentation.
  • Pass SegmentSizeBits into AOF TsavoriteLogSettings and add page-size vs segment-size validation.
  • Add config test coverage to ensure the option flows through and validation triggers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
website/docs/getting-started/configuration.md Document new --aof-segment-size configuration setting.
test/Garnet.test/GarnetServerConfigTests.cs Add tests verifying default/override segment size and invalid page>segment validation.
libs/server/Servers/GarnetServerOptions.cs Add AofSegmentSize option, compute bits, plumb into TsavoriteLogSettings, and validate page vs segment.
libs/host/defaults.conf Define default AofSegmentSize: 1g.
libs/host/Configuration/Options.cs Add CLI option --aof-segment-size with memory-size validation and map into GarnetServerOptions.
Comments suppressed due to low confidence (1)

test/Garnet.test/GarnetServerConfigTests.cs:1363

  • Same as above: this second GetAofSettings call disposes only LogDevice; LogCommitManager should also be disposed, and cleanup should be in a finally/using pattern to avoid leaking resources if assertions throw.
            serverOptions = options.GetServerOptions();
            serverOptions.GetAofSettings(0, out logSettings);
            ClassicAssert.AreEqual(1, logSettings.Length);
            ClassicAssert.AreEqual(1L << 26, logSettings[0].SegmentSize);
            foreach (var s in logSettings)
                s.LogDevice?.Dispose();

Comment thread libs/server/Servers/GarnetServerOptions.cs Outdated
Comment thread test/Garnet.test/GarnetServerConfigTests.cs Outdated
Comment thread libs/server/Servers/GarnetServerOptions.cs
@badrishc badrishc merged commit 4cc403f into main May 13, 2026
27 checks passed
@badrishc badrishc deleted the copilot/fix-aof-truncation-segment-size branch May 13, 2026 20:53
@rdavisunr

Copy link
Copy Markdown

@badrishc I’m not seeing this change in release/v1 (v1.1.x).

Could this be cherry-picked/backported into the next v1.1.x release?

@badrishc

Copy link
Copy Markdown
Collaborator

@copilot - please backport this PR to target release/v1 (and update version in that PR so its merge will create a new release).

@badrishc badrishc mentioned this pull request May 28, 2026
badrishc added a commit that referenced this pull request May 28, 2026
* Honor configured AOF segment size in TsavoriteLogSettings (#1798)

* Initial plan

* Add AofSegmentSize option and apply it to TsavoriteLogSettings

Agent-Logs-Url: https://github.com/microsoft/garnet/sessions/cc0abf6b-ee36-45e2-8578-3c89663bdc1b

Co-authored-by: badrishc <18355833+badrishc@users.noreply.github.com>

* Validate AOF sizes before allocating devices to avoid handle leak

Agent-Logs-Url: https://github.com/microsoft/garnet/sessions/172f9b38-65ea-4ef5-acee-e348757c9259

Co-authored-by: badrishc <18355833+badrishc@users.noreply.github.com>

* Dispose LogCommitManager + use try/finally in AOF segment-size test

Agent-Logs-Url: https://github.com/microsoft/garnet/sessions/ffdda9db-bb9a-4574-a510-c52b3647caf3

Co-authored-by: badrishc <18355833+badrishc@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: badrishc <18355833+badrishc@users.noreply.github.com>
Co-authored-by: Badrish Chandramouli <badrishc@microsoft.com>
(cherry picked from commit 4cc403f)

* Backport PR 1798 to release/v1

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: badrishc <18355833+badrishc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AOF truncation ignores configured SegmentSize, always uses default 1 GB granularity

5 participants