Using putAll(TreeMap) with BinaryObjects

classic Classic list List threaded Threaded
7 messages Options
Grigory.D Grigory.D
Reply | Threaded
Open this post in threaded view
|

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?
ptupitsyn ptupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: Using putAll(TreeMap) with BinaryObjects

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 Григорий Доможиров <[hidden email]> 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?
Grigory.D Grigory.D
Reply | Threaded
Open this post in threaded view
|

Re: Using putAll(TreeMap) with BinaryObjects

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/
vtchernyi vtchernyi
Reply | Threaded
Open this post in threaded view
|

Re: Using putAll(TreeMap) with BinaryObjects

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" <[hidden email]>:

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/


--
Отправлено из мобильного приложения Яндекс.Почты
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Using putAll(TreeMap) with BinaryObjects

Hello!


Regards,
--
Ilya Kasnacheev


чт, 21 мая 2020 г. в 08:16, <[hidden email]>:
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" <[hidden email]>:

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/


--
Отправлено из мобильного приложения Яндекс.Почты
Grigory.D Grigory.D
Reply | Threaded
Open this post in threaded view
|

Re: Using putAll(TreeMap) with BinaryObjects

In reply to this post by Grigory.D
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/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Using putAll(TreeMap) with BinaryObjects

Hello!

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

Regards,
--
Ilya Kasnacheev


чт, 21 мая 2020 г. в 15:59, Grigory.D <[hidden email]>:
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/