@@ -555,7 +555,7 @@ func (tc *Catalog) hardDeleteCollection(ctx context.Context, deleteCollection *m
555
555
return tc .txImpl .Transaction (ctx , func (txCtx context.Context ) error {
556
556
collectionID := deleteCollection .ID
557
557
558
- collectionEntry , err := tc .metaDomain .CollectionDb (txCtx ).GetCollectionWithoutMetadata (types .FromUniqueID (collectionID ), & deleteCollection .DatabaseName , nil )
558
+ collectionEntry , err := tc .metaDomain .CollectionDb (txCtx ).GetCollectionWithoutMetadata (types .FromUniqueID (collectionID ), & deleteCollection .DatabaseName , nil ) // todo: should filter for soft deleted
559
559
if err != nil {
560
560
return err
561
561
}
@@ -564,6 +564,51 @@ func (tc *Catalog) hardDeleteCollection(ctx context.Context, deleteCollection *m
564
564
return common .ErrCollectionDeleteNonExistingCollection
565
565
}
566
566
567
+ if ! collectionEntry .IsDeleted {
568
+ return common .ErrCollectionWasNotSoftDeleted
569
+ }
570
+
571
+ if collectionEntry .RootCollectionId != nil {
572
+ rootCollection , err := tc .metaDomain .CollectionDb (txCtx ).GetCollectionWithoutMetadata (collectionEntry .RootCollectionId , nil , nil )
573
+ if err != nil {
574
+ return err
575
+ }
576
+ if rootCollection == nil {
577
+ return errors .New ("root collection not found" )
578
+ }
579
+
580
+ if rootCollection .LineageFileName == nil {
581
+ return errors .New ("lineage file name is nil on root collection" )
582
+ }
583
+
584
+ lineageFile , err := tc .getLineageFile (txCtx , rootCollection .LineageFileName )
585
+ if err != nil {
586
+ return err
587
+ }
588
+ // filter out this collection
589
+ updatedDependencies := make ([]* coordinatorpb.CollectionVersionDependency , 0 )
590
+ for _ , dependency := range lineageFile .Dependencies {
591
+ if dependency .TargetCollectionId != deleteCollection .ID .String () {
592
+ updatedDependencies = append (updatedDependencies , dependency )
593
+ }
594
+ }
595
+ lineageFile .Dependencies = updatedDependencies
596
+
597
+ newLineageFileId , err := uuid .NewV7 ()
598
+ if err != nil {
599
+ return err
600
+ }
601
+
602
+ log .Info ("new lineage file id" , zap .String ("newLineageFileId" , newLineageFileId .String ()))
603
+
604
+ newLineageFileFullName , err := tc .s3Store .PutLineageFile (collectionEntry .Tenant , collectionEntry .DatabaseID , rootCollection .ID , fmt .Sprintf ("%s.binpb" , newLineageFileId .String ()), lineageFile )
605
+ if err != nil {
606
+ return err
607
+ }
608
+
609
+ tc .metaDomain .CollectionDb (txCtx ).UpdateCollectionLineageFilePath (rootCollection .ID , rootCollection .LineageFileName , newLineageFileFullName )
610
+ }
611
+
567
612
// Delete collection and collection metadata.
568
613
collectionDeletedCount , err := tc .metaDomain .CollectionDb (txCtx ).DeleteCollectionByID (collectionID .String ())
569
614
if err != nil {
@@ -1960,7 +2005,7 @@ func (tc *Catalog) MarkVersionForDeletion(ctx context.Context, req *coordinatorp
1960
2005
1961
2006
func (tc * Catalog ) updateProtoRemoveVersionEntries (versionFilePb * coordinatorpb.CollectionVersionFile , versions []int64 ) error {
1962
2007
// Check if version history exists
1963
- if versionFilePb .GetVersionHistory () == nil || len ( versionFilePb . GetVersionHistory (). Versions ) == 0 {
2008
+ if versionFilePb .GetVersionHistory () == nil {
1964
2009
log .Error ("version history not found" )
1965
2010
return errors .New ("version history not found" )
1966
2011
}
@@ -1996,14 +2041,14 @@ func (tc *Catalog) getNumberOfActiveVersions(versionFilePb *coordinatorpb.Collec
1996
2041
return len (activeVersions )
1997
2042
}
1998
2043
1999
- func (tc * Catalog ) getOldestVersionTs (versionFilePb * coordinatorpb.CollectionVersionFile ) time.Time {
2044
+ func (tc * Catalog ) getOldestVersionTs (versionFilePb * coordinatorpb.CollectionVersionFile ) * time.Time {
2000
2045
if versionFilePb .GetVersionHistory () == nil || len (versionFilePb .GetVersionHistory ().Versions ) == 0 {
2001
- // Returning a zero timestamp that represents an unset value.
2002
- return time.Time {}
2046
+ return nil
2003
2047
}
2004
2048
oldestVersionTs := versionFilePb .GetVersionHistory ().Versions [0 ].CreatedAtSecs
2005
2049
2006
- return time .Unix (oldestVersionTs , 0 )
2050
+ ts := time .Unix (oldestVersionTs , 0 )
2051
+ return & ts
2007
2052
}
2008
2053
2009
2054
func (tc * Catalog ) DeleteVersionEntriesForCollection (ctx context.Context , tenantID string , collectionID string , versions []int64 ) error {
@@ -2017,8 +2062,8 @@ func (tc *Catalog) DeleteVersionEntriesForCollection(ctx context.Context, tenant
2017
2062
2018
2063
// Read the existing version file
2019
2064
collectionIDPtr := & collectionID
2020
- isDeleted := false
2021
- collectionEntry , err := tc .metaDomain .CollectionDb (ctx ).GetCollectionWithoutMetadata (collectionIDPtr , nil , & isDeleted )
2065
+ // isDeleted := true // todo
2066
+ collectionEntry , err := tc .metaDomain .CollectionDb (ctx ).GetCollectionWithoutMetadata (collectionIDPtr , nil , nil ) // todo
2022
2067
if err != nil {
2023
2068
return err
2024
2069
}
@@ -2038,14 +2083,19 @@ func (tc *Catalog) DeleteVersionEntriesForCollection(ctx context.Context, tenant
2038
2083
}
2039
2084
2040
2085
numActiveVersions := tc .getNumberOfActiveVersions (versionFilePb )
2041
- if numActiveVersions < 1 {
2086
+ if numActiveVersions < 1 && ! collectionEntry . IsDeleted {
2042
2087
// No remaining valid versions after GC.
2043
2088
return errors .New ("no valid versions after gc" )
2044
2089
}
2045
2090
2046
2091
// Get the creation time of the oldest version.
2047
2092
oldestVersionTs := tc .getOldestVersionTs (versionFilePb )
2048
- if oldestVersionTs .IsZero () {
2093
+ if oldestVersionTs == nil {
2094
+ if ! collectionEntry .IsDeleted {
2095
+ // todo
2096
+ return errors .New ("oldest version timestamp is nil after GC" )
2097
+ }
2098
+ } else if oldestVersionTs .IsZero () {
2049
2099
// This should never happen.
2050
2100
log .Error ("oldest version timestamp is zero after GC." , zap .String ("collection_id" , collectionID ))
2051
2101
// No versions to delete.
@@ -2065,7 +2115,7 @@ func (tc *Catalog) DeleteVersionEntriesForCollection(ctx context.Context, tenant
2065
2115
}
2066
2116
2067
2117
// Update the version file name in Postgres table as a CAS operation
2068
- rowsAffected , err := tc .metaDomain .CollectionDb (ctx ).UpdateVersionRelatedFields (collectionID , existingVersionFileName , newVerFileFullPath , & oldestVersionTs , & numActiveVersions )
2118
+ rowsAffected , err := tc .metaDomain .CollectionDb (ctx ).UpdateVersionRelatedFields (collectionID , existingVersionFileName , newVerFileFullPath , oldestVersionTs , & numActiveVersions )
2069
2119
if err != nil {
2070
2120
// Delete the newly created version file from S3 since it is not needed
2071
2121
tc .s3Store .DeleteVersionFile (tenantID , collectionEntry .DatabaseID , collectionID , newVersionFileName )
@@ -2113,6 +2163,20 @@ func (tc *Catalog) BatchGetCollectionVersionFilePaths(ctx context.Context, colle
2113
2163
return & result , nil
2114
2164
}
2115
2165
2166
+ func (tc * Catalog ) BatchGetCollectionSoftDeleteStatus (ctx context.Context , collectionIds []string ) (* coordinatorpb.BatchGetCollectionSoftDeleteStatusResponse , error ) {
2167
+ result := coordinatorpb.BatchGetCollectionSoftDeleteStatusResponse {
2168
+ CollectionIdToIsSoftDeleted : make (map [string ]bool ),
2169
+ }
2170
+
2171
+ status , err := tc .metaDomain .CollectionDb (ctx ).BatchGetCollectionSoftDeleteStatus (collectionIds )
2172
+ if err != nil {
2173
+ return nil , err
2174
+ }
2175
+ result .CollectionIdToIsSoftDeleted = status
2176
+
2177
+ return & result , nil
2178
+ }
2179
+
2116
2180
func (tc * Catalog ) GetVersionFileNamesForCollection (ctx context.Context , tenantID string , collectionID string ) (string , error ) {
2117
2181
collectionIDPtr := & collectionID
2118
2182
isDeleted := false
0 commit comments