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

Txn.SetEntryWithDiscard #774

Closed
chernomyrdin opened this issue Apr 19, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@chernomyrdin
Copy link

commented Apr 19, 2019

First of all,
great system: simple design and enable endless possibilities!

I would like to propose the addition of SetEntryWithDiscard for Txn. Or somethig else fo set meta bit bitDiscardEarlierVersions in Entry.
For the same reason, a WriteBatch.SetEntryWithDiscard is also helpful, but to a lesser extent. I guess that would be very straightforward to implement.

Thanks again!

@ashish-goswami

This comment has been minimized.

Copy link
Contributor

commented Apr 19, 2019

@chernomyrdin Thanks for raising the issue. We already have SetWithDiscard for Txn, which is similar to what you are proposing. However we don't have this in WriteBatch.
Feel free to raise a PR if possible.

@chernomyrdin

This comment has been minimized.

Copy link
Author

commented Apr 19, 2019

I need save to database Entry with TTL and DiscadEarlierVersions at one time.
first variant code:

// SetEntryWithDiscard acts like SetEntry, but adds a marker to discard earlier
// versions of the key.
//
// The current transaction keeps a reference to the entry passed in argument.
// Users must not modify the entry until the end of the transaction.
func (txn *Txn) SetEntryWithDiscard(e *Entry) error {
	return txn.modify(&Entry{
		Key:       e.Key,
		Value:     e.Value,
		UserMeta:  e.UserMeta,
		ExpiresAt: e.ExpiresAt,
		meta:      bitDiscardEarlierVersions,
	})
}

or second variant:

// SetEntryWithDiscard acts like SetEntry, but adds a marker to discard earlier
// versions of the key.
//
// The current transaction keeps a reference to the entry passed in argument.
// Users must not modify the entry until the end of the transaction.
func (txn *Txn) SetEntryWithDiscard(e *Entry) error {
	e.meta = bitDiscardEarlierVersions
	return txn.modify(e)
}

What code style preferred?

@ashish-goswami

This comment has been minimized.

Copy link
Contributor

commented Apr 19, 2019

@chernomyrdin ExpiredAt is exported field and hence can be set directly using dot operator like e.ExpiredAt = time.Now().Unix()

@ashish-goswami

This comment has been minimized.

Copy link
Contributor

commented May 28, 2019

We have introduced new APIs for Entry. These APIs allows you to set more than one property on Entry. Finally calling SetEntry on Transaction/WriteBatch adds entry to Transaction/WriteBatch. #822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.