1

I have a problem very similar in nature to Java: Unique 10 digit ID where I need to generate a subset of a 10 digit sequence in the event that there is a DB outage and I can't use its sequence generator.

I'd like to use this feature, but my use case requires that I keep track of the last ID generated so as to not cause collisions. This needs to be done in a fault tolerant way - and the value should survive a failover from one DC so if the Hazelcast cluster comes up we start back at the last used value.

My thoughts when looking through the Hazelcast docs were to configure write-behind persistence and set the delay to be close to the DB-SLA for an unplanned outage (on the order of a few hours however I have a feeling this might not be advisable). And then try to retrieve the latest ID used if the cluster starts and the value is 0 -- meaning the entire cluster was restarted.

Any thoughts?

EDIT Sounds like this answer could be onto something - using a shared filesystem and serializing to a flat file. What if I can't get a shared filesystem provisioned in my environment. Are there any other options?

Community
  • 1
  • 1
cwash
  • 4,185
  • 5
  • 43
  • 53
  • [This github issue](https://github.com/hazelcast/hazelcast/issues/11) seems to indicate it's already a feature in 3.0 however I do not see it. – cwash Feb 26 '14 at 19:42

3 Answers3

1

We are going to implement something like this in the near future, but that doesn't solve your problem today.

I would have a look at the IAtomicLong and the IdGenerator implementation. You can easily create your own IdGenerator implementation based on the code examples that does have storage.

pveentjer
  • 10,545
  • 3
  • 23
  • 40
  • Would the storage implementation follow the same general approach outlined [here](http://stackoverflow.com/questions/10453559/hazelcast-file-persistence-mapstore-implementation/10493031#10493031)? – cwash Feb 24 '14 at 21:03
  • 1
    No. it would build on top of our SPI: Service Provider Interface. The API we use to write our own distributed datastructures. Have a look at the IdGenerator implementation, it isn't very difficult to create an implementation yourself that does have persistence. – pveentjer Feb 24 '14 at 21:05
0

I used this article to help me figure out how to get MapStore writing to the local file system. Then I used the IdGenerator's init() method to start with the last used sequence number (that was written through last). Finally whenever someone asks for a number, they get it from a service which grabs the nextId() and then puts it into my Hazelcast MapStore and stores it behind on the local filesystem for fault tolerance.

I have more testing to do but the approach seems to work.

cwash
  • 4,185
  • 5
  • 43
  • 53
0

This is how you do it these days without persistence:

hazelcastInstance.getFlakeIdGenerator("name_you_want_to_give_it").newId()

wild_nothing
  • 2,845
  • 1
  • 35
  • 47