Hi,
I am trying to implement distributed ID generators using lock and caches.
I wrote some codes like this, but it always throw exception "Failed to
unlock keys exception".
The code may runs in different JVM/hosts.
Do I misuse the lock feature? Thanks in advance.
----------------------------------------------------
Lock lock = osCache.lock(Os.CACHE_LOCK);
try
{
lock.lock();
os = osCache.get(videoMessage.os());
if (os == null)
{
os = new Os(videoMessage.os(),
idGenerator.next(Os.class.getName()));
osCache.put(os.getName(), os);
}
videoMessage.os(os.getId() + "");
}
finally
{
lock.unlock();
}
-------------------------------------------------------End
IdGenerator.next looks like this:
-------------------------------------------------------
public int next(String name)
{
IgniteCache<String, NamedSequence> cache =
ignite.cache(NamedSequence.CACHE_NAME_ID);
NamedSequence sequence = cache.get(name);
if (sequence == null)
{
sequence = new NamedSequence(name);
}
else
{
sequence.increase();
}
cache.put(sequence.getName(), sequence);
return sequence.getSequence();
}
----------------------------------------------------------