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

Method setCollectionID

base/collection_gocb.go:562–610  ·  view source on GitHub ↗

setCollectionID sets private property of kv CollectionID.

()

Source from the content-addressed store, hash-verified

560
561// setCollectionID sets private property of kv CollectionID.
562func (c *Collection) setCollectionID() error {
563 if !c.IsSupported(sgbucket.BucketStoreFeatureCollections) {
564 c.kvCollectionID = DefaultCollectionID
565 return nil
566 }
567 // default collection has a known ID
568 if c.IsDefaultScopeCollection() {
569 c.kvCollectionID = DefaultCollectionID
570 return nil
571 }
572 agent, err := c.Bucket.GetGoCBAgent()
573 if err != nil {
574 return err
575 }
576 scope := c.ScopeName()
577 collection := c.CollectionName()
578 wg := sync.WaitGroup{}
579 wg.Add(1)
580 var callbackErr error
581 callbackFunc := func(res *gocbcore.GetCollectionIDResult, getCollectionErr error) {
582 defer wg.Done()
583 if getCollectionErr != nil {
584 callbackErr = getCollectionErr
585 return
586 }
587 if res == nil {
588 callbackErr = fmt.Errorf("getCollectionID not retrieved for %s.%s", scope, collection)
589 return
590 }
591
592 c.kvCollectionID = res.CollectionID
593 }
594 _, err = agent.GetCollectionID(scope,
595 collection,
596 gocbcore.GetCollectionIDOptions{
597 Deadline: c.Bucket.getBucketOpDeadline(),
598 },
599 callbackFunc)
600
601 if err != nil {
602 wg.Done()
603 return fmt.Errorf("GetCollectionID for %s.%s, err: %w", scope, collection, err)
604 }
605 wg.Wait()
606 if callbackErr != nil {
607 return fmt.Errorf("GetCollectionID for %s.%s, err: %w", scope, collection, callbackErr)
608 }
609 return nil
610}

Callers 1

NewCollectionFunction · 0.95

Calls 11

IsSupportedMethod · 0.95
ScopeNameMethod · 0.95
CollectionNameMethod · 0.95
GetGoCBAgentMethod · 0.80
DoneMethod · 0.80
ErrorfMethod · 0.80
getBucketOpDeadlineMethod · 0.80
AddMethod · 0.45
GetCollectionIDMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected