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

Method IsSGWrite

db/document.go:673–704  ·  view source on GitHub ↗

IsSGWrite determines if a document was written by Sync Gateway or via an SDK. CV is an optional parameter to check. This would represent _vv.ver and _vv.src

(ctx context.Context, cas uint64, rawBody []byte, rawUserXattr []byte, cv cvExtractor)

Source from the content-addressed store, hash-verified

671
672// IsSGWrite determines if a document was written by Sync Gateway or via an SDK. CV is an optional parameter to check. This would represent _vv.ver and _vv.src
673func (s *SyncData) IsSGWrite(ctx context.Context, cas uint64, rawBody []byte, rawUserXattr []byte, cv cvExtractor) (isSGWrite bool, crc32Match bool, bodyChanged bool) {
674
675 // If cas matches, it was a SG write
676 if cas == s.GetSyncCas() {
677 return true, false, false
678 }
679
680 // If crc32c hash of body doesn't match value stored in SG metadata then import is required
681 if base.Crc32cHashString(rawBody) != s.Crc32c {
682 return false, false, true
683 }
684
685 if HasUserXattrChanged(rawUserXattr, s.Crc32cUserXattr) {
686 // technically the crc32 matches but return false on crc32Match so Crc32MatchCount is not incremented, to mark that it would be imported
687 return false, false, false
688 }
689
690 if s.RevAndVersion.CurrentVersion != "" || s.RevAndVersion.CurrentSource != "" {
691 extractedCV, err := cv.ExtractCV()
692 if !errors.Is(err, base.ErrNotFound) {
693 if err != nil {
694 base.InfofCtx(ctx, base.KeyImport, "Unable to extract cv during IsSGWrite write check - skipping cv match check: %v", err)
695 return true, true, false
696 }
697 if !s.CVEqual(*extractedCV) {
698 // technically the crc32 matches but return false so Crc32MatchCount is not incremented, to mark that it would be imported
699 return false, false, false
700 }
701 }
702 }
703 return true, true, false
704}
705
706// IsSGWrite - used during on-demand import. Check SyncData and HLV to determine if the document was written by Sync Gateway or by a Couchbase Server SDK write.
707func (doc *Document) IsSGWrite(ctx context.Context, rawBody []byte) (isSGWrite bool, crc32Match bool, bodyChanged bool) {

Callers 11

IsSGWriteMethod · 0.45
DocChangedMethod · 0.45
importDocMethod · 0.45
TestIsSGWriteFunction · 0.45
GetDocumentWithRawMethod · 0.45
GetDocSyncDataMethod · 0.45
PutMethod · 0.45
ImportFeedEventMethod · 0.45
CreateDocNoHLVMethod · 0.45

Calls 6

GetSyncCasMethod · 0.95
CVEqualMethod · 0.95
Crc32cHashStringFunction · 0.92
InfofCtxFunction · 0.92
HasUserXattrChangedFunction · 0.85
ExtractCVMethod · 0.65

Tested by 1

TestIsSGWriteFunction · 0.36