Skip to content

Commit

Permalink
fix for import issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gregns1 committed Oct 6, 2023
1 parent 8410ffe commit 823a6b9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
18 changes: 11 additions & 7 deletions db/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,9 @@ func (db *DatabaseCollectionWithUser) OnDemandImportForWrite(ctx context.Context
// updateHLV updates the HLV in the sync data appropriately based on what type of document update event we are encountering
func (db *DatabaseCollectionWithUser) updateHLV(d *Document, docUpdateEvent uint32) (*Document, error) {

if d.HLV == nil {
d.HLV = &HybridLogicalVector{}
}
switch docUpdateEvent {
case BlipWriteEvent:
// preserve any other logic on the HLV that has been done by the client, only update to cvCAS will be needed
Expand Down Expand Up @@ -1935,13 +1938,6 @@ func (db *DatabaseCollectionWithUser) updateAndReturnDoc(ctx context.Context, do
}
prevCurrentRev = doc.CurrentRev

doc, err = db.updateHLV(doc, docUpdateEvent)
if err != nil {
return
}
// update the mutate in options based on the above logic
updatedSpec = doc.SyncData.HLV.computeMacroExpansions()

// Check whether Sync Data originated in body
if currentXattr == nil && doc.Sequence > 0 {
doc.inlineSyncData = true
Expand All @@ -1966,6 +1962,14 @@ func (db *DatabaseCollectionWithUser) updateAndReturnDoc(ctx context.Context, do
return
}

// update the HLV values
doc, err = db.updateHLV(doc, docUpdateEvent)
if err != nil {
return
}
// update the mutate in options based on the above logic
updatedSpec = doc.SyncData.HLV.computeMacroExpansions()

deleteDoc = currentRevFromHistory.Deleted

// Return the new raw document value for the bucket to store.
Expand Down
36 changes: 18 additions & 18 deletions db/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ type ChannelSetEntry struct {

// The sync-gateway metadata stored in the "_sync" property of a Couchbase document.
type SyncData struct {
CurrentRev string `json:"rev"`
NewestRev string `json:"new_rev,omitempty"` // Newest rev, if different from CurrentRev
Flags uint8 `json:"flags,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
UnusedSequences []uint64 `json:"unused_sequences,omitempty"` // unused sequences due to update conflicts/CAS retry
RecentSequences []uint64 `json:"recent_sequences,omitempty"` // recent sequences for this doc - used in server dedup handling
Channels channels.ChannelMap `json:"channels,omitempty"`
Access UserAccessMap `json:"access,omitempty"`
RoleAccess UserAccessMap `json:"role_access,omitempty"`
Expiry *time.Time `json:"exp,omitempty"` // Document expiry. Information only - actual expiry/delete handling is done by bucket storage. Needs to be pointer for omitempty to work (see https://github.com/golang/go/issues/4357)
Cas string `json:"cas"` // String representation of a cas value, populated via macro expansion
Crc32c string `json:"value_crc32c"` // String representation of crc32c hash of doc body, populated via macro expansion
Crc32cUserXattr string `json:"user_xattr_value_crc32c,omitempty"` // String representation of crc32c hash of user xattr
TombstonedAt int64 `json:"tombstoned_at,omitempty"` // Time the document was tombstoned. Used for view compaction
Attachments AttachmentsMeta `json:"attachments,omitempty"`
ChannelSet []ChannelSetEntry `json:"channel_set"`
ChannelSetHistory []ChannelSetEntry `json:"channel_set_history"`
HLV HybridLogicalVector `json:"_vv,omitempty"`
CurrentRev string `json:"rev"`
NewestRev string `json:"new_rev,omitempty"` // Newest rev, if different from CurrentRev
Flags uint8 `json:"flags,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
UnusedSequences []uint64 `json:"unused_sequences,omitempty"` // unused sequences due to update conflicts/CAS retry
RecentSequences []uint64 `json:"recent_sequences,omitempty"` // recent sequences for this doc - used in server dedup handling
Channels channels.ChannelMap `json:"channels,omitempty"`
Access UserAccessMap `json:"access,omitempty"`
RoleAccess UserAccessMap `json:"role_access,omitempty"`
Expiry *time.Time `json:"exp,omitempty"` // Document expiry. Information only - actual expiry/delete handling is done by bucket storage. Needs to be pointer for omitempty to work (see https://github.com/golang/go/issues/4357)
Cas string `json:"cas"` // String representation of a cas value, populated via macro expansion
Crc32c string `json:"value_crc32c"` // String representation of crc32c hash of doc body, populated via macro expansion
Crc32cUserXattr string `json:"user_xattr_value_crc32c,omitempty"` // String representation of crc32c hash of user xattr
TombstonedAt int64 `json:"tombstoned_at,omitempty"` // Time the document was tombstoned. Used for view compaction
Attachments AttachmentsMeta `json:"attachments,omitempty"`
ChannelSet []ChannelSetEntry `json:"channel_set"`
ChannelSetHistory []ChannelSetEntry `json:"channel_set_history"`
HLV *HybridLogicalVector `json:"_vv,omitempty"`

// Only used for performance metrics:
TimeSaved time.Time `json:"time_saved,omitempty"` // Timestamp of save.
Expand Down

0 comments on commit 823a6b9

Please sign in to comment.