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

Avoid discarding transaction too early in queries #31

Merged
merged 1 commit into from
Sep 13, 2018

Conversation

raulk
Copy link
Member

@raulk raulk commented Sep 12, 2018

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 calls txn.Discard() on implicit transactions on closure.

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.
@ghost ghost assigned raulk Sep 12, 2018
@ghost ghost added the status/in-progress In progress label Sep 12, 2018
@raulk raulk requested review from bigs and magik6k September 12, 2018 18:57
@@ -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()
Copy link
Member Author

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.

Copy link
Member Author

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}
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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.

@raulk raulk merged commit ee73605 into ipfs:master Sep 13, 2018
@ghost ghost removed the status/in-progress In progress label Sep 13, 2018
@raulk raulk deleted the implicittx branch September 13, 2018 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants