Hello all!
Previously I've written an email inquiring about how to get
`last_seq` on previous revisions of an object. The purpose of that is
described below.
I intend to use CouchDB as a backend for a configuration
management solution. For this I need a way to achieve the following:
simple "repeatable reads" transactions...
!!!! Now before everyone starts shouting at me that this is not
the purpose of CouchDB, or even achievable, I say to my defense that I
know that... I don't want transactions in the SQL sense, I just want
"repeatable reads"... :)
All I want to achieve is the following:
* given that the configuration of a service is composed of
multiple documents inside a database; (with multiple service
configurations sharing the same database;)
* given that all updates that touch a configuration's documents,
are made in a single request of the bulk write (with atomic set to
true);
* I want to be able to read "consistent" revisions of a particular
document graph, regardless of other write operations that have
happened;
I think I could achieve this by using "multiple" get, but I'm
unsure, and moreover I don't know before hand which documents are
needed.
To achieve this I though about the following simple algorithm
which provides me with a limited MVCC-like solution:
* before reading or writing I read the last sequence number of the
entire database; (I call this the "session sequence";)
* when reading a document I first "stat" it's latest revision and
see if it's sequence is less or equal to that of the session;
** if not I read a revision back and check again; (I stop after
reading a couple of revisions and give an error);
* (up to this point all read documents are either coming from
unrelated "write sessions" or were written inside the same "write
session", but I can't have them mixed);
* I repeat the above for any needed document;
* any document to be written is batched inside a single bulk write
with atomic set to true;
* if any conflict existed I go to step one;
As seen I try to use time limited document versioning, to achieve
some kind of "repeatable reads" transactions.
As such, are there other ideas, observations, solutions?
Thanks,
Ciprian.