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)
| 452 | // other Sync Gateway nodes to serve the previous revision |
| 453 | // (https://github.com/couchbase/sync_gateway/issues/3740) |
| 454 | func (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 |
no test coverage detected