1

We are working on a layered Java application that talks directly to Gemfire.

We need to be able to generate unique "long" sequence numbers, guaranteed unique across all nodes of the application. (Not all nodes are clustered)

Normally I would create a sequence in Oracle, but in this case, even though our Gemfire configuration has a connection to the relational database for write behind persistence, our application has no other knowledge of the database.

What would be the best way to generate those guaranteed unique long values, without going to the database?

Victor Grazi
  • 15,563
  • 14
  • 61
  • 94
  • 3
    I don't know anything about gemfire but generalized solution to getting unique id in a distributed system is to assign each node a unique prefix manually. Then when you need a new unique number combine that nodes prefix with an incremented suffix, where each node maintains its highest allocated suffix. – bhspencer Jan 28 '15 at 18:53
  • @bhspencer this works if we don't need a global order which tells if one event arrives before another – Hui Wang Dec 26 '16 at 15:32
  • @HuiWang If you need guaranteed order then you need to have a central authority assign the sequence numbers. I have used an Apache Zookeeper cluster for this purpose using the Curator recipe "Distributed Atomic Long" – bhspencer Dec 26 '16 at 18:13
  • thx a lot @bhspencer for that information :) – Hui Wang Dec 26 '16 at 20:26

1 Answers1

3

The first question to ask yourself is do you really need a long sequence number (monotonically increasing long integer) or do you just need a globally unique identifier (like a UUID).

The most performant solution is going to be a globally unique id and I would just suggest using a GUID.

If you need a globally unique monotonically increasing long value (long sequence) then you will have to use some distributed locking and increment a value in the region. The method for this and performance depends on the type of region you are using.

Look at Region.replace(K, V, V). It can perform globally atomic updates to values under specific region definitions. You may need to consider a region that just has your sequences if your current region type is not sufficiently defined.