Don't use the version as your timestamp.  It's possible, but you'll end up
with problems when attempting to overwrite or delete entries.

Instead, make the version part of the primary key:

CREATE TABLE document_store (document_id bigint, version int, document
text, PRIMARY KEY (document_id, version)) WITH CLUSTERING ORDER BY (version
desc)

That way you don't have to worry about overwriting higher versions with a
lower one, and to read the latest version, you only have to do:

SELECT * FROM document_store WHERE document_id = ? LIMIT 1;

Another option is to use lightweight transactions (i.e. UPDATE ... SET
docuement = ?, version = ? WHERE document_id = ? IF version < ?), but
that's going to make writes much more expensive.

On Wed, Mar 11, 2015 at 12:45 AM, Sachin Nikam <skni...@gmail.com> wrote:

> I am planning to use the Update...USING TIMESTAMP... statement to make
> sure that I do not overwrite fresh data with stale data while having to
> avoid doing at least LOCAL_QUORUM writes.
>
> Here is my table structure.
>
> Table=DocumentStore
> DocumentID (primaryKey, bigint)
> Document(text)
> Version(int)
>
> If the service receives 2 write requests with Version=1 and Version=2,
> regardless of the order of arrival, the business requirement is that we end
> up with Version=2 in the database.
>
> Can I use the following CQL Statement?
>
> Update DocumentStore using <versionValue>
> SET  Document=<documentValue>,
> Version=<versionValue>
> where DocumentID=<documentIDValue>;
>
> Has anybody used something like this? If so was the behavior as expected?
>
> Regards
> Sachin
>



-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Reply via email to