riak-scala-client icon indicating copy to clipboard operation
riak-scala-client copied to clipboard

Conditional Fetch requests support

Open ajantis opened this issue 9 years ago • 5 comments

Overview

Introduces support for conditional request parameters when fetching a value from Riak bucket.

Riak Fetch Object (HTTP API) parameters are described in here: http://docs.basho.com/riak/kv/2.1.4/developing/api/http/fetch-object/#request

Supported conditions:

  • IfMatch - fetch a value if it has the same ETag.
  • IfNotMatch - fetch a value if it has a different ETag.
  • IfModifiedSince - fetch a value if it has been modified (Last-Modified attribute) since a specific time.
  • IfUnmodifiedSince - fetch a value if it has been modified (Last-Modified attribute) since a specific time.

Conditions can be combined together.

Compatibility

This change is backwards compatible with existing code that uses the library.

Tests

Tested with integration specs (RiakBucketSpec.scala) against Riak 1.4 (1.4.10) and Riak 2 (2.1.1).

Future improvements

Conditional parameters support can be expanded also to Store Object API: http://docs.basho.com/riak/kv/2.1.4/developing/api/http/store-object/#request

It works the same way in Riak.

Support of other API backends

Note that the conditional requests support in Protobuf API is a bit different: http://docs.basho.com/riak/kv/2.1.4/developing/api/protocol-buffers/fetch-object/#request

  • No support of conditions based on Last-Modified attribute.
  • If(Not)Match conditions are based on VClocks, not ETags.

So HTTP API and Protobuf API are not on par in that sense.

ajantis avatar Jul 07 '16 11:07 ajantis

Coverage Status

Coverage increased (+0.5%) to 81.308% when pulling 11ac7d02f3519871b623c4fcb5b6a708eec37281 on ajantis:conditional-fetch-support into 54f742a19ab6a1bf5d40f7b4a5ef788e8d2e9138 on agemooij:master.

coveralls avatar Jul 07 '16 11:07 coveralls

Looks good! I made some minor comments but nothing really important. Feel free to merge at any time.

agemooij avatar Jul 07 '16 11:07 agemooij

Hey Age,

Thanks for your swift review! ;) I am applying the comments.

Didier's remark makes sense, too: I also was thinking that it might be needed for a client to be able to distinguish 'Not Found' and 'Found but Precondition Failed' cases.

BR, Dmitry

ajantis avatar Jul 08 '16 12:07 ajantis

I agree with @didierliauw too.

I recommend using Spray's StatusCodes (or akka-http's StatusCodes) as inspiration since Http doesn't have 404 and 304 for nothing 😄

agemooij avatar Jul 11 '16 12:07 agemooij

I put this change on hold for now, as there is one substantial piece missing. In case of siblings, all ETag-based conditions don't work with resolved RiakValue's ETag, only with the parent ETag. Currently, library doesn't expose those parent ETags anyhow, so this needs to be fixed as part of this PR, I guess.

ajantis avatar Feb 21 '17 16:02 ajantis