|Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/7/12 2:34 AM|
I've thought about the following idea over the weekend:
MultiMap is a very useful data-structures in many cases, but its set of values for each key is represented as a collection (e.g. list or set).
For some use-cases though, it could be interesting to have a very similar data structure, which uses usual java.util.Maps for values. Let's call such values "value-maps" to distinguish them from the usual HZ maps. In all other respects, its overall design should be similar to MultiMap. It means, among other things that a value-map belonging to a given key is not distributed and is handled as a usual value by HZ, just like it is done for a MultiMap values collection belonging to the same key.
The methods for manipulating entries of a MapMap would be of course Map specific, e.g:
Map<K2,V> myMap = ...;
// K1 is the class for usual HZ keys, K2 is the class used for the keys of a value-map, V is the type used for values of a value-map
MapMap<K1, K2, V> mapMap = hzInstance.getMapMap(mapMapName);
// Add A->B to the map associated with key1
mapMap.put("key1", "A", "B");
// Remove an entry from a value-map
// Add a whole map in one go
// Get the (copy of) value-map. Direct changes on a value-map are not propagated!
// Always use MapMap operations to update value-maps.
Map<K2, V> value = mapMap.get("key1");
Similar to MultiMap, those updates operations could be optimized, i.e. HZ would not serialize the whole value-map on every update, but only changed entries.
What do think about it? Does it make sense?
How difficult would it be to implement such a data structure?
Is it correct to assume that it is very similar to MultiMaps and a lot of code can be reused? Or do you think it would require a very different implementation due to some subtle details?
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||5/7/12 3:02 AM|
Yes, we thought about it and it could be a good candidate to store session data in distributed fashion. And the updates would be very less costly. But I don't like the name MapMap. Can we have any better name?
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/7/12 3:38 AM|
Question: Is it already on the roadmap? If so, when is this feature planned?
If not, should I file an issue on github?
But I don't like the name MapMap. Can we have any better name?
Sure. I'm also not happy about the name ;-( I introduced MapMap just a temporary name and tried to follow the MultiMap naming convention. (actually, MultiMap would be a very nice name for MapMap, but it is used for lists already ;-)
And in Infinispan, they call a similar thing AtomicHashMap, but I'm not sure that it is much better and reflects the semantics.
So, may be something like ValueMap, because this map is a value in a distributed map? Later, if someone wants to introduce similar approach for e.g. sets and so on, one could use ValueSet, ValueList, ValueXYZ, etc. Anyway, I don't have any strong opinion about a name for such a thing. Suggestions are welcome!
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||peter veentjer||5/7/12 3:48 AM|
Although not spectacular, what about the ManyMap.
> --> https://groups.google.com/d/msg/hazelcast/-/1OUfRNkT1R4J.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Tim Peierls||5/7/12 4:30 AM|
Guava calls it Table.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/8/12 12:59 AM|
I created a new issue on github for this feature:
All name proposals suggested so far are listed there.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Nils Kilden-Pedersen||5/8/12 5:33 AM|
On Mon, May 7, 2012 at 11:02 AM, Fuad Malikov <fu...@hazelcast.com> wrote:Yes, we thought about it and it could be a good candidate to store session data in distributed fashion. And the updates would be very less costly. But I don't like the name MapMap. Can we have any better name?
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Hugo||5/8/12 6:46 AM|
On May 8, 2:33 pm, Nils Kilden-Pedersen <nil...@gmail.com> wrote:
> On Mon, May 7, 2012 at 11:02 AM, Fuad Malikov <f...@hazelcast.com> wrote:> >http://groups.google.com/group/hazelcast?hl=en.- Hide quoted text -
> - Show quoted text -
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||5/9/12 3:02 AM|
Answers are inlined:
On Mon, May 7, 2012 at 1:38 PM, mongonix <romi...@gmail.com> wrote:
Thanks for the issue. No ETA yet. In the past we had people from community with strong ninja skills that implemented Semaphore, CountdownLatch and etc:)
To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/1OUfRNkT1R4J.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||5/9/12 3:04 AM|
I started a poll on linkedin. It only allows 5 choices per poll and we had 8 choices right now. I had to start 2 polls with 4 choices on each. If you have some new ideas, add them as a comment.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||5/15/12 11:05 PM|
Based on the poll results, the winner is NestedMap. This was Nils's suggestion, thank you. There were some other suggestions like MultiKeyMap, which I couldn't include into poll. Is there any ninja coder volunteering for the development of NestedMap?:)
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/21/12 12:58 AM|
I could give it a try.
Could you give me some hints where to look at and roughly what pieces of the Hazelcast code-base (which classes, which commands, what should be extended, etc) should be touched when a new distributed data-structure like this is added to the library? This would help me to achieve the results faster, because I will spend less time on digging out this knowledge by analyzing Hazelcast's code.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||5/22/12 6:17 AM|
You basically should analyze MultiMap and you can start by looking at classes:
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/23/12 8:05 AM|
I started looking into the code to see what needs to be adapted and added. The initial analysis shows that handling of MultiMaps as it is implemented now is rather complex and spread over quite some places (including Record, transactions, requests, etc), touching a lot of rather sensitive places. There is a lot of places, where there is a hard-coded explicit check if current data structure is a MultiMap and a special logic to handle it. Plus, the code assumes that it know how MultiMaps are represented internally (e.g. sets or lists) and uses this knowledge (as opposed e.g. to treating MultiMaps as black-boxes and delegating all the logic to a small set of MultiMap specific classes). IMHO, based on my still rather limited knowledge of HZ codebase, the current implementation does not make it very easy to add a new data structure if it is different enough from existing ones in terms of APIs (e.g. each operation takes more than one key, etc).
With this in mind, I see the following potential approaches:
1) Copy/paste all MultiMap related code and introduce corresponding NestedMap related code. It will probably work, but will introduce a lot of very similar code.
In addition, I have to add at very many places methods with NestedMap suffix/prefix, as it is done for MultiMaps currently, and this will pollute the code even more. Many of those methods with NestedMap suffix would allow for (key1, key2, value) parameters, similar to the way how it is done for MultiMap with (key, value) parameters (e.g. MProxy should be extended and so on). So, it will work, but it will not look like a nice and easily maintainable code. It would also require quite some effort. And should one want to add a new data structure in the future, the situation may become even worse.
2) An alternative could be to treat in the most places in code the last two elements of the (K1, K2, V) tuple, i.e. (K2, V), as a compound-value and sort of a black-box, whose semantic is not known to majority of the code. Such a compound-value is treated almost as an atomic value and can be e.g. internally sent/received during get/put operations. In this sense, it is not different to the way how usual simple map values are treated by Hazelcast. Only the endpoints of the chain exchanging these atoms need to know how to interpret this value when trying to insert it into the map. I.e. instead of inserting it into the map in a usual way like it is done e.g. for integers, it would split it into K2 and V parts and insert it into the local value-map belonging to the key K1. When one needs to send (K1, K2, V) for a put operation, then the opposite will be done. (K2, V) will be combined into one new value NV, which will be serialized and a usual map update operation will be sent for key K1 and value NV. The other side will receive it in a usual way and only when it will be about to update the entry for K1, it will check that the target entry is not a usual value, but a Map and therefore NV needs to be split into parts and processed accordingly.
I think this approach may cover also other data structures and e.g. MultiMap can be expressed in its terms as well. More over, it would allow for many further custom data-structures that are also delta-aware similar to MultiMap and NestedMap.
I hope I managed to explain my ideas in more or less understandable way ;-) And I'm very eager to hear your opinions on these issues, before a lot of time is spent on either of the proposed solutions.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/24/12 4:24 AM|
To avoid pollution of this group with too many implementation details, I copied/moved the implementation discussion to the corresponding issue on GitHub:
Hope to see some responses soon, so that I can proceed with the implementation.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||5/29/12 1:38 AM|
Hi Talip, Hi Fuad,
Don't want to annoy you, but some feedback on this topic would be really nice. Without it I cannot proceed with the implementation. We need to decide which direction should be taken.
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||5/29/12 1:47 AM|
Sorry for that. Both of us are traveling. I just returned and will have a look at it.
Sent from Mobile
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||mongonix||6/26/12 1:31 AM|
The usual monthly ping :-)
Any hope to get an answer regarding how to proceed?
|Re: Idea about introducing MapMap (map of maps) similar to MultiMap||Fuad Malikov||6/30/12 12:31 AM|
I have replied at issue 147.
Co-founder & Managing Partner
Hazelcast | Open source in-memory data grid
Mobile: +90.538.378.9777 | @fuadm
To view this discussion on the web visit https://groups.google.com/d/msg/hazelcast/-/a_tAAyRqHSoJ.