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 a CASStore trait #222

Open
johnynek opened this issue Mar 10, 2014 · 5 comments
Open

Add a CASStore trait #222

johnynek opened this issue Mar 10, 2014 · 5 comments

Comments

@johnynek
Copy link
Collaborator

something like:

trait CASStore[T:Equiv, K, V] {
  def get(k: K): Future[(V, T)]
  // returns the token immediately before
  // and the value. If the result equiv(Token, T), then the swap happened 
  def cas(token: T, kv: (K, V)): Future[(V,T)] 
}

With this, we can build a local cache of tokens and values and do Mergeable with 1 roundtrip, rather than 2 in Memcache etc..

Note, this does not put an Option on the returns. If missing values are allowed, use Option[V].

Question: does multiCas make sense? We can always add it, but how many systems can optimize it?

@ianoc
Copy link
Collaborator

ianoc commented Mar 10, 2014

Sounds pretty cool. I believe redis can support it via its scripting API. But not sure of any other ones that could. (Scripts are executed atomically, so you could return key's for which the swap wasn't possible).

@rubanm
Copy link
Contributor

rubanm commented Mar 11, 2014

I think this will work great with memcache if the locally cached tokens are usually going to be current.

Redis doesn't use tokens for cas. Instead, it lets you "watch" the key for any updates by other threads while you try to make an update. The same applies to scripts as well I think. So we may not need a token there - http://redis.io/topics/transactions#cas

Is there a way to model this trait for stores that do not use cas tokens?

@avibryant
Copy link

This seems to overlap with my (sadly abandoned) UpdateableStore PR, right? #119

@rubanm
Copy link
Contributor

rubanm commented Mar 13, 2014

Ah, yes. UpdateableStore sounds like the more appropriate place for redis updates.

UpdateableStore was conceived for read-modify-writes. On the other hand, CASStore seems to be separating the three (get for reads, modify, and then cas for writes) by optimizing for cases where locally cached tokens are current.

I can see a MemcacheUpdateableStore built on top of a MemcacheCASStore though.

@rubanm
Copy link
Contributor

rubanm commented Mar 13, 2014

Having said that, +1 for the trait.
Along with memcache, twitter's internal key-value store also supports CAS so this will be really useful.

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

No branches or pull requests

4 participants