(ctx context.Context, docid string, rev string, body []byte, deletedDoc bool, expiry uint32, channels base.Set)
| 330 | } |
| 331 | |
| 332 | func (db *DatabaseCollectionWithUser) setOldRevisionJSON(ctx context.Context, docid string, rev string, body []byte, deletedDoc bool, expiry uint32, channels base.Set) error { |
| 333 | // no channel information available (Note: this is different than an empty set of channels) |
| 334 | if channels == nil { |
| 335 | base.WarnfCtx(ctx, "setOldRevisionJSON called with nil channels for old revision %q / %q", base.UD(docid), rev) |
| 336 | return db.setOldRevisionJSONBody(ctx, docid, rev, body, expiry) |
| 337 | } |
| 338 | |
| 339 | // store channels as optional metadata in the backup |
| 340 | // not stored as a real Couchbase Server xattr since we need to write this as a binary document |
| 341 | channelsJSON, err := channels.MarshalJSON() |
| 342 | if err != nil { |
| 343 | return fmt.Errorf("error marshalling channels for old revision %q / %q: %v", base.UD(docid), rev, err) |
| 344 | } |
| 345 | deletedJSON, err := base.JSONMarshal(deletedDoc) |
| 346 | if err != nil { |
| 347 | return fmt.Errorf("error marshalling deleted flag for old revision %q / %q: %v", base.UD(docid), rev, err) |
| 348 | } |
| 349 | meta := []sgbucket.Xattr{ |
| 350 | {Name: backupRevisionChannelsMetaKey, Value: channelsJSON}, |
| 351 | {Name: backupRevisionBodyDeletedMetaKey, Value: deletedJSON}, |
| 352 | } |
| 353 | bodyWithMeta := sgbucket.EncodeValueWithXattrs(body, meta...) |
| 354 | nonJSONBytes := withNonJSONPrefix(nonJSONPrefixKindRevWithMeta, bodyWithMeta) |
| 355 | |
| 356 | err = db.dataStore.SetRaw(oldRevisionKey(docid, rev), expiry, nil, nonJSONBytes) |
| 357 | if err != nil { |
| 358 | base.WarnfCtx(ctx, "setOldRevisionJSONBodyWithMeta failed: doc=%q rev=%q err=%v", base.UD(docid), rev, err) |
| 359 | return err |
| 360 | } |
| 361 | |
| 362 | base.DebugfCtx(ctx, base.KeyCRUD, "Backed up revision body (with meta) %q/%q (%d bytes, ttl:%d)", base.UD(docid), rev, len(body), expiry) |
| 363 | return nil |
| 364 | } |
| 365 | |
| 366 | // Extends the expiry on a revision backup. If this fails w/ key not found, will attempt to recreate the revision backup when body is non-empty. |
| 367 | func (db *DatabaseCollectionWithUser) refreshOldRevisionJSON(ctx context.Context, docid string, revid string, body []byte, expiry uint32, channels base.Set, deleted bool) error { |
no test coverage detected