Skip to content

CBG-5453: [4.0.6 backport] generate HLV.version from our own HLC for SGW actor writes#8366

Merged
torcolvin merged 3 commits into
release/4.0.6from
CBG-5453
Jun 15, 2026
Merged

CBG-5453: [4.0.6 backport] generate HLV.version from our own HLC for SGW actor writes#8366
torcolvin merged 3 commits into
release/4.0.6from
CBG-5453

Conversation

@gregns1

@gregns1 gregns1 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

CBG-5453

Backports #8355

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • 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

Copilot AI review requested due to automatic review settings June 15, 2026 12:08

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

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.HybridLogicalClock and store one per DatabaseContext to 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 adamcfraser enabled auto-merge (squash) June 15, 2026 20:15
@torcolvin torcolvin disabled auto-merge June 15, 2026 20:23
@torcolvin torcolvin merged commit 7024552 into release/4.0.6 Jun 15, 2026
42 checks passed
@torcolvin torcolvin deleted the CBG-5453 branch June 15, 2026 20:23
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.

4 participants