You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Ciprian Dorin Craciun <ci...@gmail.com> on 2012/12/18 22:35:54 UTC
Simple "transactional" access (i.e. "repeatable reads") (related to
`last_seq` for previous revisions)
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.
Re: Simple "transactional" access (i.e. "repeatable reads") (related
to `last_seq` for previous revisions)
Posted by Ciprian Dorin Craciun <ci...@gmail.com>.
On Wed, Dec 19, 2012 at 12:04 PM, Dave Cottlehuber <dc...@jsonified.com> wrote:
> On 19 December 2012 10:26, Ciprian Dorin Craciun
> <ci...@gmail.com> wrote:
>> On Wed, Dec 19, 2012 at 11:18 AM, Robert Newson <rn...@apache.org> wrote:
>>> Attempting to use CouchDB's MVCC mechanism as a user-facing version
>>> control system is very problematic, it's probably the #1 misconception
>>> about CouchDB. I strongly advise against it.
>>
>> Indeed I understand that the internal MVCC features shouldn't be
>> used on a day to day business. But in my case I intend to use CouchDB
>> as a "backend" store, thus I'll have a stronger control over it than a
>> normal application / user.
>>
>> From your reply I also understand from this that it is available
>> somehow... Thus how? :)
>>
>> Ciprian.
>
> Please don't abuse CouchDB's MVCC to act as a version control system.
Ok... Either I'm not able to express myself well enough in English, or...
This is the n-th time I reiterate the fact that:
* I don't want to obtain a versioning system out of CouchDB;
* I know that revisions aren't replicated, persistent, etc.;
* I only want to "opportunistically" be able to obtain a snapshot
in time of the some related documents stored inside the same CouchDB
database;
* if it happens that the revision that matches that "snapshot"
isn't available I will restart the entire operation, until either the
process tries enough times, or it manages to push through the
changes...
> Would you live in your car, using the back seat as a bed?
Thus no... I don't want to live in my car... But it happens that
sometimes you do need to sleep on the back seat... :)
> You can store every version that you wish to keep as a separate
> attachment within the same document, or as a separate document and use
> some sort of complex id to track it, or add an additional field for
> the same result.
No it's not the same result. I don't want the revisions to be
persistent. I only want to be able to find out the "sequence" of a
particular revision. (In the end I think I'll settle with a timestamp
written by the application layer, or some other global counter.)
> Those patterns are reliable and appropriate. Using MVCC is not.
Again, as said I know that MVCC is not reliable. I can live
without reliability... But it would be nice to have access to the
MVCC...
Thanks for the reply, don't get me wrong, I understand that what I
want to do is "unorthodox", and I understand all its negative
implications. But for this limited use case that I have I think it's
the best solution.
Ciprian.
Re: Simple "transactional" access (i.e. "repeatable reads") (related
to `last_seq` for previous revisions)
Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 19 December 2012 10:26, Ciprian Dorin Craciun
<ci...@gmail.com> wrote:
> On Wed, Dec 19, 2012 at 11:18 AM, Robert Newson <rn...@apache.org> wrote:
>> Attempting to use CouchDB's MVCC mechanism as a user-facing version
>> control system is very problematic, it's probably the #1 misconception
>> about CouchDB. I strongly advise against it.
>
> Indeed I understand that the internal MVCC features shouldn't be
> used on a day to day business. But in my case I intend to use CouchDB
> as a "backend" store, thus I'll have a stronger control over it than a
> normal application / user.
>
> From your reply I also understand from this that it is available
> somehow... Thus how? :)
>
> Ciprian.
Please don't abuse CouchDB's MVCC to act as a version control system.
Would you live in your car, using the back seat as a bed?
You can store every version that you wish to keep as a separate
attachment within the same document, or as a separate document and use
some sort of complex id to track it, or add an additional field for
the same result.
Those patterns are reliable and appropriate. Using MVCC is not.
Compaction is not only saving on disk space but aids performance by
bringing ordered data into contiguous blocks in the db file again,
e.g. for range queries this helps.
A+
Dave
Re: Simple "transactional" access (i.e. "repeatable reads") (related
to `last_seq` for previous revisions)
Posted by Ciprian Dorin Craciun <ci...@gmail.com>.
On Wed, Dec 19, 2012 at 11:18 AM, Robert Newson <rn...@apache.org> wrote:
> Attempting to use CouchDB's MVCC mechanism as a user-facing version
> control system is very problematic, it's probably the #1 misconception
> about CouchDB. I strongly advise against it.
Indeed I understand that the internal MVCC features shouldn't be
used on a day to day business. But in my case I intend to use CouchDB
as a "backend" store, thus I'll have a stronger control over it than a
normal application / user.
From your reply I also understand from this that it is available
somehow... Thus how? :)
Ciprian.
Re: Simple "transactional" access (i.e. "repeatable reads") (related
to `last_seq` for previous revisions)
Posted by Robert Newson <rn...@apache.org>.
Attempting to use CouchDB's MVCC mechanism as a user-facing version
control system is very problematic, it's probably the #1 misconception
about CouchDB. I strongly advise against it.
CouchDB only cares about the leaf revision of each document (typically
one, but can be more if there are conflicts). Only leaf revisions are
preserved by the compactor and only leaf revisions are replicated.
Compaction is a necessary maintenance chore, artificially delaying it
to preserve older revisions can be painful (i.e, you might run out of
disk space for no good reason).
B.
On 19 December 2012 08:10, Ciprian Dorin Craciun
<ci...@gmail.com> wrote:
> On Wed, Dec 19, 2012 at 9:42 AM, svilen <az...@svilendobrev.com> wrote:
>> IMO couchdb doesnt keep *all* revisions.. i think i read it somewhere.
>> so rough guess, maybe a version control system suits u better?
>> there are a few with usable APIs..
>
> Indeed CouchDB doesn't store all revisions, but:
> * it does store the latest few (I think I remember somewhere a
> configuration option to keep at least the N last revisions, or?);
> * also the compaction can be run only on demand (thus I'm in
> control of when old revisions are dropped);
>
> Thus in my case I don't want an arbitrary old revision. I just
> want to be able to access the revision which was written before a
> certain sequence number, which I can guarantee (through my own
> application level code) that won't span more than a few minutes. (Thus
> missing revisions from the database is not an issue.)
>
> Ciprian.
Re: Simple "transactional" access (i.e. "repeatable reads") (related
to `last_seq` for previous revisions)
Posted by Ciprian Dorin Craciun <ci...@gmail.com>.
On Wed, Dec 19, 2012 at 9:42 AM, svilen <az...@svilendobrev.com> wrote:
> IMO couchdb doesnt keep *all* revisions.. i think i read it somewhere.
> so rough guess, maybe a version control system suits u better?
> there are a few with usable APIs..
Indeed CouchDB doesn't store all revisions, but:
* it does store the latest few (I think I remember somewhere a
configuration option to keep at least the N last revisions, or?);
* also the compaction can be run only on demand (thus I'm in
control of when old revisions are dropped);
Thus in my case I don't want an arbitrary old revision. I just
want to be able to access the revision which was written before a
certain sequence number, which I can guarantee (through my own
application level code) that won't span more than a few minutes. (Thus
missing revisions from the database is not an issue.)
Ciprian.
Re: Simple "transactional" access (i.e. "repeatable reads")
(related to `last_seq` for previous revisions)
Posted by svilen <az...@svilendobrev.com>.
IMO couchdb doesnt keep *all* revisions.. i think i read it somewhere.
so rough guess, maybe a version control system suits u better?
there are a few with usable APIs..
ciao
svilen
On Tue, 18 Dec 2012 23:35:54 +0200
Ciprian Dorin Craciun <ci...@gmail.com> wrote:
> 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...
...
> As such, are there other ideas, observations, solutions?
>