Yohan, IgniteCache#containsKey(...) <https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/IgniteCache.html#containsKey-K-> 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 <yohan.ferna...@tudor.com> 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 <wrong...@gmail.com <mailto:wrong...@gmail.com>> > Sent: 19 August 2019 08:00 > To: user@ignite.apache.org <mailto:user@ignite.apache.org> > 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 > <https://urldefense.proofpoint.com/v2/url?u=https-3A__apacheignite.readme.io_docs_distributed-2Dlocks&d=DwMFaQ&c=lcVbikor4usg5Rj5OmznbA&r=m3tOHOhTDmqyOCq26PYainXMtahLsVWUQ4sqnN5broM&m=OI_UZ3gny3V8V5LQLeGQxF_GFdCwvZRHvxcHXzZ9tno&s=Bi2hfO-Sdhxidc_h2QGpmMRSfsEapHSmgLg9BH0nNbo&e=> > . 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 <yohan.ferna...@tudor.com > <mailto:yohan.ferna...@tudor.com>> 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 >