You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by begineer <re...@gmail.com> on 2017/09/28 05:40:39 UTC

Using igniteAtomicLong or igniteAtomicSequence as uniqueId in ignite cache

Hi,
My application submits heavy requests from UI which are run in async and
request Id is stored in ignite cache and other request details  as value. I
was looking for a way to generate request id. One way to use AtlomicInteger
but that will not support distributed behavior. So I found igniteAtomicLong
datastructure but not quite sure how would I create its bean in spring.xml
to use it.

If some one can provide some sample example , it would be helpful

Thanks



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Using igniteAtomicLong or igniteAtomicSequence as uniqueId in ignite cache

Posted by begineer <re...@gmail.com>.
Thanks for reply. Surely this should work.Just one query. Will it work in
distributed environment. We have a grid of nodes and I am trying to do it in
a way that it should be working on cluster of nodes than just one jvm.

Regards



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Using igniteAtomicLong or igniteAtomicSequence as uniqueId in ignite cache

Posted by Alexey Kukushkin <ku...@gmail.com>.
Hi,

Some thoughts that might help you to make a decision:

   - IgniteAtomicLong and IgniteAtomicSequence are both public interfaces
   but their implementations are inside the internal part of Ignite. It is a
   bad practice to reference Ignite internals so you cannot configure them in
   the XML file.
   - You create both atomic long and sequence as Ignite#atomicLong(name,
   initialValue) and Ignite#atomicSequence(name, initialValue). Thus, if you
   really want to make them Spring beans you could create an annotated spring
   configuration (@Configuration MyConfiguration { ... }) and provide factory
   methods for them (like @Bean public requestId() { return
   ignite.atomicLong("requestId", initialValue); }
   - In my opinion both the methods currently have this design flaw: even
   if you enable native persistence, you still cannot get the last sequence
   value since you are forced to provide initial value in the factory methods.
   Thus, you have to provide your custom mechanism to restore last sequence
   value after the cluster restart and pass it as initialValue if you want the
   value to be unique through the cluster restarts.
   - Please note differences between atomic long and sequence: both of them
   provide unique values but the "long" is sequential but slower and the
   "sequence" is not sequential but faster.
   - Are you sure simple Java UUID.randomUUID() will not work for you?