Skip to content

Conversation

@bbrks
Copy link
Member

@bbrks bbrks commented Aug 20, 2025

CBG-4751

  • Allow CV to be used in OCC writes (Document Update/Delete and the associated attachment endpoints) using existing rev parameter - which can automatically detect RevTreeID/CV.
  • Switch test helpers to use CV in writes when available for coverage, and allow fallback to RevTreeID. This is a prereq for getting CBG-3778 remove rt.*Directly functions #7658 merged
  • Prevent CV OCC value in doc updates for docs in conflict or against non-current versions, since we don't maintain linear version history like we do for RevTrees and can't correlate an old CV with a branched revision ID.

Integration Tests

…ociated attachment endpoints) using existing `rev` parameter - which can automatically detect RevTreeID/CV.

Switch test helpers to use CV in writes when available for coverage, and allow fallback to RevTreeID.
Prevent CV OCC value in doc updates for docs in conflict or against non-current versions, since we don't maintain linear version history like we do for RevTrees and can't correlate an old CV with a branched revision ID.
@bbrks bbrks self-assigned this Aug 20, 2025
Copilot AI review requested due to automatic review settings August 20, 2025 13:29
@github-actions
Copy link

github-actions bot commented Aug 20, 2025

Redocly previews

This comment was marked as outdated.

@bbrks bbrks requested a review from Copilot August 20, 2025 16:31
@bbrks bbrks removed their assignment Aug 20, 2025

This comment was marked as outdated.

Copy link
Collaborator

@torcolvin torcolvin left a comment

Choose a reason for hiding this comment

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

LGTM in general.

// Can't use CV as an OCC Value when a document is in conflict, or we're updating the non-winning leaf
// There's no way to get from a given old CV to a RevTreeID to perform the update correctly, since we don't maintain linear history for a given SourceID.
// Reject the request and force the user to resolve the conflict using RevTree IDs which does have linear history available.
conflictErr = base.HTTPErrorf(http.StatusBadRequest, "Cannot use CV to modify a document in conflict - resolve first with RevTree ID")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any way that this is going to get hit for a blip code pathway? If it does, will the blip code know how to handle a 400 with this error message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, it can't happen.

BLIP goes through PutExistingCurrentVersion since the client is the one generating a new CV value and pushing it, not relying on SG to generate the HLV entry. Put is SG/REST API-only writes.

@torcolvin torcolvin assigned bbrks and unassigned torcolvin Aug 20, 2025
@bbrks bbrks mentioned this pull request Aug 21, 2025
2 tasks
@bbrks bbrks requested a review from Copilot August 21, 2025 15:16
Copy link
Contributor

Copilot AI left a comment

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 allows Current Version (CV) to be used as an optimistic concurrency control (OCC) value in REST API document operations (updates/deletes) using the existing rev parameter, which can now automatically detect whether the value is a RevTreeID or CV. The changes also update test helpers to use CV when available for better test coverage and prevent CV usage on conflicted documents since linear version history isn't maintained for CVs.

  • Add CV support for OCC in document write operations (PUT/DELETE)
  • Update test utilities to prefer CV over RevTreeID when available
  • Add validation to prevent CV usage on documents in conflict

Reviewed Changes

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

Show a summary per file
File Description
rest/doc_api.go Add CV support for OCC operations and new helper functions for version type detection
rest/utilities_testing_resttester.go Update test helpers to use CV when available with fallback to RevTreeID
rest/utilities_testing.go Add GetRawDoc helper and update DocVersionFromPutResponse to handle CV responses
db/crud.go Update DeleteDoc to accept DocVersion and add CV validation in Put operations
db/document.go Move DocVersion struct definition and add new helper methods
topologytest/sync_gateway_peer_test.go Update DeleteDocument to use ExtractDocVersion()
docs/api/* Update OpenAPI documentation to reflect CV support and terminology improvements
base/util.go Add IsRevTreeID helper function for version type detection

@bbrks bbrks requested a review from torcolvin August 21, 2025 15:24
@bbrks bbrks assigned torcolvin and unassigned bbrks Aug 21, 2025
torcolvin
torcolvin previously approved these changes Aug 21, 2025
torcolvin
torcolvin previously approved these changes Aug 21, 2025
@bbrks bbrks merged commit c16e23c into main Aug 21, 2025
45 checks passed
@bbrks bbrks deleted the CBG-4751 branch August 21, 2025 19:18
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