Named cluster-wide lock

classic Classic list List threaded Threaded
4 messages Options
Alex Rogachevsky Alex Rogachevsky
Reply | Threaded
Open this post in threaded view
|

Named cluster-wide lock

I need to lock the entire cluster during loading. Different cluster nodes load different caches concurrently from different "databases" on startup. I adapted the IgniteCountDownLatch for that, however a more "atomic" cluster-wide lock would be nice. Something like

java.util.concurrent.locks.Lock Ignite.lock(String lockName, Long timeout), where timeout can be null to wait indefinitely or zero to just try the lock.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Named cluster-wide lock

Hi Alex,

You can create transactional IgniteCache and use explicit lock provided by IgniteCache.lock(K key) method.
Adding distributed locks as well as other synchronization structures is on the roadmap: https://issues.apache.org/jira/browse/IGNITE-641

-Val
Alex Rogachevsky Alex Rogachevsky
Reply | Threaded
Open this post in threaded view
|

Re: Named cluster-wide lock

Thanks. I remember thinking about that when I implemented that framework feature, but something prevented me from doing it. I think I didn't want to do an extra step and check if the cache exists. I want it to be a one-step atomic operation. Let me revisit it.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Named cluster-wide lock

Alex Rogachevsky wrote
Thanks. I remember thinking about that when I implemented that framework feature, but something prevented me from doing it. I think I didn't want to do an extra step and check if the cache exists. I want it to be a one-step atomic operation. Let me revisit it.
Alex,

I don't think you need any additional steps, just use Ignite.getOrCreateCache() method. It will do all required synchronization internally.

-Val