@@ -1389,20 +1389,35 @@ func (tc *Catalog) ListCollectionVersions(ctx context.Context,
1389
1389
return filteredVersions , nil
1390
1390
}
1391
1391
1392
- func (tc * Catalog ) updateVersionFileInS3 (ctx context. Context , existingVersionFilePb * coordinatorpb.CollectionVersionFile , flushCollectionCompaction * model.FlushCollectionCompaction , ts_secs int64 ) (string , error ) {
1392
+ func (tc * Catalog ) updateVersionFileInS3 (existingVersionFilePb * coordinatorpb.CollectionVersionFile , flushCollectionCompaction * model.FlushCollectionCompaction , previousSegmentInfo [] * model. Segment , ts_secs int64 ) (string , error ) {
1393
1393
segmentCompactionInfos := make ([]* coordinatorpb.FlushSegmentCompactionInfo , 0 , len (flushCollectionCompaction .FlushSegmentCompactions ))
1394
- for _ , compaction := range flushCollectionCompaction .FlushSegmentCompactions {
1395
- // Convert map[string][]string to map[string]*coordinatorpb.FilePaths
1396
- convertedPaths := make (map [string ]* coordinatorpb.FilePaths )
1397
- for k , v := range compaction .FilePaths {
1398
- convertedPaths [k ] = & coordinatorpb.FilePaths {Paths : v }
1394
+ // If flushCollectionCompaction.FlushSegmentCompactions is empty then use previousSegmentInfo.
1395
+ if len (flushCollectionCompaction .FlushSegmentCompactions ) == 0 {
1396
+ for _ , segment := range previousSegmentInfo {
1397
+ convertedPaths := make (map [string ]* coordinatorpb.FilePaths )
1398
+ for k , v := range segment .FilePaths {
1399
+ convertedPaths [k ] = & coordinatorpb.FilePaths {Paths : v }
1400
+ }
1401
+ info := & coordinatorpb.FlushSegmentCompactionInfo {
1402
+ SegmentId : segment .ID .String (),
1403
+ FilePaths : convertedPaths ,
1404
+ }
1405
+ segmentCompactionInfos = append (segmentCompactionInfos , info )
1399
1406
}
1407
+ } else {
1408
+ for _ , compaction := range flushCollectionCompaction .FlushSegmentCompactions {
1409
+ // Convert map[string][]string to map[string]*coordinatorpb.FilePaths
1410
+ convertedPaths := make (map [string ]* coordinatorpb.FilePaths )
1411
+ for k , v := range compaction .FilePaths {
1412
+ convertedPaths [k ] = & coordinatorpb.FilePaths {Paths : v }
1413
+ }
1400
1414
1401
- info := & coordinatorpb.FlushSegmentCompactionInfo {
1402
- SegmentId : compaction .ID .String (),
1403
- FilePaths : convertedPaths ,
1415
+ info := & coordinatorpb.FlushSegmentCompactionInfo {
1416
+ SegmentId : compaction .ID .String (),
1417
+ FilePaths : convertedPaths ,
1418
+ }
1419
+ segmentCompactionInfos = append (segmentCompactionInfos , info )
1404
1420
}
1405
- segmentCompactionInfos = append (segmentCompactionInfos , info )
1406
1421
}
1407
1422
1408
1423
existingVersionFilePb .GetVersionHistory ().Versions = append (existingVersionFilePb .GetVersionHistory ().Versions , & coordinatorpb.CollectionVersionInfo {
@@ -1544,7 +1559,8 @@ func (tc *Catalog) FlushCollectionCompactionForVersionedCollection(ctx context.C
1544
1559
for numAttempts < maxAttempts {
1545
1560
numAttempts ++
1546
1561
// Get the current version info and the version file from the table.
1547
- collectionEntry , err := tc .metaDomain .CollectionDb (ctx ).GetCollectionEntry (types .FromUniqueID (flushCollectionCompaction .ID ), nil )
1562
+ collectionEntry , segments , err := tc .GetCollectionWithSegments (ctx , flushCollectionCompaction .ID )
1563
+ // collectionEntry, err := tc.metaDomain.CollectionDb(ctx).GetCollectionEntry(types.FromUniqueID(flushCollectionCompaction.ID), nil)
1548
1564
if err != nil {
1549
1565
return nil , err
1550
1566
}
@@ -1574,15 +1590,16 @@ func (tc *Catalog) FlushCollectionCompactionForVersionedCollection(ctx context.C
1574
1590
}
1575
1591
1576
1592
existingVersionFileName := collectionEntry .VersionFileName
1593
+ // existingSegments := segments
1577
1594
var existingVersionFilePb * coordinatorpb.CollectionVersionFile
1578
1595
if existingVersionFileName == "" {
1579
1596
// The VersionFile has not been created.
1580
1597
existingVersionFilePb = & coordinatorpb.CollectionVersionFile {
1581
1598
CollectionInfoImmutable : & coordinatorpb.CollectionInfoImmutable {
1582
- TenantId : collectionEntry .Tenant ,
1583
- DatabaseId : collectionEntry .DatabaseID ,
1584
- CollectionId : collectionEntry .ID ,
1585
- CollectionName : * collectionEntry .Name ,
1599
+ TenantId : collectionEntry .TenantID ,
1600
+ DatabaseId : collectionEntry .DatabaseId . String () ,
1601
+ CollectionId : collectionEntry .ID . String () ,
1602
+ CollectionName : collectionEntry .Name ,
1586
1603
CollectionCreationSecs : collectionEntry .CreatedAt .Unix (),
1587
1604
},
1588
1605
VersionHistory : & coordinatorpb.CollectionVersionHistory {
@@ -1598,10 +1615,10 @@ func (tc *Catalog) FlushCollectionCompactionForVersionedCollection(ctx context.C
1598
1615
1599
1616
// There was previously a bug that resulted in the tenant ID missing from some version files (https://github.com/chroma-core/chroma/pull/4408).
1600
1617
// This line can be removed once all corrupted version files are fixed.
1601
- existingVersionFilePb .CollectionInfoImmutable .TenantId = collectionEntry .Tenant
1618
+ existingVersionFilePb .CollectionInfoImmutable .TenantId = collectionEntry .TenantID
1602
1619
1603
1620
// Do a simple validation of the version file.
1604
- err = tc .validateVersionFile (existingVersionFilePb , collectionEntry .ID , existingVersion )
1621
+ err = tc .validateVersionFile (existingVersionFilePb , collectionEntry .ID . String () , existingVersion )
1605
1622
if err != nil {
1606
1623
log .Error ("version file validation failed" , zap .Error (err ))
1607
1624
return nil , err
@@ -1611,7 +1628,7 @@ func (tc *Catalog) FlushCollectionCompactionForVersionedCollection(ctx context.C
1611
1628
// The update function takes the content of the existing version file,
1612
1629
// and the set of segments that are part of the new version file.
1613
1630
// NEW VersionFile is created in S3 at this step.
1614
- newVersionFileName , err := tc .updateVersionFileInS3 (ctx , existingVersionFilePb , flushCollectionCompaction , time .Now ().Unix ())
1631
+ newVersionFileName , err := tc .updateVersionFileInS3 (existingVersionFilePb , flushCollectionCompaction , segments , time .Now ().Unix ())
1615
1632
if err != nil {
1616
1633
return nil , err
1617
1634
}
0 commit comments