Is MongooseJS "versionKey" (__v field) a "vector clock"?

I have been using MongooseJS revisionKeyfor a while - the field __vthat it includes with documents is by default. I understand what the purpose of the version number is, and generally when it is updated.

I recently spoke with a friend about the idea of ​​a "vector clock", and I mentioned MongoDB and MongooseJS having this field __v. At that time it sounded like it could be a vector clock. But having read a little about vector clocks, now I'm not sure.

So I'm wondering: can the versionKeyMongooseJS attribute and the field __vthat it creates by default, can be considered a vector clock? Yes or no, and why?

+4
source share
2 answers

In my opinion, the versionKeyone you are talking about cannot be considered a vector hour. You might consider this a Lamport (or Lamport Clock) timestamp.

Let's look globally at what we manage:

Both Lamport timestamps and vector clocks are algorithms used to determine the causality order for various events occurring in a distributed system. In other words, both algorithms are used to synchronize events that do not have a common reference.

The Lamport timestamp algorithm uses one counter for each process (in case of a question, we can say one counter for each document). The algorithm works as follows:

1) , (, ..), .

2) , .

3) - , ( ), , ,

, :

Lamport timestamps for three processes

Lamport , , ( .

, versionKey - , , , , .

Mongoose (Mongoose v3 1:: :

3 increment(), . , , .

, versionKey , , .

, , increment() . Lamport, , . versionKey Lamport.

( ). versionKey :

  • , . . , . versionKey , . DynamoDB ,

:

, . (node, counter). . , , . , . .

versionKey, Lamport .

+4

, versionKey save findOneAndUpdate. versionKey update mongo cli, , .

+2

All Articles