Significance of generation field in Write Policy


Hi, While writing a record to database there is a field in WrietePolicy , which is generation. If I am explicitly setting it to 0 or 1 and next I am trying fetch the record I see the generation is incremented value equal to number of times the record is updated. Is this generation value decides different version of records in the device file (persisted records to file or ssd) ?

Can client change this generation value to 1 always. I am not clear on the use of this generation field in WritePolicy.

Transaction using aerospike

Its an internal counter that Aerospike increments every time you update a record. You cannot change the value of the counter. It rolls over back to zero after 64K. Aerospike keeps track of the rollover. It is used to accomplish read - modify - write between two separate locks on the record. In the read operation, which is under a single record lock, besides reading the data, you also read the generation value. In the write operation, which is another, but separate record lock, you send the update you want to make and the previously read generation value and use write policy GEN_EQUAL which tells Aerospike - make the update to the record only if the generation value is ‘this’ … whatever you passed. If someone modified the record between your read and write, your write will not succeed in this case and you can retry the read-modify-write. It is also called “Check and Set” functionality. It is useful in modeling some problems and is required because Aerospike has record level locks, for both read and write operations. There are two other possible alternatives, depending on use case, to using this method (GEN_EQ)… one is via Operate() and the other is using Record UDFs (User defined functions).

*Gen counter is not updated if you just read a record


Thank you for the information!