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)
| 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 |
| 673 | func (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. |
| 707 | func (doc *Document) IsSGWrite(ctx context.Context, rawBody []byte) (isSGWrite bool, crc32Match bool, bodyChanged bool) { |