How does CouchDB calculate the Sequence Id (seq)

北城余情 提交于 2019-12-11 17:09:41

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/53962975/how-does-couchdb-calculate-the-sequence-id-seq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!