You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Григорий Доможиров <gr...@gmail.com> on 2020/02/11 21:11:46 UTC

Using putAll(TreeMap) with BinaryObjects

Hello.
As I know it's recommended to use putAll with TreeMap to avoid deadlocks
(is there any other reasons?). If so, how to deal with .withKeepBinary
cache, where you have to provide Map of BinaryObjects, which are not
Comparable, and thus couldn't be put in TreeMap?

Also, why deadlocks could happen with HashMap, and why using TreeMap
prevents it?

Re: Using putAll(TreeMap) with BinaryObjects

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I think it needs not be present on server, but I recommend testing that :)

Regards,
-- 
Ilya Kasnacheev


чт, 21 мая 2020 г. в 15:59, Grigory.D <gr...@gmail.com>:

> Question is still open:
> In case of using TreeMap with Comparator provided to constructor, should
> this comparator be present on server node, or it is just applied on client
> side?
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Using putAll(TreeMap) with BinaryObjects

Posted by "Grigory.D" <gr...@gmail.com>.
Question is still open:
In case of using TreeMap with Comparator provided to constructor, should
this comparator be present on server node, or it is just applied on client
side?



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Using putAll(TreeMap) with BinaryObjects

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

It was discussed previously but did not get anywhere
http://apache-ignite-developers.2346864.n4.nabble.com/Let-s-make-BinaryObjectImpl-and-CacheKeyObject-Comparable-td46028.html

Regards,
-- 
Ilya Kasnacheev


чт, 21 мая 2020 г. в 08:16, <vt...@gmail.com>:

> Hi,
>
> I did implement user pojo with comparator on the client node, that pojo
> exists in the client process jar file. That approach works well on the
> client.
>
> But it seems that pojo will not be zero deployed, since it is just user
> class without any system inheritance. So I didn't even try to use it in
> ComputeJobAdapter objects that are executed on the cluster nodes.
>
> It will ge great to implement comparable binary object on the system level
>
> 16:08, 20 мая 2020 г., "Grigory.D" <gr...@gmail.com>:
>
> For solution 2, should Comparator implementation class be present on server
> node (in case of no p2p cl enabled)? Or it is used only on client side.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
>
>
> --
> Отправлено из мобильного приложения Яндекс.Почты

Re: Using putAll(TreeMap) with BinaryObjects

Posted by vt...@gmail.com.
Hi,

  

I did implement user pojo with comparator on the client node, that pojo exists
in the client process jar file. That approach works well on the client.

  

But it seems that pojo will not be zero deployed, since it is just user class
without any system inheritance. So I didn't even try to use it in
ComputeJobAdapter objects that are executed on the cluster nodes.

  

It will ge great to implement comparable binary object on the system level  
  

16:08, 20 мая 2020 г., "Grigory.D" <gr...@gmail.com>:  

> For solution 2, should Comparator implementation class be present on server  
> node (in case of no p2p cl enabled)? Or it is used only on client side.  
>  
>  
>  
>

>

> \--  
> Sent from: <http://apache-ignite-users.70518.x6.nabble.com/>  
>

  
  
\--  
Отправлено из мобильного приложения Яндекс.Почты


Re: Using putAll(TreeMap) with BinaryObjects

Posted by "Grigory.D" <gr...@gmail.com>.
For solution 2, should Comparator implementation class be present on server
node (in case of no p2p cl enabled)? Or it is used only on client side.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Using putAll(TreeMap) with BinaryObjects

Posted by Pavel Tupitsyn <pt...@apache.org>.
The reason for any deadlock (local or distributed) is taking locks on same
objects in different order, e. g:
Thread 1 locks A, B
Thread 2 locks B, A
  => thread 1 holds A and waits on B, thread 2 holds B and waits on A

When doing putAll, Ignite iterates over the provided map and locks keys in
the iterator order.
TreeMap is sorted, so it solves the problem automatically. Locks are taken
in the same order on all nodes/threads, preventing deadlocks.
HashMap can reorder elements arbitrarily, on the other hand, causing random
deadlocks.


For withKeepBinary cache you have two options:
- LinkedHashMap preserves insertion order. Make sure you always populate
the map in the same order.
- TreeMap with Comparator. Implement Comparator that sorts your keys the
right way, probably based on a particular field of the BinaryObject



On Wed, Feb 12, 2020 at 12:12 AM Григорий Доможиров <
grigorydomozhirov@gmail.com> wrote:

> Hello.
> As I know it's recommended to use putAll with TreeMap to avoid deadlocks
> (is there any other reasons?). If so, how to deal with .withKeepBinary
> cache, where you have to provide Map of BinaryObjects, which are not
> Comparable, and thus couldn't be put in TreeMap?
>
> Also, why deadlocks could happen with HashMap, and why using TreeMap
> prevents it?
>