Skip to content

Commit

Permalink
fix: Make returned collections respect explicit transactions (#2385)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2384

## Description

Makes returned collections respect explicit transactions.
  • Loading branch information
AndrewSisley authored Mar 6, 2024
1 parent 76d8735 commit b377876
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit b377876

Please sign in to comment.