-
Notifications
You must be signed in to change notification settings - Fork 33
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
Avoid discarding transaction too early in queries #31
Conversation
Introduces the notion of implicit transactions: those started to execute one-off queries called on the Datastore. The goprocess for the iterator calls txn.Discard() on implicit transactions on closure. Needed after dgraph-io/badger@b1ad1e9.
@@ -142,9 +152,10 @@ func (d *Datastore) Delete(key ds.Key) error { | |||
} | |||
|
|||
func (d *Datastore) Query(q dsq.Query) (dsq.Results, error) { | |||
txn := d.NewTransaction(true) | |||
defer txn.Discard() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defer
is problematic with badger master, as it discards the txn while the iterator is active.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the error this PR solves:
panic: Unclosed iterator at time of Txn.Discard. [recovered]
panic: Unclosed iterator at time of Txn.Discard.
@@ -79,11 +83,17 @@ func NewDatastore(path string, options *Options) (*Datastore, error) { | |||
// can be mutated without incurring changes to the underlying Datastore until | |||
// the transaction is Committed. | |||
func (d *Datastore) NewTransaction(readOnly bool) ds.Txn { | |||
return &txn{d.DB.NewTransaction(!readOnly)} | |||
return &txn{d.DB.NewTransaction(!readOnly), false} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that we have more than one value in the struct, let's address them by name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I merged before addressing this. Worth opening another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just leave a todo for yourself! i think it's fine.
Tests against badger master are failing because of dgraph-io/badger@b1ad1e9
As per that commit, badger now fails if a transaction holding an iterator is discarded while the iterator is still active.
This commit tracks implicit transactions: those created solely to execute
one-off queries called on the
Datastore
. The goprocess for the iterator now callstxn.Discard()
on implicit transactions on closure.