Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBG-3956 replace GetAllScopes call to work with CBS 7.6 #6854

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions base/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,44 @@ func (b *GocbV2Bucket) ListDataStores() ([]sgbucket.DataStoreName, error) {
if !b.IsSupported(sgbucket.BucketStoreFeatureCollections) {
return []sgbucket.DataStoreName{ScopeAndCollectionName{DefaultScope, DefaultCollection}}, nil
}
scopes, err := b.bucket.Collections().GetAllScopes(nil)

// ListDataStores is used only by integration test harness, so call mgmt API directly as a workaround for GOCBC-1586, fixed in newer gocb, see CBG-3711
uri := fmt.Sprintf("/pools/default/buckets/%s/scopes", b.GetName())
resp, err := b.mgmtRequest(context.Background(), http.MethodGet, uri, "application/json", nil)
if err != nil {
return nil, fmt.Errorf("Could not get bucket listing %w", err)
}

defer func() { _ = resp.Body.Close() }()

respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

type collectionResponse struct {
Name string `json:"name"`
}
type scopeResponse struct {
Name string `json:"name"`
Collections []collectionResponse `json:"collections"`
}
type allScopesResponse struct {
Scopes []scopeResponse `json:"scopes"`
}

var scopes allScopesResponse
err = JSONUnmarshal(respBytes, &scopes)
if err != nil {
return nil, err
}

collections := make([]sgbucket.DataStoreName, 0)
for _, s := range scopes {
for _, s := range scopes.Scopes {
// skip the _system scope to match GetAllScopes(nil) behavior
if s.Name == "_system" {
continue
}
for _, c := range s.Collections {
collections = append(collections, ScopeAndCollectionName{s.Name, c.Name})
}
Expand Down
Loading