*USE CASE *- use IgniteAtomicLong for table sequence generation (may not be
correct approach in a distributed environment).

*Ignite Server *(start Ignite as server mode) - apache-ignite-2.8.0.20190215
daily build
*Ignite Service* (start Ignite as client mode) - use Ignite Spring to
initialize the sequence, see code snippet below.  
*code snippet*

IgniteAtomicLong userSeq;

@Autowired
UserRepository userRepository;

@Autowired
Ignite igniteInstance;

@PostConstruct
@Override
public void initSequence() {
Long maxId = userRepository.getMaxId();
if (maxId == null)

{ maxId = 0L; }
LOG.info("Max User id: {}", maxId);
userSeq = igniteInstance.atomicLong("userSeq", maxId, true);
userSeq.getAndSet(maxId);
}

@Override
public Long getNextSequence() {
return userSeq.incrementAndGet();
}

*Exception*
This code works well until the Ignite Server restarted (Ignite Service was
not restarted).  It raised "Sequence was removed from cache" after Ignite
Server node restarted.

020-08-11 16:14:46 [http-nio-8282-exec-3] ERROR
c.p.c.p.service.PersistenceService - Error while saving entity:
java.lang.IllegalStateException: Sequence was removed from cache: userSeq
at
org.apache.ignite.internal.processors.datastructures.AtomicDataStructureProxy.removedError(AtomicDataStructureProxy.java:145)
at
org.apache.ignite.internal.processors.datastructures.AtomicDataStructureProxy.checkRemoved(AtomicDataStructureProxy.java:116)
at
org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongImpl.incrementAndGet(GridCacheAtomicLongImpl.java:94)

*Tried to reinitialize when the server node is down. But raises another
exception - "cannot start/stop cache within lock or transaction"*

How to solve such issues?  Any suggestions are appreciated.

@Override
public Long getNextSequence() {
if (useSeq == null || userSeq.removed())

{ initSeqence(); }
return userSeq.incrementAndGet();
}






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

Reply via email to