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

Method WriteMetadataDocument

base/bootstrap.go:327–348  ·  view source on GitHub ↗

WriteMetadataDocument writes a metadata document, and fails on CAS mismatch

(ctx context.Context, location, docID string, cas uint64, value interface{})

Source from the content-addressed store, hash-verified

325
326// WriteMetadataDocument writes a metadata document, and fails on CAS mismatch
327func (cc *CouchbaseCluster) WriteMetadataDocument(ctx context.Context, location, docID string, cas uint64, value interface{}) (newCAS uint64, err error) {
328 if cc == nil {
329 return 0, errors.New("nil CouchbaseCluster")
330 }
331 if cas == 0 {
332 return 0, RedactErrorf("CAS for %q in bucket %q must be non-zero to call WriteMetadataDocument, to add a new document use InsertMetadataDocument", MD(docID), MD(location))
333 }
334
335 b, teardown, err := cc.getBucket(ctx, location)
336 if err != nil {
337 return 0, err
338 }
339 defer teardown()
340
341 rawDocument, err := JSONMarshal(value)
342 if err != nil {
343 return 0, err
344 }
345
346 casOut, err := cc.configPersistence.replaceRawConfig(b.DefaultCollection(), docID, rawDocument, gocb.Cas(cas))
347 return uint64(casOut), err
348}
349
350func (cc *CouchbaseCluster) TouchMetadataDocument(ctx context.Context, location, docID string, property, value string, cas uint64) (newCAS uint64, err error) {
351

Callers

nothing calls this directly

Calls 6

getBucketMethod · 0.95
RedactErrorfFunction · 0.85
MDFunction · 0.85
JSONMarshalFunction · 0.70
replaceRawConfigMethod · 0.65
CasMethod · 0.65

Tested by

no test coverage detected