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

Implement new TxDatastore and Txn interfaces #27

Merged
merged 12 commits into from
Aug 14, 2018
Merged

Conversation

bigs
Copy link
Contributor

@bigs bigs commented Jul 25, 2018

adds full on transaction support for the badger datastore. related to ipfs/go-datastore#91, though not dependent on it. also updates all vanilla Datastore methods to leverage the transaction wrapper.

WIP for now because it doesn't include transaction specific tests, though all existing tests (which depend on them implicitly) are passing.

@bigs
Copy link
Contributor Author

bigs commented Jul 25, 2018

i could also bundle the TTL implementation in this branch which, thinking about it, seems to make the most sense as it will eventually depend on this code, too!

@bigs
Copy link
Contributor Author

bigs commented Jul 25, 2018

added TTL!

@bigs bigs changed the title [WIP] Implement new TxDatastore and Txn interfaces Implement new TxDatastore and Txn interfaces Jul 27, 2018
@bigs
Copy link
Contributor Author

bigs commented Jul 27, 2018

i'd say this is ready for review now. @Stebalien not sure who else to rope in, but this is relevant to stuff we've been thinking about

return true, nil
}
func (t *txn) Has(key ds.Key) (bool, error) {
_, err := t.Get(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there still no way to do that touching vlogs / having to fetch the value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you know what i can open a transaction that specifically doesn't pre-load values. i will change that. good catch

datastore.go Outdated
err = nil
}
return err
func (t *txn) Rollback() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this name is rather confusing as at least in the SQL world it usually means 'undo changes by this transaction'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok, i can work w/ that. perhaps we go with Discard?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes more sense, but still deserves a docstring explaining that it doesn't touch committed data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on Discard, especially because the user will see it being called on every txn method.

ds_test.go Outdated
@@ -547,3 +548,155 @@ func TestDiskUsage(t *testing.T) {
}
d.Close()
}

func TestTxnRollback(t *testing.T) {
d, err := NewDatastore("/tmp/testing_badger_du", nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use ioutil.TempDir

datastore.go Outdated
@@ -18,6 +19,10 @@ type datastore struct {
gcDiscardRatio float64
}

type txn struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add here that this is documenting the datastore.Txn interface?

datastore.go Outdated
err = nil
}
return err
func (t *txn) Rollback() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on Discard, especially because the user will see it being called on every txn method.

Copy link
Contributor

@schomatis schomatis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM but I feel we're abusing the Datastore interface a bit with the new Txn that extends it.

Although the signature of the functions are the same their semantic is different in the key aspect that Txn requires Commit() to be called (it's not an optional extension) to fulfill the Put() promise. A new user that just follows a Get/Put definition all the way to Datastore won't realize that difference.

@bigs
Copy link
Contributor Author

bigs commented Aug 7, 2018

@schomatis yeah, i do understand that. i could just duplicate the method signatures in Txn if that would help. either way, until we come to a decision on that i'll make sure the interface has good docstrings to explain.

ultimately, i think it'd be a mistake not to implement transactions in their fullest capacity just because golang makes it difficult to represent the types well. there's an awful lot of performance/efficiency to be gained!

@schomatis
Copy link
Contributor

ultimately, i think it'd be a mistake not to implement transactions in their fullest capacity just because golang makes it difficult to represent the types well. there's an awful lot of performance/efficiency to be gained!

Agreed.

@bigs
Copy link
Contributor Author

bigs commented Aug 7, 2018

updated, rebased

@bigs
Copy link
Contributor Author

bigs commented Aug 7, 2018

@schomatis yeahhhhhhhh. what do you think of explicitly moving datastore operations onto the txn interface? i think that would at least make it clear that there is a separation.

@bigs
Copy link
Contributor Author

bigs commented Aug 8, 2018

cheers, thanks for feedback @schomatis ! change with that is up on the datastore repo

@ghost ghost assigned bigs Aug 14, 2018
@ghost ghost added the status/in-progress In progress label Aug 14, 2018
@bigs bigs merged commit f3dd075 into ipfs:master Aug 14, 2018
@ghost ghost removed the status/in-progress In progress label Aug 14, 2018
@bigs bigs deleted the feat/txdatastore branch August 14, 2018 22:42
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