Question

Suppose two processes execute the same write command at the same time to RIAK with same bucket and same key (might be addressing two different RIAK nodes) with allow_mult true and the key is definitely new in the bucket: {ok, WrittenObject} = riakc_pb_socket:put(Pid, Obj, [return_body])

Can it happen that both processes get WrittenObject back where riakc_obj:value_count(WrittenObject) is greater than 1, or definitely one process will have it as 1 and the other gets the value of 2?

Was it helpful?

Solution

Depending on what is already stored at the key, and what vclock is included with each put request, the value count may be 1,2 or 3. Assuming no partition event (i.e. non-failure case), each put will be coordinated by one of the primary vnodes in the key's preflist, and if the vclock contained in the object being stored does not dominate the one already present, both values will be stored. Even if both requests are made nearly simultaneously, which is processed first, and which if not both see a sibling will be a race.

Edit: If the allow_mult property on the bucket is set to false, Riak will select a single value to return based on the X-Riak-Last-Modified and X-Riak-Deleted entries in metadata. This means that the value you put may not be the value returned.

Only if allow_mult is true will you see more than one value returned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top