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

Add TTL and Transactional interfaces #91

Merged
merged 9 commits into from
Aug 14, 2018
Merged

Conversation

bigs
Copy link
Contributor

@bigs bigs commented Jul 25, 2018

adds two Datastore superclasses, TTLDatastore and TxDatastore. together, these give us pretty complete access to datastores such as badger.

closes #87 and simplifies a slew of other issues as well.

datastore.go Outdated
}

// Txn is an interface for transactions that can be committed or rolled back.
type Txn interface {

Choose a reason for hiding this comment

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

Maybe just Tx since the datastore is TxDatastore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

went the other way, but made them consistent!

datastore.go Outdated

// Txn is an interface for transactions that can be committed or rolled back.
type Txn interface {
Datastore
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we want to say that txn should implement stuff like Query. Feels a bit badger specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reasoning here is that updating values (i.e. reading an existing value and manipulating it) is pretty essential to most transactional behavior. without query support you just have the existing Batching interface.

@ghost ghost assigned bigs Aug 7, 2018
@ghost ghost added the status/in-progress In progress label Aug 7, 2018
@bigs
Copy link
Contributor Author

bigs commented Aug 7, 2018

renamed Rollback -> Discard and made some docstrings

@bigs bigs requested a review from schomatis August 8, 2018 15:38
datastore.go Outdated
// queries and mutations to the Datastore into atomic groups, or transactions.
// Actions performed on a transaction will not take hold until a successful
// call to Commit has been made. Likewise, transactions can be aborted by
// calling Discard before a successful Commit has been made.
Copy link
Member

Choose a reason for hiding this comment

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

This comment should be above the type Txn interface line.

Copy link

@schomatis schomatis Aug 9, 2018

Choose a reason for hiding this comment

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

Yes, and maybe this could be named TxnDatastore. (edit: that already exists.)

datastore.go Outdated
Get(key Key) (value interface{}, err error)
Has(key Key) (exists bool, err error)
Delete(key Key) error
Query(q query.Query) (query.Results, error)
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather extend Datastore here so we avoid duplicating these

Copy link
Contributor Author

@bigs bigs Aug 9, 2018

Choose a reason for hiding this comment

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

so i generally agree, though this change was made in response to discussion happening in the badger impl, specifically right here. what do you think? the idea was to make it clear that this is happening in the Txn not directly on the Datastore. open to either

Choose a reason for hiding this comment

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

The rationale behind this is that Txn is not extending the Datastore interface but is actually redefining it (committing is not an optional new feature, it's mandatory for the Put to take effect). I agree that this solution is also not ideal, seems to me the lesser of the two evils, but I'm okay if you want to use Datastore here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

further thoughts on this? think we're pretty close!

Choose a reason for hiding this comment

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

Hey @bigs, I think neither @magik6k nor myself have a strong feeling towards any of the proposed solutions, so it's your call, both solutions are fine by me. @Stebalien Do you any preferences here?

datastore.go Outdated
// queries and mutations to the Datastore into atomic groups, or transactions.
// Actions performed on a transaction will not take hold until a successful
// call to Commit has been made. Likewise, transactions can be aborted by
// calling Discard before a successful Commit has been made.
Copy link

@schomatis schomatis Aug 9, 2018

Choose a reason for hiding this comment

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

Yes, and maybe this could be named TxnDatastore. (edit: that already exists.)

datastore.go Outdated
Get(key Key) (value interface{}, err error)
Has(key Key) (exists bool, err error)
Delete(key Key) error
Query(q query.Query) (query.Results, error)

Choose a reason for hiding this comment

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

The rationale behind this is that Txn is not extending the Datastore interface but is actually redefining it (committing is not an optional new feature, it's mandatory for the Put to take effect). I agree that this solution is also not ideal, seems to me the lesser of the two evils, but I'm okay if you want to use Datastore here.

@bigs
Copy link
Contributor Author

bigs commented Aug 14, 2018

OK, i'm going to revert this to extend Datastore and do some publish/merges

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

Add TTL and Transaction support
4 participants