AJ Venturella
AJ Venturella

Reputation: 4922

How does CouchDB calculate the Sequence Id (seq)

I am looking for pseudo code or the actual code in the source repository (https://github.com/apache/couchdb) defining how CouchDB calculates the seq value.

Reviewing the technical overview in the docs: http://docs.couchdb.org/en/2.2.0/intro/overview.html it says:

Each update to a database instance generates a new sequential number.

But it doesn't go into how. I think that it may be implementation dependent, looking at the replication protocol docs it states:

Sequence ID: An ID provided by the Changes Feed. It MUST be incremental, but MAY NOT always be an integer.

 1-g1AAAAIreJyVkEsKwjAURZ-toI5cgq5A0sQ0OrI70XyppcaRY92J7kR3ojupaSPUUgotgRd4yTlwbw4A0zRUMLdnpaMkwmyF3Ily9xBwEIuiKLI05KOTW0wkV4rruP29UyGWbordzwKVxWBNOGMKZhertDlarbr5pOT3DV4gudUC9-MPJX9tpEAYx4TQASns2E24ucuJ7rXJSL1BbEgf3vTwpmedCZkYa7Pulck7Xt7x_usFU2aIHOD4eEfVTVA5KMGUkqhNZV-8_o5i

This questions is somewhat related in that it's asking how it calculates another component of a document, the rev:

How does CouchDB calculate the Revision number

Upvotes: 0

Views: 1822

Answers (1)

Juanjo Rodriguez
Juanjo Rodriguez

Reputation: 2131

You can find here some information about the change sequence internals

The sequence number reflects the cluster state for a document update sequence, this information is encoded into the sequence number.

The numeric part of the sequence number is the sum of the update sequences of a document in each of the cluster nodes.

The second part of the sequence number is a base64 encoded string with the update sequence information in each of the cluster nodes.

Upvotes: 2

Related Questions