Skip to content

Commit

Permalink
fix: Discard index and subscription implicit transactions (#1715)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #1714

## Description

Discard index and subscription implicit transactions.

I'm not sure if this was causing any problems, but they should be
discarded.
  • Loading branch information
AndrewSisley authored Jul 26, 2023
1 parent 5b2182f commit 2385525
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
2 changes: 2 additions & 0 deletions db/collection_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ func (c *collection) GetIndexes(ctx context.Context) ([]client.IndexDescription,
if err != nil {
return nil, err
}
defer c.discardImplicitTxn(ctx, txn)

err = c.loadIndexes(ctx, txn)
if err != nil {
return nil, err
Expand Down
41 changes: 27 additions & 14 deletions db/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/planner"
)
Expand Down Expand Up @@ -58,25 +59,37 @@ func (db *db) handleSubscription(
continue
}

p := planner.New(ctx, db.WithTxn(txn), txn)
db.handleEvent(ctx, txn, pub, evt, r)

s := r.ToSelect(evt.DocKey, evt.Cid.String())
txn.Discard(ctx)
}
}

result, err := p.RunSubscriptionRequest(ctx, s)
if err != nil {
pub.Publish(client.GQLResult{
Errors: []error{err},
})
continue
}
func (db *db) handleEvent(
ctx context.Context,
txn datastore.Txn,
pub *events.Publisher[events.Update],
evt events.Update,
r *request.ObjectSubscription,
) {
p := planner.New(ctx, db.WithTxn(txn), txn)

// Don't send anything back to the client if the request yields an empty dataset.
if len(result) == 0 {
continue
}
s := r.ToSelect(evt.DocKey, evt.Cid.String())

result, err := p.RunSubscriptionRequest(ctx, s)
if err != nil {
pub.Publish(client.GQLResult{
Data: result,
Errors: []error{err},
})
return
}

// Don't send anything back to the client if the request yields an empty dataset.
if len(result) == 0 {
return
}

pub.Publish(client.GQLResult{
Data: result,
})
}

0 comments on commit 2385525

Please sign in to comment.