Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This question is pretty old but I'd like to complete it with an other solution. </p> <p>Any solution that relies on nodes synchronization is unreasonable. It's pretty sure to break either by blocking IDs generation or by creating duplicate IDs.</p> <h2>MySQL way</h2> <p>You can reproduce the way it's done with the mysql master-master replication with the <code>auto_increment_increment</code> and <code>auto_increment_offset</code> parameters.</p> <p>To reproduce it, you need to know the number of nodes or the max number of expected nodes and you need to create a (non-cassandra) counter (a file per example) on each node.</p> <p>Each time you want to generate a new number, you find the current value, add the increment and save it. If it doesn't exist yet, it's the offset.</p> <p>So for 10 nodes, you would have an increment of 10 and an offset of 1 for the first node, 2 for the second node, etc. Node 1 would create the IDs 1, 11, 21. Node 2 would create the IDs 2, 21, 22.</p> <p>If you want your IDs to be (approximatively) ordered between nodes, you need to maintain a shared counter and make sure each generated ID is higher than the shared counter. That way, unless your nodes/datacenters are out of sync for a long time, you shouldn't notice much difference.</p> <h2>Prefixing</h2> <p>You can do basically the same thing by prefixing the ID (if it's an acceptable solution) with the node number (or name). And you don't have to known the number of nodes. Node 1 would create 1_1, 1_2, 1_3. Node 2 would create 2_1, 2_2, 2_3.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload