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

feat: discard batch safely after commit batch #217

Merged
merged 6 commits into from
Jul 2, 2023

Conversation

rfyiamcool
Copy link
Member

@rfyiamcool
Copy link
Member Author

add ut for discard.

@roseduan
Copy link
Collaborator

roseduan commented Jul 2, 2023

I think this is a little complicated, like we have to maintain the locked field.

A better simple solution is to add a Rollback function:

  • clear pendingWrites if any
  • make rollbacked field as true
  • unlock
  • add check if rollbacked, just return an error

so the user will either call commit or rollback.

@rfyiamcool
Copy link
Member Author

I think this is a little complicated, like we have to maintain the locked field.

A better simple solution is to add a Rollback function:

  • clear pendingWrites if any
  • make rollbacked field as true
  • unlock
  • add check if rollbacked, just return an error

so the user will either call commit or rollback.

done, review.

@roseduan
Copy link
Collaborator

roseduan commented Jul 2, 2023

I think the locked field can be removed?

@@ -20,6 +22,7 @@ func main() {

// create a batch
batch := db.NewBatch(rosedb.DefaultBatchOptions)
defer batch.Rollback()
Copy link
Collaborator

Choose a reason for hiding this comment

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

use will either call Commit or Rollback, so need to call this in defer

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@roseduan roseduan merged commit a844f39 into rosedblabs:main Jul 2, 2023
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.

2 participants