Skip to content
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

fix: Make returned collections respect explicit transactions #2385

Merged
merged 1 commit into from
Mar 6, 2024
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
6 changes: 6 additions & 0 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,19 @@ type Store interface {
// GetCollectionByName attempts to retrieve a collection matching the given name.
//
// If no matching collection is found an error will be returned.
//
// If a transaction was explicitly provided to this [Store] via [DB].[WithTxn], any function calls
// made via the returned [Collection] will respect that transaction.
GetCollectionByName(context.Context, CollectionName) (Collection, error)

// GetCollections returns all collections and their descriptions matching the given options
// that currently exist within this [Store].
//
// Inactive collections are not returned by default unless a specific schema version ID
// is provided.
//
// If a transaction was explicitly provided to this [Store] via [DB].[WithTxn], any function calls
// made via the returned [Collection]s will respect that transaction.
GetCollections(context.Context, CollectionFetchOptions) ([]Collection, error)

// GetSchemaByVersionID returns the schema description for the schema version of the
Expand Down
18 changes: 16 additions & 2 deletions db/txn_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func (db *implicitTxnDB) GetCollectionByName(ctx context.Context, name string) (

// GetCollectionByName returns an existing collection within the database.
func (db *explicitTxnDB) GetCollectionByName(ctx context.Context, name string) (client.Collection, error) {
return db.getCollectionByName(ctx, db.txn, name)
col, err := db.getCollectionByName(ctx, db.txn, name)
if err != nil {
return nil, err
}

return col.WithTxn(db.txn), nil
}

// GetCollections gets all the currently defined collections.
Expand All @@ -101,7 +106,16 @@ func (db *explicitTxnDB) GetCollections(
ctx context.Context,
options client.CollectionFetchOptions,
) ([]client.Collection, error) {
return db.getCollections(ctx, db.txn, options)
cols, err := db.getCollections(ctx, db.txn, options)
if err != nil {
return nil, err
}

for i := range cols {
cols[i] = cols[i].WithTxn(db.txn)
}

return cols, nil
}

// GetSchemaByVersionID returns the schema description for the schema version of the
Expand Down
Loading