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

Method backupPreImportRevision

db/import.go:454–487  ·  view source on GitHub ↗

backupPreImportRev attempts to make a temporary backup of a revision body if the revision is currently resident in the revision cache. This is the import parallel for the temporary revision bodies made during SG writes. Allows in-flight replications on other Sync Gateway nodes to serve the previou

(ctx context.Context, docid, revid string)

Source from the content-addressed store, hash-verified

452// other Sync Gateway nodes to serve the previous revision
453// (https://github.com/couchbase/sync_gateway/issues/3740)
454func (db *DatabaseCollectionWithUser) backupPreImportRevision(ctx context.Context, docid, revid string) error {
455
456 // If Delta Sync is enabled, this will already be handled by the backup handling used for delta generation
457 if db.deltaSyncEnabled() {
458 return nil
459 }
460
461 previousRev, ok := db.revisionCache.Peek(ctx, docid, revid)
462 if !ok {
463 return nil
464 }
465
466 var kvPairs []base.KVPair
467 if len(previousRev.Attachments) > 0 {
468 kvPairs = append(kvPairs, base.KVPair{Key: BodyAttachments, Val: previousRev.Attachments})
469 }
470
471 if previousRev.Deleted {
472 kvPairs = append(kvPairs, base.KVPair{Key: BodyDeleted, Val: true})
473 }
474
475 // Stamp _attachments and _deleted into backup
476 oldRevJSON, err := base.InjectJSONProperties(previousRev.BodyBytes, kvPairs...)
477 if err != nil {
478 return err
479 }
480
481 setOldRevErr := db.setOldRevisionJSON(ctx, docid, revid, oldRevJSON, previousRev.Deleted, db.oldRevExpirySeconds(), previousRev.Channels)
482 if setOldRevErr != nil {
483 return fmt.Errorf("Persistence error: %v", setOldRevErr)
484 }
485
486 return nil
487}
488
489// ////// Import Filter Function
490

Callers 1

importDocMethod · 0.95

Calls 6

setOldRevisionJSONMethod · 0.95
InjectJSONPropertiesFunction · 0.92
deltaSyncEnabledMethod · 0.80
oldRevExpirySecondsMethod · 0.80
ErrorfMethod · 0.80
PeekMethod · 0.65

Tested by

no test coverage detected