Skip to content

Commit

Permalink
updates to address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gregns1 committed Oct 4, 2023
1 parent 327a049 commit 7d73389
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
16 changes: 7 additions & 9 deletions db/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

const (
kMaxRecentSequences = 20 // Maximum number of sequences stored in RecentSequences before pruning is triggered
// hlvExpandMacroCASValue causes the field to be populated by CAS value by macro expansion
hlvExpandMacroCASValue = math.MaxUint64
)

// ErrForbidden is returned when the user requests a document without a revision that they do not have access to.
Expand Down Expand Up @@ -869,7 +871,7 @@ func (db *DatabaseCollectionWithUser) OnDemandImportForWrite(ctx context.Context
return nil
}

// updateMutateInSpec updates the mutate in options with the appropriate mutate in spec needed based off the outcome in updateHLV
// updateMutateInSpec returns the mutate in spec needed for the document update based off the outcome in updateHLV
func updateMutateInSpec(hlv HybridLogicalVector) []sgbucket.MacroExpansionSpec {
var outputSpec []sgbucket.MacroExpansionSpec
if hlv.Version == math.MaxUint64 {
Expand All @@ -889,19 +891,15 @@ func (db *DatabaseCollectionWithUser) updateHLV(d *Document, docUpdateEvent DocU
switch docUpdateEvent.eventType {
case BlipWriteEvent:
// preserve any other logic on the HLV that has been done by the client, only update to cvCAS will be needed
d.HLV.CurrentVersionCAS = math.MaxUint64 // this will be an alias to "should macro expand"
d.HLV.CurrentVersionCAS = hlvExpandMacroCASValue
case ImportEvent:
// VV should remain unchanged
case SGWriteEvent:
// add a new entry to the version vector
newVVEntry := CurrentVersionVector{}
bucketUUID, err := db.dbCtx.Bucket.UUID()
if err != nil {
return nil, err
}
newVVEntry.SourceID = bucketUUID
newVVEntry.VersionCAS = math.MaxUint64 // this will be an alias to "should macro expand"
err = d.SyncData.HLV.AddVersion(newVVEntry)
newVVEntry.SourceID = db.dbCtx.BucketUUID
newVVEntry.VersionCAS = hlvExpandMacroCASValue
err := d.SyncData.HLV.AddVersion(newVVEntry)
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type DatabaseContext struct {
MetadataStore base.DataStore // Storage for database metadata (anything that isn't an end-user's/customer's documents)
Bucket base.Bucket // Storage
BucketSpec base.BucketSpec // The BucketSpec
BucketUUID string // The bucket UUID for the bucket the database is created against
BucketLock sync.RWMutex // Control Access to the underlying bucket object
mutationListener changeListener // Caching feed listener
ImportListener *importListener // Import feed listener
Expand Down Expand Up @@ -425,6 +426,11 @@ func NewDatabaseContext(ctx context.Context, dbName string, bucket base.Bucket,
metadataStore = bucket.DefaultDataStore()
}

bucketUUID, err := bucket.UUID()
if err != nil {
return nil, err
}

// Register the cbgt pindex type for the configGroup
RegisterImportPindexImpl(ctx, options.GroupID)

Expand All @@ -433,6 +439,7 @@ func NewDatabaseContext(ctx context.Context, dbName string, bucket base.Bucket,
UUID: cbgt.NewUUID(),
MetadataStore: metadataStore,
Bucket: bucket,
BucketUUID: bucketUUID,
StartTime: time.Now(),
autoImport: autoImport,
Options: options,
Expand Down
2 changes: 1 addition & 1 deletion db/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ func (doc *Document) UnmarshalWithXattr(ctx context.Context, data []byte, xdata
tmpData := SyncData{}
unmarshalErr := base.JSONUnmarshal(xdata, &tmpData)
if unmarshalErr != nil {
return pkgerrors.WithStack(base.RedactErrorf("Failed to UnmarshalWithXattr() doc with id: %s (DocUnmarshalVV). Error: %v", base.UD(doc.ID), unmarshalErr))
return base.RedactErrorf("Failed to UnmarshalWithXattr() doc with id: %s (DocUnmarshalVV). Error: %w", base.UD(doc.ID), unmarshalErr)
}
doc.SyncData.HLV = tmpData.HLV
doc._rawBody = data
Expand Down

0 comments on commit 7d73389

Please sign in to comment.