Skip to content

Variable length values

James Hunter edited this page Sep 7, 2018 · 5 revisions

FASTER supports variable-length values. If you update (i.e., Upsert() or Rmw()) an existing variable-length value to a new value that's no larger than the existing value, FASTER will update the value in place. Otherwise, FASTER will mark the existing value as read-only, and perform a copy-on-write/read-copy-update to a new value, of the appropriate size.

In C++

See example unit tests "InMemFaster / UpsertRead_ResizeValue_Concurrent" and "InMemFaster / Rmw_ResizeValue_Concurrent".

To create a variable-length value, your Upsert or RMW context should:

  1. Define a value_size() method that returns the actual size of your value. You should store this size inside your value's header, but you can define this however you like. In the example unit tests, value_size() returns "sizeof(value_t) + length_", where length_ is a 4-byte integer stored in value_t's header.
  2. Define its PutAtomic() / RmwAtomic() lambda to return "false" when the value cannot be updated in place (e.g, because the update requires more space), and also mark the record as read-only or "replaced." The lambda should also return false if some other thread previously marked the record as read-only/"replaced."

When the FASTER KV store sees PutAtomic() / RmwAtomic() return false, it retries the operation as a copy-on-write/read-copy-update.

Clone this wiki locally