Skip to content

Commit 491f743

Browse files
committed
[ENH]: allow deleting v0 from version file
1 parent c3dbe3a commit 491f743

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

go/pkg/sysdb/coordinator/table_catalog.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ func (tc *Catalog) createSegmentImpl(txCtx context.Context, createSegment *model
10621062
Type: createSegment.Type,
10631063
Scope: createSegment.Scope,
10641064
Ts: ts,
1065+
FilePaths: createSegment.FilePaths,
10651066
}
10661067
err := tc.metaDomain.SegmentDb(txCtx).Insert(dbSegment)
10671068
if err != nil {
@@ -1918,11 +1919,11 @@ func (tc *Catalog) getNumberOfActiveVersions(versionFilePb *coordinatorpb.Collec
19181919
}
19191920

19201921
func (tc *Catalog) getOldestVersionTs(versionFilePb *coordinatorpb.CollectionVersionFile) time.Time {
1921-
if versionFilePb.GetVersionHistory() == nil || len(versionFilePb.GetVersionHistory().Versions) <= 1 {
1922+
if versionFilePb.GetVersionHistory() == nil || len(versionFilePb.GetVersionHistory().Versions) == 0 {
19221923
// Returning a zero timestamp that represents an unset value.
19231924
return time.Time{}
19241925
}
1925-
oldestVersionTs := versionFilePb.GetVersionHistory().Versions[1].CreatedAtSecs
1926+
oldestVersionTs := versionFilePb.GetVersionHistory().Versions[0].CreatedAtSecs
19261927

19271928
return time.Unix(oldestVersionTs, 0)
19281929
}
@@ -1958,7 +1959,7 @@ func (tc *Catalog) DeleteVersionEntriesForCollection(ctx context.Context, tenant
19581959
}
19591960

19601961
numActiveVersions := tc.getNumberOfActiveVersions(versionFilePb)
1961-
if numActiveVersions <= 1 {
1962+
if numActiveVersions < 1 {
19621963
// No remaining valid versions after GC.
19631964
return errors.New("no valid versions after gc")
19641965
}
@@ -2008,11 +2009,15 @@ func (tc *Catalog) DeleteCollectionVersion(ctx context.Context, req *coordinator
20082009
result := coordinatorpb.DeleteCollectionVersionResponse{
20092010
CollectionIdToSuccess: make(map[string]bool),
20102011
}
2012+
var firstErr error
20112013
for _, collectionVersionList := range req.Versions {
20122014
err := tc.DeleteVersionEntriesForCollection(ctx, collectionVersionList.TenantId, collectionVersionList.CollectionId, collectionVersionList.Versions)
20132015
result.CollectionIdToSuccess[collectionVersionList.CollectionId] = err == nil
2016+
if firstErr == nil && err != nil {
2017+
firstErr = err
2018+
}
20142019
}
2015-
return &result, nil
2020+
return &result, firstErr
20162021
}
20172022

20182023
func (tc *Catalog) BatchGetCollectionVersionFilePaths(ctx context.Context, collectionIds []string) (*coordinatorpb.BatchGetCollectionVersionFilePathsResponse, error) {

go/pkg/sysdb/grpc/proto_model_convert.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package grpc
22

33
import (
4+
"time"
5+
46
"github.com/chroma-core/chroma/go/pkg/common"
57
"github.com/chroma-core/chroma/go/pkg/proto/coordinatorpb"
68
"github.com/chroma-core/chroma/go/pkg/sysdb/coordinator/model"
@@ -131,6 +133,7 @@ func convertToCreateCollectionModel(req *coordinatorpb.CreateCollectionRequest)
131133
GetOrCreate: req.GetGetOrCreate(),
132134
TenantID: req.GetTenant(),
133135
DatabaseName: req.GetDatabase(),
136+
Ts: time.Now().Unix(),
134137
}, nil
135138
}
136139

rust/garbage_collector/src/operators/delete_versions_at_sysdb.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct DeleteVersionsAtSysDbOutput {
3838

3939
#[derive(Error, Debug)]
4040
pub enum DeleteVersionsAtSysDbError {
41+
#[error("Unknown error occurred when deleting versions at sysdb")]
42+
UnknownError,
4143
#[error("Error deleting versions in sysdb: {0}")]
4244
SysDBError(String),
4345
#[error("Error deleting version file {path}: {message}")]
@@ -157,7 +159,14 @@ impl Operator<DeleteVersionsAtSysDbInput, DeleteVersionsAtSysDbOutput>
157159
.delete_collection_version(vec![input.versions_to_delete.clone()])
158160
.await
159161
{
160-
Ok(_) => {
162+
Ok(results) => {
163+
for (_, was_successful) in results {
164+
if !was_successful {
165+
// todo: redo API to perform 1 delete at a time?
166+
return Err(DeleteVersionsAtSysDbError::UnknownError);
167+
}
168+
}
169+
161170
tracing::info!(
162171
versions = ?input.versions_to_delete.versions,
163172
"Successfully deleted versions from SysDB"

rust/sysdb/src/sysdb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,14 +1330,14 @@ impl ChromaError for MarkVersionForDeletionError {
13301330

13311331
#[derive(Error, Debug)]
13321332
pub enum DeleteCollectionVersionError {
1333-
#[error("Failed to delete version")]
1333+
#[error("Failed to delete version: {0}")]
13341334
FailedToDeleteVersion(#[from] tonic::Status),
13351335
}
13361336

13371337
impl ChromaError for DeleteCollectionVersionError {
13381338
fn code(&self) -> ErrorCodes {
13391339
match self {
1340-
DeleteCollectionVersionError::FailedToDeleteVersion(_) => ErrorCodes::Internal,
1340+
DeleteCollectionVersionError::FailedToDeleteVersion(e) => e.code().into(),
13411341
}
13421342
}
13431343
}

0 commit comments

Comments
 (0)