setCollectionID sets private property of kv CollectionID.
()
| 560 | |
| 561 | // setCollectionID sets private property of kv CollectionID. |
| 562 | func (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 | } |
no test coverage detected