MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / AddVersion

Method AddVersion

db/hybrid_logical_vector.go:386–422  ·  view source on GitHub ↗

AddVersion adds newVersion as the current version to the in memory representation of the HLV.

(newVersion Version)

Source from the content-addressed store, hash-verified

384
385// AddVersion adds newVersion as the current version to the in memory representation of the HLV.
386func (hlv *HybridLogicalVector) AddVersion(newVersion Version) error {
387
388 // check if this is the first time we're adding a source - version pair
389 if hlv.SourceID == "" {
390 hlv.Version = newVersion.Value
391 hlv.SourceID = newVersion.SourceID
392 return nil
393 }
394
395 // If the new version is older than an existing version for the same source, return error
396 existingValueForSource, found := hlv.GetValue(newVersion.SourceID)
397 if found && existingValueForSource > newVersion.Value {
398 return fmt.Errorf("attempting to add new version vector entry with a value that is less than the existing value for the same source. New version: %v, Existing HLV: %v", newVersion, hlv)
399 }
400
401 // Move existing mv to pv before adding the new version
402 hlv.InvalidateMV()
403
404 // If the new version has the same source as existing cv, we just update the cv value
405 if newVersion.SourceID == hlv.SourceID {
406 hlv.Version = newVersion.Value
407 return nil
408 }
409
410 // If we get here this is a new version from a different sourceID. Need to move existing cv to pv and update cv
411 if hlv.PreviousVersions == nil {
412 hlv.PreviousVersions = make(HLVVersions)
413 }
414
415 hlv.PreviousVersions[hlv.SourceID] = hlv.Version
416
417 // If new version source already existed in PV, need to remove it
418 delete(hlv.PreviousVersions, newVersion.SourceID)
419 hlv.Version = newVersion.Value
420 hlv.SourceID = newVersion.SourceID
421 return nil
422}
423
424// InvalidateMV will move all merge versions to PV, except merge version entries that share a source with cv
425func (hlv *HybridLogicalVector) InvalidateMV() {

Callers 15

updateHLVFunction · 0.95
upsertDocMethod · 0.95
CreateDocumentMethod · 0.95
extractHLVFromBlipStringFunction · 0.95
MergeWithIncomingHLVMethod · 0.95
TestInternalHLVFunctionsFunction · 0.95
InsertWithHLVMethod · 0.95
getDocVersionFunction · 0.80
TestHLVAddVersionFunction · 0.80

Calls 3

GetValueMethod · 0.95
InvalidateMVMethod · 0.95
ErrorfMethod · 0.80

Tested by 6

CreateDocumentMethod · 0.76
TestInternalHLVFunctionsFunction · 0.76
getDocVersionFunction · 0.64
TestHLVAddVersionFunction · 0.64