Does IgniteCache.containsKey lock the key in a Transaction?

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

Does IgniteCache.containsKey lock the key in a Transaction?

Hi All, Does  IgniteCache.containsKey() lock the key in a Transaction similar to IgniteCache.get() ? Basically I want a lightweight call to lock the key without having to Serialize objects from each node within a Transaction.

 

 

_________________________________________________________

This email, its contents, and any attachments transmitted with it are intended only for the addressee(s) and may be confidential and legally privileged. We do not waive any confidentiality by misdelivery. If you have received this email in error, please notify the sender immediately and delete it. You should not copy it, forward it or otherwise use the contents, attachments or information in any way. Any liability for viruses is excluded to the fullest extent permitted by law.

Tudor Capital Europe LLP (TCE) is authorised and regulated by The Financial Conduct Authority (the FCA). TCE is registered as a limited liability partnership in England and Wales No: OC340673 with its registered office at 10 New Burlington Street, London, W1S 3BE, United Kingdom

nattapon nattapon
Reply | Threaded
Open this post in threaded view
|

Re: Does IgniteCache.containsKey lock the key in a Transaction?

Hi Yohan,

There is IgniteCache.lock(key) method described in https://apacheignite.readme.io/docs/distributed-locks . Is it suited your requirement?

IgniteCache<String, Integer> cache = ignite.cache("myCache");

// Create a lock for the given key
Lock lock = cache.lock("keyLock");
try {
    // Acquire the lock
    lock.lock();
 
    cache.put("Hello", 11);
    cache.put("World", 22);
}
finally {
    // Release the lock
    lock.unlock();
}

Regards,
Nattapon

On Fri, Aug 16, 2019 at 5:23 PM Yohan Fernando <[hidden email]> wrote:

Hi All, Does  IgniteCache.containsKey() lock the key in a Transaction similar to IgniteCache.get() ? Basically I want a lightweight call to lock the key without having to Serialize objects from each node within a Transaction.

 

 

_________________________________________________________

This email, its contents, and any attachments transmitted with it are intended only for the addressee(s) and may be confidential and legally privileged. We do not waive any confidentiality by misdelivery. If you have received this email in error, please notify the sender immediately and delete it. You should not copy it, forward it or otherwise use the contents, attachments or information in any way. Any liability for viruses is excluded to the fullest extent permitted by law.

Tudor Capital Europe LLP (TCE) is authorised and regulated by The Financial Conduct Authority (the FCA). TCE is registered as a limited liability partnership in England and Wales No: OC340673 with its registered office at 10 New Burlington Street, London, W1S 3BE, United Kingdom

yfernando yfernando
Reply | Threaded
Open this post in threaded view
|

RE: Does IgniteCache.containsKey lock the key in a Transaction?

Hi Nattapon,

 

Unfortunately explicit locks cannot be used within transactions and an exception will be thrown.

 

It seems the only way is to rely on implicit locks using calls like get() and containsKey(). I looked through the ignite source for these methods and it does appear like containsKey delegates to the same call as get() but has a flag about whether to serialize or not so I assume that containsKey might avoid serialization. However I’m not an expert on the Ignite codebase so it would be good if someone can confirm that this is indeed the case.

 

Thanks

 

Yohan

 

From: nattapon <[hidden email]>
Sent: 19 August 2019 08:00
To: [hidden email]
Subject: Re: Does IgniteCache.containsKey lock the key in a Transaction?

 

Caution: This email originated from outside of Tudor.

 

Hi Yohan,

 

There is IgniteCache.lock(key) method described in https://apacheignite.readme.io/docs/distributed-locks . Is it suited your requirement?

 

IgniteCache<String, Integer> cache = ignite.cache("myCache");

// Create a lock for the given key
Lock lock = cache.lock("keyLock");
try {
    // Acquire the lock
    lock.lock();
 
    cache.put("Hello", 11);
    cache.put("World", 22);
}
finally {
    // Release the lock
    lock.unlock();
}

 

Regards,

Nattapon

 

On Fri, Aug 16, 2019 at 5:23 PM Yohan Fernando <[hidden email]> wrote:

Hi All, Does  IgniteCache.containsKey() lock the key in a Transaction similar to IgniteCache.get() ? Basically I want a lightweight call to lock the key without having to Serialize objects from each node within a Transaction.

 

 

_________________________________________________________

This email, its contents, and any attachments transmitted with it are intended only for the addressee(s) and may be confidential and legally privileged. We do not waive any confidentiality by misdelivery. If you have received this email in error, please notify the sender immediately and delete it. You should not copy it, forward it or otherwise use the contents, attachments or information in any way. Any liability for viruses is excluded to the fullest extent permitted by law.

Tudor Capital Europe LLP (TCE) is authorised and regulated by The Financial Conduct Authority (the FCA). TCE is registered as a limited liability partnership in England and Wales No: OC340673 with its registered office at 10 New Burlington Street, London, W1S 3BE, United Kingdom

_________________________________________________________

This email, its contents, and any attachments transmitted with it are intended only for the addressee(s) and may be confidential and legally privileged. We do not waive any confidentiality by misdelivery. If you have received this email in error, please notify the sender immediately and delete it. You should not copy it, forward it or otherwise use the contents, attachments or information in any way. Any liability for viruses is excluded to the fullest extent permitted by law.

Tudor Capital Europe LLP (TCE) is authorised and regulated by The Financial Conduct Authority (the FCA). TCE is registered as a limited liability partnership in England and Wales No: OC340673 with its registered office at 10 New Burlington Street, London, W1S 3BE, United Kingdom

Denis Mekhanikov Denis Mekhanikov
Reply | Threaded
Open this post in threaded view
|

Re: Does IgniteCache.containsKey lock the key in a Transaction?

Yohan,

IgniteCache#containsKey(...) locks a key under pessimistic transactions with REPEATABLE_READ isolation level, just like a get().
And it doesn’t make servers send values back to a requesting node, so basically it does what you need.

Denis

On 19 Aug 2019, at 14:08, Yohan Fernando <[hidden email]> wrote:

Hi Nattapon,
 
Unfortunately explicit locks cannot be used within transactions and an exception will be thrown.
 
It seems the only way is to rely on implicit locks using calls like get() and containsKey(). I looked through the ignite source for these methods and it does appear like containsKey delegates to the same call as get() but has a flag about whether to serialize or not so I assume that containsKey might avoid serialization. However I’m not an expert on the Ignite codebase so it would be good if someone can confirm that this is indeed the case.
 
Thanks
 
Yohan
 
From: nattapon <[hidden email]> 
Sent: 19 August 2019 08:00
To: [hidden email]
Subject: Re: Does IgniteCache.containsKey lock the key in a Transaction?
 
Caution: This email originated from outside of Tudor.
 
Hi Yohan,
 
There is IgniteCache.lock(key) method described in https://apacheignite.readme.io/docs/distributed-locks . Is it suited your requirement?
 
IgniteCache<String, Integer> cache = ignite.cache("myCache");

// Create a lock for the given key
Lock lock = cache.lock("keyLock");
try {
    // Acquire the lock
    lock.lock();
  
    cache.put("Hello", 11);
    cache.put("World", 22);
}
finally {
    // Release the lock
    lock.unlock();
}
 
Regards,
Nattapon
 
On Fri, Aug 16, 2019 at 5:23 PM Yohan Fernando <[hidden email]> wrote:
Hi All, Does  IgniteCache.containsKey() lock the key in a Transaction similar to IgniteCache.get() ? Basically I want a lightweight call to lock the key without having to Serialize objects from each node within a Transaction. 
 
 

_________________________________________________________

This email, its contents, and any attachments transmitted with it are intended only for the addressee(s) and may be confidential and legally privileged. We do not waive any confidentiality by misdelivery. If you have received this email in error, please notify the sender immediately and delete it. You should not copy it, forward it or otherwise use the contents, attachments or information in any way. Any liability for viruses is excluded to the fullest extent permitted by law.

Tudor Capital Europe LLP (TCE) is authorised and regulated by The Financial Conduct Authority (the FCA). TCE is registered as a limited liability partnership in England and Wales No: OC340673 with its registered office at 10 New Burlington Street, London, W1S 3BE, United Kingdom

_________________________________________________________

This email, its contents, and any attachments transmitted with it are intended only for the addressee(s) and may be confidential and legally privileged. We do not waive any confidentiality by misdelivery. If you have received this email in error, please notify the sender immediately and delete it. You should not copy it, forward it or otherwise use the contents, attachments or information in any way. Any liability for viruses is excluded to the fullest extent permitted by law.

Tudor Capital Europe LLP (TCE) is authorised and regulated by The Financial Conduct Authority (the FCA). TCE is registered as a limited liability partnership in England and Wales No: OC340673 with its registered office at 10 New Burlington Street, London, W1S 3BE, United Kingdom