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

Method getBucket

base/bootstrap.go:492–520  ·  view source on GitHub ↗
(ctx context.Context, bucketName string)

Source from the content-addressed store, hash-verified

490}
491
492func (cc *CouchbaseCluster) getBucket(ctx context.Context, bucketName string) (b *gocb.Bucket, teardownFn func(), err error) {
493
494 if cc.bucketConnectionMode != CachedClusterConnections {
495 return cc.connectToBucket(ctx, bucketName)
496 }
497
498 teardownFn = func() {
499 cc.cachedBucketConnections.teardown(bucketName)
500 }
501 cc.cachedBucketConnections.lock.Lock()
502 defer cc.cachedBucketConnections.lock.Unlock()
503 bucket := cc.cachedBucketConnections._get(bucketName)
504 if bucket != nil {
505 return bucket.bucket, teardownFn, nil
506 }
507
508 // cached bucket not found, connect and add
509 newBucket, bucketCloseFn, err := cc.connectToBucket(ctx, bucketName)
510 if err != nil {
511 return nil, nil, err
512 }
513 cc.cachedBucketConnections._set(bucketName, &cachedBucket{
514 bucket: newBucket,
515 bucketCloseFn: bucketCloseFn,
516 refcount: 1,
517 })
518
519 return newBucket, teardownFn, nil
520}
521
522func (cc *CouchbaseCluster) GetClusterConnectionForBucket(ctx context.Context, bucketName string) (connection *gocb.Cluster, teardownFn func(), err error) {
523 if bucketAuth, set := cc.perBucketAuth[bucketName]; set {

Callers 9

TestBootstrapRefCountingFunction · 0.95
GetMetadataDocumentMethod · 0.95
WriteMetadataDocumentMethod · 0.95
TouchMetadataDocumentMethod · 0.95
KeyExistsMethod · 0.95
GetDocumentMethod · 0.95

Calls 6

connectToBucketMethod · 0.95
teardownMethod · 0.80
_getMethod · 0.80
_setMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestBootstrapRefCountingFunction · 0.76