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

Method persistModifiedRevisionBodies

db/document.go:861–888  ·  view source on GitHub ↗

persistModifiedRevisionBodies writes new non-inline revisions to the bucket. Should be invoked BEFORE the document is successfully committed.

(datastore sgbucket.DataStore)

Source from the content-addressed store, hash-verified

859// persistModifiedRevisionBodies writes new non-inline revisions to the bucket.
860// Should be invoked BEFORE the document is successfully committed.
861func (doc *Document) persistModifiedRevisionBodies(datastore sgbucket.DataStore) error {
862
863 for _, revID := range doc.addedRevisionBodies {
864 // if this rev is also in the delete set, skip add/delete
865 _, ok := doc.removedRevisionBodyKeys[revID]
866 if ok {
867 delete(doc.removedRevisionBodyKeys, revID)
868 continue
869 }
870
871 revInfo, err := doc.History.getInfo(revID)
872 if revInfo == nil || err != nil {
873 return err
874 }
875 if revInfo.BodyKey == "" || len(revInfo.Body) == 0 {
876 return base.RedactErrorf("Missing key or body for revision during external persistence. doc: %s rev:%s key: %s len(body): %d", base.UD(doc.ID), revID, base.UD(revInfo.BodyKey), len(revInfo.Body))
877 }
878
879 // If addRaw indicates that the doc already exists, can ignore. Another writer already persisted this rev backup.
880 addErr := doc.persistRevisionBody(datastore, revInfo.BodyKey, revInfo.Body)
881 if addErr != nil {
882 return err
883 }
884 }
885
886 doc.addedRevisionBodies = []string{}
887 return nil
888}
889
890// deleteRemovedRevisionBodies deletes obsolete non-inline revisions from the bucket.
891// Should be invoked AFTER the document is successfully committed.

Callers 1

documentUpdateFuncMethod · 0.80

Calls 4

persistRevisionBodyMethod · 0.95
RedactErrorfFunction · 0.92
UDFunction · 0.92
getInfoMethod · 0.80

Tested by

no test coverage detected