From 823a6b9b049d5603c4fa939994dacc2869693527 Mon Sep 17 00:00:00 2001 From: Gregory Newman-Smith Date: Fri, 6 Oct 2023 11:31:51 +0100 Subject: [PATCH] fix for import issues --- db/crud.go | 18 +++++++++++------- db/document.go | 36 ++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/db/crud.go b/db/crud.go index 3af40cf2db..ebe0209d6d 100644 --- a/db/crud.go +++ b/db/crud.go @@ -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 @@ -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 @@ -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. diff --git a/db/document.go b/db/document.go index 7b367770c4..c9803d06f6 100644 --- a/db/document.go +++ b/db/document.go @@ -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.