CBG-5453: [4.0.6 backport] generate HLV.version from our own HLC for SGW actor writes#8366
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Backport to generate HLV current-version values from a Sync Gateway–owned Hybrid Logical Clock (HLC) for SG actor writes, avoiding server-side CAS macro expansion for _vv.ver and adding safety logic to preserve the cv.ver <= cas invariant needed for XDCR.
Changes:
- Introduce
base.HybridLogicalClockand store one perDatabaseContextto generate literal HLV version values for SG writes and merge resolution. - Add post-write correction (
correctVersionAheadOfCAS) that re-stamps CAS when a generated HLV version ends up ahead of the committed CAS (bounded wait + new internal stat). - Update/extend unit + integration tests to assert on HLV version semantics (not equality with CAS) and add coverage for many channel removals; temporarily skip topology tests on Windows.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| topologytest/main_test.go | Skips topology tests on Windows due to non-deterministic HLV ordering from low clock precision. |
| rest/replicatortest/replicator_test.go | Updates replicator conflict assertions to expect HLV versions not equal to CAS. |
| rest/replicatortest/replicator_conflict_test.go | Adjusts conflict setup/expectations to use HLC-generated versions for local/remote HLV edits. |
| rest/changes_test.go | Changes CV assertions to compare against doc.HLV.Version instead of doc.Cas. |
| rest/blip_api_crud_test.go | Adds coverage for many channel removals on doc updates; removes long-channel-name macro-expansion test path. |
| rest/api_test.go | Updates REST API tests to validate HLV version semantics (!= 0, <= CAS) and adds many-channel-removal coverage. |
| db/utilities_hlv_testing.go | Makes test HLV agent explicitly simulate external peers macro-expanding both _vv.ver and _vv.cvCas; adds HLC test accessor. |
| db/revision_cache_test.go | Updates channel update call signature and expected CV to use doc.HLV.Version. |
| db/hybrid_logical_vector.go | Adds maxValueForSource helper and removes macro-expansion plumbing for _vv.ver / channel revocation paths. |
| db/hybrid_logical_vector_test.go | Adds tests for CAS-ahead correction behavior and maxValueForSource. |
| db/document.go | Simplifies updateChannels signature (removes revoked-channel macro-expansion tracking). |
| db/database.go | Adds hlc to DatabaseContext and initializes it in NewDatabaseContext; updates call sites for updateChannels. |
| db/database_test.go | Updates resync expectations to use preResyncDoc.HLV.Version rather than CAS. |
| db/crud.go | Generates HLV versions via db HLC, writes literal _vv.ver, adds post-write CAS re-stamp correction + helper to re-persist xattrs. |
| db/crud_test.go | Updates tests to no longer assume HLV.Version == CAS and removes revoked-channel-path tests. |
| db/changes_test.go | Updates changes/CV tests to assert CV values against doc.HLV.Version. |
| base/stats.go | Adds internal counter stat hlv_version_cas_retry_count and version constant 4.0.6. |
| base/stats_descriptions.go | Adds description string for hlv_version_cas_retry_count. |
| base/hlc.go | Introduces HybridLogicalClock used to generate CAS-comparable, monotonic HLV version values. |
| base/hlc_test.go | Adds unit tests for HLC monotonicity, floor behavior, masking, and concurrency. |
| // assert channel removals are present in sync data | ||
| channelRemovals := doc.SyncData.Channels | ||
| require.Len(t, channelRemovals, 20) // 19 removals but should also include non-removed channel "A" but just with no removal info | ||
| require.Nil(t, channelRemovals["A"]) // channel "A" should not have removal info since it's not removed) |
adamcfraser
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CBG-5453
Backports #8355
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests