Skip to content

CBG-5980: Set the default client partition window to the server purge interval - #8942

Merged
RIT3shSapata merged 3 commits into
mainfrom
CBG-5980
Oct 22, 2026
Merged

RIT3shSapata merged 3 commits into
mainfrom
CBG-5980

Conversation

@RIT3shSapata

@RIT3shSapata RIT3shSapata commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

CBG-5980

If client_partition_window_secs is not set, Sync Gateway now uses the metadata purge interval of the bucket as the client partition window. If the bucket has no purge interval of its own, it uses the cluster-wide value. Before this change, the default was a fixed 30 days.

  • DatabaseContextOptions.ClientPartitionWindow is now a pointer, so nil means that the setting is not set. The new DatabaseContext.ClientPartitionWindow returns the configured value or the cached purge interval, and Authenticator() uses it.
  • With include_runtime=true, GET /{db}/_config and GET /_config report the window that the database uses. Without include_runtime, the config leaves the field out when the user did not set it, in both persistent and non-persistent mode.
  • NewDatabaseContext fills the purge interval cache, and the default is also cached for buckets that are not Couchbase buckets. This stops a data race between Authenticator() and Close() on DatabaseContext.Bucket.
  • Removed the 30-day default from DefaultDbConfig and from the OpenAPI spec, and added the field to the allowlist in TestDefaultDbConfigFieldCoverage.
  • Added TestDefaultClientPartitionWindow. It covers explicit and default values, with and without include_runtime, in persistent and non-persistent mode. It runs only on Couchbase Server, because on Rosmar the purge interval always equals the old 30-day default.

Behavior change: without the setting, the window drops from 30 days to the server purge interval, which is 3 days by default. Clients that stay offline longer than that no longer get revocations for grants removed while they were offline. This needs a release note.

Pre-review checklist

  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

@RIT3shSapata
RIT3shSapata requested review from a team and a balanced review from Copilot October 19, 2026 12:18
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Redocly previews

@factory-droid

factory-droid Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Droid finished @RIT3shSapata's task —— View job


The defaulting logic and runtime config behavior look coherent, and the added test coverage matches the stated intent. One documentation source of truth is still inconsistent (the Go struct comment still mentions a 30-day default).

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.

🟡 Changes recommended

The integration test exhausts single-bucket pools, and the authenticator’s changed retention window needs direct regression coverage.

2 open issues
What changed in this PR

Defaults Sync Gateway’s client partition window to the server metadata purge interval rather than a fixed 30 days.

Changes:

  • Preserves explicit settings and caches the purge interval.
  • Reports the effective window in runtime config responses.
  • Updates API documentation and integration coverage.
File Description
rest/​server_context.go Preserves unset versus explicit window values.
rest/​config_database.go Resolves the runtime window dynamically.
rest/​config_database_test.go Allows the runtime-dependent default.
rest/​api_test.go Tests explicit and default config responses.
rest/​admin_api.go Includes the effective runtime window.
docs/​api/​components/​schemas.yaml Documents the purge-interval default.
db/​database.go Resolves authenticator windows and initializes the cache.
base/​constants.go Clarifies the test-only default constant.

Review effort: Balanced

Comment thread rest/api_test.go Resolved
Comment thread db/database.go Outdated
// Authenticators are lightweight & stateless, so it's OK to return a new one every time
authenticator := auth.NewAuthenticator(context.MetadataStore, context, auth.AuthenticatorOptions{
ClientPartitionWindow: context.Options.ClientPartitionWindow,
ClientPartitionWindow: context.ClientPartitionWindow(ctx),
Comment thread docs/api/components/schemas.yaml Resolved
@RIT3shSapata
RIT3shSapata requested review from bbrks and a balanced review from Copilot October 19, 2026 13:20
@RIT3shSapata RIT3shSapata assigned bbrks and unassigned RIT3shSapata Oct 19, 2026
@RIT3shSapata

Copy link
Copy Markdown
Contributor Author

@droid review

@factory-droid

factory-droid Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Droid finished @RIT3shSapata's task —— View job


Pass 2 (validation): No additional high-confidence, actionable review comments to add beyond existing discussions. The defaulting change and runtime config reporting are consistent, and the prior doc-comment inconsistency is addressed in this diff.

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.

🔵 Needs a closer look

A config-refresh reporting bug remains, and the retention and shutdown changes still need integration and race-test validation.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Use reloaded database context for runtime purge interval

rest/​admin_api.go:623

With refresh_config=true, applyConfigs replaces the database context, but h.db still points to the previous one. If the persisted config removes an explicit seven-day window, GET /db/_config?refresh_config=true&include_runtime=true reports 604800 seconds even though the reloaded database uses its purge interval (259200 seconds for a three-day interval). Look up the current database context before filling this runtime field, and add a regression test for removing an explicit value during refresh.

1 resolved since last review

Review effort: Balanced

@bbrks bbrks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few comments - see what you think and let me know if you're unsure. I think we can simplify it a little bit.

Comment thread db/database.go Resolved
Comment thread db/database.go Resolved
Comment thread db/database.go Resolved
Comment thread base/constants.go Resolved
If client_partition_window_secs is not set, the client partition window
is now the metadata purge interval of the bucket, or the cluster-wide
value if the bucket has none. Before this change, the default was a
fixed 30 days.
- force a reload of metadata purge interval on database creation
- replace DefaultPurgeInterval with DefaultClientPartitionWindow
- read the purge interval from cache for ClientPartitionWindow
@RIT3shSapata RIT3shSapata assigned bbrks and unassigned RIT3shSapata Oct 22, 2026

@bbrks bbrks left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good - just one follow-up ticket to file to make sure we support a changing metadata purge interval on server side.

This only affects the existing Authenticator code right now, which was always a hardcoded 30d const before this PR anyway so I'm not bothered about supporting it in this PR yet.

Comment thread db/database.go Resolved
@RIT3shSapata
RIT3shSapata merged commit 019db40 into main Oct 22, 2026
54 checks passed
@RIT3shSapata
RIT3shSapata deleted the CBG-5980 branch October 22, 2026 10:37
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.

3 participants