Skip to content

Commit

Permalink
ING-782: Update WaitForIndexOnline to handle empty scope/collection
Browse files Browse the repository at this point in the history
  • Loading branch information
chvck committed Nov 26, 2024
1 parent ef8be2c commit a8548ea
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
23 changes: 16 additions & 7 deletions gateway/dataimpl/server_v1/queryadminserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,20 @@ func (s *QueryIndexAdminServer) WaitForIndexOnline(
ctx context.Context,
in *admin_query_v1.WaitForIndexOnlineRequest,
) (*admin_query_v1.WaitForIndexOnlineResponse, error) {
scopeName := "_default"
collectionName := "_default"
if in.ScopeName != "" {
scopeName = in.ScopeName
}
if in.CollectionName != "" {
collectionName = in.CollectionName
}

for {
watchIndexesResp, err := s.GetAllIndexes(ctx, &admin_query_v1.GetAllIndexesRequest{
BucketName: &in.BucketName,
ScopeName: &in.ScopeName,
CollectionName: &in.CollectionName,
ScopeName: &scopeName,
CollectionName: &collectionName,
})
if err != nil {
return nil, err
Expand All @@ -874,8 +883,8 @@ func (s *QueryIndexAdminServer) WaitForIndexOnline(
var foundIndex *admin_query_v1.GetAllIndexesResponse_Index
for _, index := range watchIndexesResp.Indexes {
if index.Name == in.Name &&
index.CollectionName == in.CollectionName &&
index.ScopeName == in.ScopeName &&
index.CollectionName == collectionName &&
index.ScopeName == scopeName &&
index.BucketName == in.BucketName {
foundIndex = index
}
Expand All @@ -886,13 +895,13 @@ func (s *QueryIndexAdminServer) WaitForIndexOnline(
nil,
in.Name,
in.BucketName,
in.ScopeName,
in.CollectionName).Err()
scopeName,
collectionName).Err()
}

if foundIndex.State == admin_query_v1.IndexState_INDEX_STATE_DEFERRED {
return nil, s.errorHandler.NewQueryIndexNotBuildingStatus(
nil, in.BucketName, in.ScopeName, in.CollectionName, in.Name).Err()
nil, in.BucketName, scopeName, collectionName, in.Name).Err()
}

if foundIndex.State == admin_query_v1.IndexState_INDEX_STATE_ONLINE {
Expand Down
44 changes: 44 additions & 0 deletions gateway/test/query_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,3 +1059,47 @@ func (s *GatewayOpsTestSuite) TestQueryManagementBuildDeferredBuildsSpecificColl
}, grpc.PerRPCCredentials(s.basicRpcCreds))
assertRpcStatus(s.T(), err, codes.InvalidArgument)
}

// This test ensures that an empty collection and scope are treated as _default.
func (s *GatewayOpsTestSuite) TestQueryManagementWaitForIndexOnlineEmptyCollectionAndScope() {
if !s.SupportsFeature(TestFeatureQueryManagement) {
s.T().Skip()
}

queryAdminClient := admin_query_v1.NewQueryAdminServiceClient(s.gatewayConn)

defaultScope := "_default"
defaultCollection := "_default"

indexName := uuid.NewString()
trueBool := true

createIndex := func(scopeName, collectionName string) {
iResp, err := queryAdminClient.CreateIndex(context.Background(), &admin_query_v1.CreateIndexRequest{
Name: indexName,
BucketName: s.bucketName,
ScopeName: &scopeName,
CollectionName: &collectionName,
Fields: []string{"test"},
Deferred: &trueBool,
}, grpc.PerRPCCredentials(s.basicRpcCreds))
requireRpcSuccess(s.T(), iResp, err)
}

createIndex(defaultScope, defaultCollection)

buildResp, err := queryAdminClient.BuildDeferredIndexes(context.Background(), &admin_query_v1.BuildDeferredIndexesRequest{
BucketName: s.bucketName,
ScopeName: &defaultScope,
CollectionName: &defaultCollection,
}, grpc.PerRPCCredentials(s.basicRpcCreds))
requireRpcSuccess(s.T(), buildResp, err)

waitResp, err := queryAdminClient.WaitForIndexOnline(context.Background(), &admin_query_v1.WaitForIndexOnlineRequest{
BucketName: s.bucketName,
ScopeName: "",
CollectionName: "",
Name: indexName,
}, grpc.PerRPCCredentials(s.basicRpcCreds))
requireRpcSuccess(s.T(), waitResp, err)
}

0 comments on commit a8548ea

Please sign in to comment.