-
Notifications
You must be signed in to change notification settings - Fork 23
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
refactor: Create meta.DB interface #92
Conversation
Current Aviator status
This PR was merged using Aviator. Stack
|
internal/meta/db.go
Outdated
// WithTx runs the given function in a transaction. The transaction is | ||
// committed when the function returns (unless it has been aborted by | ||
// calling WriteTx.Abort). | ||
WithTx(func(tx WriteTx)) error |
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.
WithTx(func(tx WriteTx) error)) error
might be more convenient as we can use it in RunE directly.
RunE: func(...) error {
db := ...
return db.WriteTx(func(tx WriteTx) error) error {
...
})
}
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.
That was actually my original strategy but I chose against it to make it more clear that it's not a direct passthrough -- WriteTx
can returns its own errors. Honestly, in hindsight, I think just doing a
tx := db.WriteTx()
tx.SetBranch(...)
tx.Commit()
will be a better API. I chose the function-arg version to make it impossible to forget to commit/abort a transaction, but I think it's fine to just have an API invariant of "you MUST call Commit
or Abort
on this transaction object".
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.
Rereviewed for the updated interface.
// Abort aborts the transaction (no changes will be committed). | ||
// The transaction cannot be used after it has been aborted. | ||
Abort() | ||
// Commit commits the transaction (all changes will be committed). |
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.
Small ask: Can we add a contract like "Abort can be called even after Commit". Otherwise, we need to cancel the Cleanup.
This pull request failed to merge: top queued PR in the stack failed to merge. Remove the |
5718042
to
68f461b
Compare
This is just the first PR in what will probably be a few. This one adds a basic database interface that just stores everything as a big
map
(which is probably fine for our scale of data) and writes to/reads from a JSON file as the persistence mechanism.Wanted to open this now and get some feedback. In the next PR, I'll probably implement writing to refs while also writing to the JSON database. After that, the annoying change of having to plumb the database through everywhere.