Skip to content

[ENH]: allow deleting v0 from version file & correctly propagate errors on DeleteCollectionVersion #4579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions go/pkg/sysdb/coordinator/table_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ func (tc *Catalog) createSegmentImpl(txCtx context.Context, createSegment *model
Type: createSegment.Type,
Scope: createSegment.Scope,
Ts: ts,
FilePaths: createSegment.FilePaths,
}
err := tc.metaDomain.SegmentDb(txCtx).Insert(dbSegment)
if err != nil {
Expand Down Expand Up @@ -2000,11 +2001,11 @@ func (tc *Catalog) getNumberOfActiveVersions(versionFilePb *coordinatorpb.Collec
}

func (tc *Catalog) getOldestVersionTs(versionFilePb *coordinatorpb.CollectionVersionFile) time.Time {
if versionFilePb.GetVersionHistory() == nil || len(versionFilePb.GetVersionHistory().Versions) <= 1 {
if versionFilePb.GetVersionHistory() == nil || len(versionFilePb.GetVersionHistory().Versions) == 0 {
// Returning a zero timestamp that represents an unset value.
return time.Time{}
}
oldestVersionTs := versionFilePb.GetVersionHistory().Versions[1].CreatedAtSecs
oldestVersionTs := versionFilePb.GetVersionHistory().Versions[0].CreatedAtSecs

return time.Unix(oldestVersionTs, 0)
}
Expand Down Expand Up @@ -2041,7 +2042,7 @@ func (tc *Catalog) DeleteVersionEntriesForCollection(ctx context.Context, tenant
}

numActiveVersions := tc.getNumberOfActiveVersions(versionFilePb)
if numActiveVersions <= 1 {
if numActiveVersions < 1 {
// No remaining valid versions after GC.
return errors.New("no valid versions after gc")
}
Expand Down Expand Up @@ -2091,11 +2092,15 @@ func (tc *Catalog) DeleteCollectionVersion(ctx context.Context, req *coordinator
result := coordinatorpb.DeleteCollectionVersionResponse{
CollectionIdToSuccess: make(map[string]bool),
}
var firstErr error
for _, collectionVersionList := range req.Versions {
err := tc.DeleteVersionEntriesForCollection(ctx, collectionVersionList.TenantId, collectionVersionList.CollectionId, collectionVersionList.Versions)
result.CollectionIdToSuccess[collectionVersionList.CollectionId] = err == nil
if firstErr == nil && err != nil {
firstErr = err
}
}
return &result, nil
return &result, firstErr
}

func (tc *Catalog) BatchGetCollectionVersionFilePaths(ctx context.Context, collectionIds []string) (*coordinatorpb.BatchGetCollectionVersionFilePathsResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/sysdb/coordinator/table_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func TestCatalog_DeleteCollectionVersion_CollectionNotFound(t *testing.T) {
resp, err := catalog.DeleteCollectionVersion(context.Background(), req)

// Verify results
assert.NoError(t, err)
assert.Error(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

The code is returning a successful response (assert.NoError(t, err)) even when the collection does not exist, but that seems to conflict with the implementation which now returns the first error encountered. The test should expect an error in this case.

assert.NotNil(t, resp)
assert.False(t, resp.CollectionIdToSuccess[collectionID])

Expand Down
3 changes: 3 additions & 0 deletions go/pkg/sysdb/grpc/proto_model_convert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package grpc

import (
"time"

"github.com/chroma-core/chroma/go/pkg/common"
"github.com/chroma-core/chroma/go/pkg/proto/coordinatorpb"
"github.com/chroma-core/chroma/go/pkg/sysdb/coordinator/model"
Expand Down Expand Up @@ -131,6 +133,7 @@ func convertToCreateCollectionModel(req *coordinatorpb.CreateCollectionRequest)
GetOrCreate: req.GetGetOrCreate(),
TenantID: req.GetTenant(),
DatabaseName: req.GetDatabase(),
Ts: time.Now().Unix(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prior to this, v0 in the version file always had created_at_secs: 0

}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct DeleteVersionsAtSysDbOutput {

#[derive(Error, Debug)]
pub enum DeleteVersionsAtSysDbError {
#[error("Unknown error occurred when deleting versions at sysdb")]
UnknownError,
#[error("Error deleting versions in sysdb: {0}")]
SysDBError(String),
#[error("Error deleting version file {path}: {message}")]
Expand Down Expand Up @@ -157,7 +159,13 @@ impl Operator<DeleteVersionsAtSysDbInput, DeleteVersionsAtSysDbOutput>
.delete_collection_version(vec![input.versions_to_delete.clone()])
.await
{
Ok(_) => {
Ok(results) => {
for (_, was_successful) in results {
if !was_successful {
return Err(DeleteVersionsAtSysDbError::UnknownError);
}
}

tracing::info!(
versions = ?input.versions_to_delete.versions,
"Successfully deleted versions from SysDB"
Expand Down
4 changes: 2 additions & 2 deletions rust/sysdb/src/sysdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,14 +1331,14 @@ impl ChromaError for MarkVersionForDeletionError {

#[derive(Error, Debug)]
pub enum DeleteCollectionVersionError {
#[error("Failed to delete version")]
#[error("Failed to delete version: {0}")]
FailedToDeleteVersion(#[from] tonic::Status),
}

impl ChromaError for DeleteCollectionVersionError {
fn code(&self) -> ErrorCodes {
match self {
DeleteCollectionVersionError::FailedToDeleteVersion(_) => ErrorCodes::Internal,
DeleteCollectionVersionError::FailedToDeleteVersion(e) => e.code().into(),
}
}
}
Loading