Skip to content

Commit ab87d31

Browse files
committed
[ENH]: add batch get version file paths method to Sysdb
1 parent 8fa5a73 commit ab87d31

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

go/pkg/sysdb/coordinator/coordinator.go

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ func (s *Coordinator) DeleteCollectionVersion(ctx context.Context, req *coordina
259259
return s.catalog.DeleteCollectionVersion(ctx, req)
260260
}
261261

262+
func (s *Coordinator) BatchGetCollectionVersionFilePaths(ctx context.Context, req *coordinatorpb.BatchGetCollectionVersionFilePathsRequest) (*coordinatorpb.BatchGetCollectionVersionFilePathsResponse, error) {
263+
return s.catalog.BatchGetCollectionVersionFilePaths(ctx, req)
264+
}
265+
262266
// SetDeleteMode sets the delete mode for testing
263267
func (c *Coordinator) SetDeleteMode(mode DeleteMode) {
264268
c.deleteMode = mode

go/pkg/sysdb/coordinator/coordinator_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12+
"github.com/chroma-core/chroma/go/pkg/proto/coordinatorpb"
1213
"github.com/chroma-core/chroma/go/pkg/sysdb/metastore/db/dao"
1314
s3metastore "github.com/chroma-core/chroma/go/pkg/sysdb/metastore/s3"
1415
"github.com/pingcap/log"
@@ -1484,6 +1485,34 @@ func (suite *APIsTestSuite) TestForkCollection() {
14841485
suite.Empty(collections)
14851486
}
14861487

1488+
func (suite *APIsTestSuite) TestBatchGetCollectionVersionFilePaths() {
1489+
ctx := context.Background()
1490+
1491+
// Create a new collection
1492+
newCollection := &model.CreateCollection{
1493+
ID: types.NewUniqueID(),
1494+
Name: "test_batch_get_collection_version_file_paths",
1495+
TenantID: suite.tenantName,
1496+
DatabaseName: suite.databaseName,
1497+
}
1498+
1499+
// Create the collection
1500+
_, _, err := suite.coordinator.CreateCollection(ctx, newCollection)
1501+
suite.NoError(err)
1502+
1503+
// Get the version file paths for the collection
1504+
versionFilePaths, err := suite.coordinator.BatchGetCollectionVersionFilePaths(ctx, &coordinatorpb.BatchGetCollectionVersionFilePathsRequest{
1505+
CollectionIds: []string{newCollection.ID.String()},
1506+
})
1507+
suite.NoError(err)
1508+
suite.Len(versionFilePaths, 1)
1509+
1510+
// Verify version file exists in S3
1511+
exists, err := suite.s3MetaStore.HasObjectWithPrefix(ctx, versionFilePaths.CollectionIdToVersionFilePath[newCollection.ID.String()])
1512+
suite.NoError(err)
1513+
suite.True(exists, "Version file should exist in S3")
1514+
}
1515+
14871516
func TestAPIsTestSuite(t *testing.T) {
14881517
testSuite := new(APIsTestSuite)
14891518
suite.Run(t, testSuite)

go/pkg/sysdb/coordinator/table_catalog.go

+20
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,26 @@ func (tc *Catalog) DeleteCollectionVersion(ctx context.Context, req *coordinator
19411941
return &result, nil
19421942
}
19431943

1944+
func (tc *Catalog) BatchGetCollectionVersionFilePaths(ctx context.Context, req *coordinatorpb.BatchGetCollectionVersionFilePathsRequest) (*coordinatorpb.BatchGetCollectionVersionFilePathsResponse, error) {
1945+
result := coordinatorpb.BatchGetCollectionVersionFilePathsResponse{
1946+
CollectionIdToVersionFilePath: make(map[string]string),
1947+
}
1948+
1949+
for _, collectionId := range req.CollectionIds {
1950+
collectionIDPtr := &collectionId
1951+
collectionEntry, err := tc.metaDomain.CollectionDb(ctx).GetCollectionEntry(collectionIDPtr, nil)
1952+
if err != nil {
1953+
return nil, err
1954+
}
1955+
if collectionEntry == nil {
1956+
return nil, common.ErrCollectionNotFound
1957+
}
1958+
1959+
result.CollectionIdToVersionFilePath[collectionId] = collectionEntry.VersionFileName
1960+
}
1961+
return &result, nil
1962+
}
1963+
19441964
func (tc *Catalog) GetVersionFileNamesForCollection(ctx context.Context, tenantID string, collectionID string) (string, error) {
19451965
collectionIDPtr := &collectionID
19461966
collectionEntry, err := tc.metaDomain.CollectionDb(ctx).GetCollectionEntry(collectionIDPtr, nil)

go/pkg/sysdb/grpc/collection_service.go

+8
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,11 @@ func (s *Server) DeleteCollectionVersion(ctx context.Context, req *coordinatorpb
517517
}
518518
return res, nil
519519
}
520+
521+
func (s *Server) BatchGetCollectionVersionFilePaths(ctx context.Context, req *coordinatorpb.BatchGetCollectionVersionFilePathsRequest) (*coordinatorpb.BatchGetCollectionVersionFilePathsResponse, error) {
522+
res, err := s.coordinator.BatchGetCollectionVersionFilePaths(ctx, req)
523+
if err != nil {
524+
return nil, grpcutils.BuildInternalGrpcError(err.Error())
525+
}
526+
return res, nil
527+
}

idl/chromadb/proto/coordinator.proto

+9
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@ message DeleteCollectionVersionResponse {
456456
map<string, bool> collection_id_to_success = 1;
457457
}
458458

459+
message BatchGetCollectionVersionFilePathsRequest {
460+
repeated string collection_ids = 1;
461+
}
462+
463+
message BatchGetCollectionVersionFilePathsResponse {
464+
map<string, string> collection_id_to_version_file_path = 1;
465+
}
466+
459467
service SysDB {
460468
rpc CreateDatabase(CreateDatabaseRequest) returns (CreateDatabaseResponse) {}
461469
rpc GetDatabase(GetDatabaseRequest) returns (GetDatabaseResponse) {}
@@ -486,4 +494,5 @@ service SysDB {
486494
rpc ListCollectionsToGc(ListCollectionsToGcRequest) returns (ListCollectionsToGcResponse) {}
487495
rpc MarkVersionForDeletion(MarkVersionForDeletionRequest) returns (MarkVersionForDeletionResponse) {}
488496
rpc DeleteCollectionVersion(DeleteCollectionVersionRequest) returns (DeleteCollectionVersionResponse) {}
497+
rpc BatchGetCollectionVersionFilePaths(BatchGetCollectionVersionFilePathsRequest) returns (BatchGetCollectionVersionFilePathsResponse) {}
489498
}

0 commit comments

Comments
 (0)