On 21/12/2015 14:17, Torgeir Veimo wrote: > Can someone confirm if the atomic counter support code is suitable for > sequences? > I think on Segment it can safely be used but not on a mongo cluster.
What the atomic counter ensure is that the amount of increments/decrements is consistent from a persistence POV no matter the number of concurrent operations you're pushing in. While the sequence use case is more like: give me the next available value. it's definitely a good starting point on top of which you can build a sequence mechanism. if we speak of single instance Segment only, you can opt for an application side lock in which you put in the increments and fetch of the value. Something like: public static long nextSeq(String p, Session s) { // ... fecthing of the node by path `p` // initiate application side lock session.refresh(); // fetch whatever may come from other MVCC counter.setProperty("oak:increment", 1); session.save(); long seq = counter.getProperty(...).getLong(); // release lock return seq; } As said, on segment ONLY, it should work fairly fine. It won't work on a mongo clustered instance as the cluster nodes alignment is asynchronous and because of OAK-2472. So to be put in words, you may have the same sequence returned by two different cluster nodes. HTH Davide