ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shawn Du" <shawn...@neulion.com.cn>
Subject 答复: Lock and Failed to unlock keys exception
Date Thu, 24 Nov 2016 07:11:15 GMT
Fixed by myself.

There are two errors in my code/configuration.

1) lock are only supported in TRANSACTIONAL mode. I missed it in my
configuration.
2) within a lock block, can't start cache:
  IgniteCache<String, NamedSequence> cache =
ignite.cache(NamedSequence.CACHE_NAME_ID);
  
  Above code should be called out of the lock block.

Thanks
Shawn

-----邮件原件-----
发件人: Shawn Du [mailto:shawn.du@neulion.com.cn] 
发送时间: 2016年11月24日 14:20
收件人: user@ignite.apache.org
主题: Lock and Failed to unlock keys exception

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();
}
----------------------------------------------------------


Mime
View raw message