9
9
"testing"
10
10
"time"
11
11
12
+ "github.com/chroma-core/chroma/go/pkg/proto/coordinatorpb"
12
13
"github.com/chroma-core/chroma/go/pkg/sysdb/metastore/db/dao"
13
14
s3metastore "github.com/chroma-core/chroma/go/pkg/sysdb/metastore/s3"
14
15
"github.com/pingcap/log"
@@ -179,8 +180,8 @@ func testSegment(t *rapid.T) {
179
180
180
181
t .Repeat (map [string ]func (* rapid.T ){
181
182
"create_segment" : func (t * rapid.T ) {
182
- segment := rapid.Custom [* model.CreateSegment ](func (t * rapid.T ) * model.CreateSegment {
183
- return & model.CreateSegment {
183
+ segment := rapid.Custom [* model.Segment ](func (t * rapid.T ) * model.Segment {
184
+ return & model.Segment {
184
185
ID : types .MustParse (rapid .StringMatching (`[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}` ).Draw (t , "segment_id" )),
185
186
Type : "test-segment-type" ,
186
187
Scope : "test-segment-scope" ,
@@ -294,7 +295,7 @@ func (suite *APIsTestSuite) TestCreateCollectionAndSegments() {
294
295
DatabaseName : suite .databaseName ,
295
296
}
296
297
297
- segments := []* model.CreateSegment {
298
+ segments := []* model.Segment {
298
299
{
299
300
ID : types .NewUniqueID (),
300
301
Type : "test_type" ,
@@ -306,6 +307,9 @@ func (suite *APIsTestSuite) TestCreateCollectionAndSegments() {
306
307
Type : "test_type" ,
307
308
Scope : "VECTOR" ,
308
309
CollectionID : newCollection .ID ,
310
+ FilePaths : map [string ][]string {
311
+ "test_path" : {"test_file1" },
312
+ },
309
313
},
310
314
}
311
315
@@ -347,6 +351,22 @@ func (suite *APIsTestSuite) TestCreateCollectionAndSegments() {
347
351
}
348
352
suite .ElementsMatch (expected_ids , actual_ids )
349
353
354
+ // Validate version file
355
+ versionFilePathPrefix := suite .s3MetaStore .GetVersionFilePath (collection .TenantID , suite .databaseId , newCollection .ID .String (), "0" )
356
+ versionFile , err := suite .s3MetaStore .GetVersionFile (versionFilePathPrefix )
357
+ suite .NoError (err )
358
+ suite .NotNil (versionFile )
359
+ v0 := versionFile .VersionHistory .Versions [0 ]
360
+ suite .NotNil (v0 )
361
+
362
+ // Validate file paths of segments
363
+ suite .NotNil (v0 .SegmentInfo )
364
+ suite .NotNil (v0 .SegmentInfo .SegmentCompactionInfo )
365
+ suite .Equal (len (v0 .SegmentInfo .SegmentCompactionInfo ), 2 )
366
+ for _ , segment := range segments {
367
+ assertExpectedSegmentInfoExist (suite , segment , v0 .SegmentInfo .SegmentCompactionInfo )
368
+ }
369
+
350
370
// Attempt to create a duplicate collection (should fail)
351
371
_ , _ , err = suite .coordinator .CreateCollectionAndSegments (ctx , newCollection , segments )
352
372
suite .Error (err )
@@ -486,7 +506,7 @@ func (suite *APIsTestSuite) TestCreateGetDeleteCollections() {
486
506
suite .Equal (createCollection .Metadata , results [0 ].Metadata )
487
507
488
508
// Create segments associated with collection
489
- segment := & model.CreateSegment {
509
+ segment := & model.Segment {
490
510
ID : types .MustParse ("00000000-0000-0000-0000-000000000001" ),
491
511
CollectionID : createCollection .ID ,
492
512
Type : "test_segment" ,
@@ -993,7 +1013,7 @@ func (suite *APIsTestSuite) TestCreateGetDeleteSegments() {
993
1013
994
1014
sampleSegments := SampleSegments (suite .sampleCollections )
995
1015
for _ , segment := range sampleSegments {
996
- errSegmentCreation := c .CreateSegment (ctx , & model.CreateSegment {
1016
+ errSegmentCreation := c .CreateSegment (ctx , & model.Segment {
997
1017
ID : segment .ID ,
998
1018
Type : segment .Type ,
999
1019
Scope : segment .Scope ,
@@ -1003,7 +1023,7 @@ func (suite *APIsTestSuite) TestCreateGetDeleteSegments() {
1003
1023
suite .NoError (errSegmentCreation )
1004
1024
1005
1025
// Create segment with empty collection id fails
1006
- errSegmentCreation = c .CreateSegment (ctx , & model.CreateSegment {
1026
+ errSegmentCreation = c .CreateSegment (ctx , & model.Segment {
1007
1027
ID : segment .ID ,
1008
1028
Type : segment .Type ,
1009
1029
Scope : segment .Scope ,
@@ -1014,7 +1034,7 @@ func (suite *APIsTestSuite) TestCreateGetDeleteSegments() {
1014
1034
1015
1035
// Create segment to test unique constraint violation on segment.id.
1016
1036
// This should fail because the id is already taken.
1017
- errSegmentCreation = c .CreateSegment (ctx , & model.CreateSegment {
1037
+ errSegmentCreation = c .CreateSegment (ctx , & model.Segment {
1018
1038
ID : segment .ID ,
1019
1039
Type : segment .Type ,
1020
1040
Scope : segment .Scope ,
@@ -1037,7 +1057,7 @@ func (suite *APIsTestSuite) TestCreateGetDeleteSegments() {
1037
1057
suite .Equal (sampleSegments , results )
1038
1058
1039
1059
// Duplicate create fails
1040
- err := c .CreateSegment (ctx , & model.CreateSegment {
1060
+ err := c .CreateSegment (ctx , & model.Segment {
1041
1061
ID : sampleSegments [0 ].ID ,
1042
1062
Type : sampleSegments [0 ].Type ,
1043
1063
Scope : sampleSegments [0 ].Scope ,
@@ -1108,7 +1128,7 @@ func (suite *APIsTestSuite) TestUpdateSegment() {
1108
1128
}
1109
1129
1110
1130
ctx := context .Background ()
1111
- errSegmentCreation := suite .coordinator .CreateSegment (ctx , & model.CreateSegment {
1131
+ errSegmentCreation := suite .coordinator .CreateSegment (ctx , & model.Segment {
1112
1132
ID : segment .ID ,
1113
1133
Type : segment .Type ,
1114
1134
Scope : segment .Scope ,
@@ -1313,7 +1333,7 @@ func (suite *APIsTestSuite) TestCollectionVersioningWithMinio() {
1313
1333
DatabaseName : suite .databaseName ,
1314
1334
}
1315
1335
1316
- segments := []* model.CreateSegment {
1336
+ segments := []* model.Segment {
1317
1337
{
1318
1338
ID : types .NewUniqueID (),
1319
1339
Type : "test_type_a" ,
@@ -1353,6 +1373,33 @@ func (suite *APIsTestSuite) TestCollectionVersioningWithMinio() {
1353
1373
// suite.True(exists, "Version file should exist in S3")
1354
1374
}
1355
1375
1376
+ func findSegmentInfo (segmentID types.UniqueID , segmentInfos []* coordinatorpb.FlushSegmentCompactionInfo ) * coordinatorpb.FlushSegmentCompactionInfo {
1377
+ for _ , segmentInfo := range segmentInfos {
1378
+ if segmentInfo .SegmentId == segmentID .String () {
1379
+ return segmentInfo
1380
+ }
1381
+ }
1382
+ return nil
1383
+ }
1384
+
1385
+ func assertExpectedSegmentInfoExist (suite * APIsTestSuite , expectedSegment * model.Segment , segmentInfos []* coordinatorpb.FlushSegmentCompactionInfo ) {
1386
+ segmentInfo := findSegmentInfo (expectedSegment .ID , segmentInfos )
1387
+ suite .NotNil (segmentInfo )
1388
+
1389
+ if expectedSegment .FilePaths == nil {
1390
+ suite .Nil (segmentInfo .FilePaths )
1391
+ return
1392
+ }
1393
+
1394
+ suite .NotNil (segmentInfo .FilePaths )
1395
+
1396
+ filePaths := map [string ][]string {}
1397
+ for key , filePath := range segmentInfo .FilePaths {
1398
+ filePaths [key ] = filePath .Paths
1399
+ }
1400
+ suite .Equal (filePaths , expectedSegment .FilePaths )
1401
+ }
1402
+
1356
1403
func (suite * APIsTestSuite ) TestForkCollection () {
1357
1404
ctx := context .Background ()
1358
1405
@@ -1363,28 +1410,28 @@ func (suite *APIsTestSuite) TestForkCollection() {
1363
1410
DatabaseName : suite .databaseName ,
1364
1411
}
1365
1412
1366
- sourceCreateMetadataSegment := & model.CreateSegment {
1413
+ sourceCreateMetadataSegment := & model.Segment {
1367
1414
ID : types .NewUniqueID (),
1368
1415
Type : "test_blockfile" ,
1369
1416
Scope : "METADATA" ,
1370
1417
CollectionID : sourceCreateCollection .ID ,
1371
1418
}
1372
1419
1373
- sourceCreateRecordSegment := & model.CreateSegment {
1420
+ sourceCreateRecordSegment := & model.Segment {
1374
1421
ID : types .NewUniqueID (),
1375
1422
Type : "test_blockfile" ,
1376
1423
Scope : "RECORD" ,
1377
1424
CollectionID : sourceCreateCollection .ID ,
1378
1425
}
1379
1426
1380
- sourceCreateVectorSegment := & model.CreateSegment {
1427
+ sourceCreateVectorSegment := & model.Segment {
1381
1428
ID : types .NewUniqueID (),
1382
1429
Type : "test_hnsw" ,
1383
1430
Scope : "VECTOR" ,
1384
1431
CollectionID : sourceCreateCollection .ID ,
1385
1432
}
1386
1433
1387
- segments := []* model.CreateSegment {
1434
+ segments := []* model.Segment {
1388
1435
sourceCreateMetadataSegment ,
1389
1436
sourceCreateRecordSegment ,
1390
1437
sourceCreateVectorSegment ,
@@ -1467,6 +1514,22 @@ func (suite *APIsTestSuite) TestForkCollection() {
1467
1514
}
1468
1515
}
1469
1516
1517
+ // Check version file of forked collection
1518
+ versionFilePathPrefix := suite .s3MetaStore .GetVersionFilePath (collection .TenantID , suite .databaseId , forkCollection .TargetCollectionID .String (), "0" )
1519
+ versionFile , err := suite .s3MetaStore .GetVersionFile (versionFilePathPrefix )
1520
+ suite .NoError (err )
1521
+ suite .NotNil (versionFile )
1522
+ v0 := versionFile .VersionHistory .Versions [0 ]
1523
+ suite .NotNil (v0 )
1524
+ // Validate file paths of segments
1525
+ suite .NotNil (v0 .SegmentInfo )
1526
+ suite .NotNil (v0 .SegmentInfo .SegmentCompactionInfo )
1527
+ suite .Equal (len (v0 .SegmentInfo .SegmentCompactionInfo ), 3 )
1528
+
1529
+ for _ , segment := range collection_segments {
1530
+ assertExpectedSegmentInfoExist (suite , segment , v0 .SegmentInfo .SegmentCompactionInfo )
1531
+ }
1532
+
1470
1533
// Attempt to fork a collcetion with same name (should fail)
1471
1534
forkCollectionWithSameName := & model.ForkCollection {
1472
1535
SourceCollectionID : sourceCreateCollection .ID ,
@@ -1505,28 +1568,28 @@ func (suite *APIsTestSuite) TestCountForks() {
1505
1568
DatabaseName : suite .databaseName ,
1506
1569
}
1507
1570
1508
- sourceCreateMetadataSegment := & model.CreateSegment {
1571
+ sourceCreateMetadataSegment := & model.Segment {
1509
1572
ID : types .NewUniqueID (),
1510
1573
Type : "test_blockfile" ,
1511
1574
Scope : "METADATA" ,
1512
1575
CollectionID : sourceCreateCollection .ID ,
1513
1576
}
1514
1577
1515
- sourceCreateRecordSegment := & model.CreateSegment {
1578
+ sourceCreateRecordSegment := & model.Segment {
1516
1579
ID : types .NewUniqueID (),
1517
1580
Type : "test_blockfile" ,
1518
1581
Scope : "RECORD" ,
1519
1582
CollectionID : sourceCreateCollection .ID ,
1520
1583
}
1521
1584
1522
- sourceCreateVectorSegment := & model.CreateSegment {
1585
+ sourceCreateVectorSegment := & model.Segment {
1523
1586
ID : types .NewUniqueID (),
1524
1587
Type : "test_hnsw" ,
1525
1588
Scope : "VECTOR" ,
1526
1589
CollectionID : sourceCreateCollection .ID ,
1527
1590
}
1528
1591
1529
- segments := []* model.CreateSegment {
1592
+ segments := []* model.Segment {
1530
1593
sourceCreateMetadataSegment ,
1531
1594
sourceCreateRecordSegment ,
1532
1595
sourceCreateVectorSegment ,
0 commit comments