1

Background

I am new to Hazelcast. I'm currently working on an internal tool that uses Hazelcast to cache our data.

Problem

The HazelCast IMap has a String key & HashMap<K, V> value.

We are having an issue with this tool, where inputting an updated HashMap object with put() into the IMap does not update the HashMap object, refer to sample code below. The V in HashMap<K, V> is what gets updated.

Code Structure

In our main code, we have the following:

main() {
    updateTableStatus(...);
    // other business logic 
    updateTableStatus(...);
}

The updateTableStatus code updates the IMap:

updateTableStatus(...) {
    hazelcastInstance.getMap("String").put(K, V);
}

After running the app in debug mode, it seems that the first updateTableStatus does not update the HashMap object, only the second updateTableStatus.

The tool is a SpringBoot application, where the HazelcastInstance object is defined as follows:

@Autowired
HazelcastInstance hazelcastInstance;

I understand that objects saved to the Hazelcast IMap need to be serializable, but it seems that Hazelcast already has optimized the serialization for HashMap objects as per link.

My Research/Effort To Debug The Problem

I'm not quite sure what other avenues to explore with regards to updating objects in a Hazelcast IMap, these were the StackOverflow articles I referred to:

I think Article #3 is the closest to what I'm asking, but his post had no answers, so I'm not sure how else to proceed.

If there is any other missing pieces of information I could provide about the project / Hazelcast setup, please let me know! I'm still new & learning :)

I appreciate any responses & other people's understanding :)

waffledood
  • 193
  • 8
  • 1
    i couldn't get the point. maybe there is some typo, I think you may add a listener to Imap and see really updated or not. For each operation, (add/update/delete/etc) listener is triggered and can see old/new data. – newuserua_ext Dec 06 '22 at 07:07
  • @newuserua_ext hey, i insert updated `HashMap` objects into `IMap` with `put()` & retrieve them later, but based on the debug output, the `HashMap` objects in `IMap` didn't actually get updated – waffledood Dec 06 '22 at 07:11
  • 1
    What is the configuration of hazelcast? Are you using client side caching? – Gurkan İlleez Dec 06 '22 at 07:53
  • @waffledood, let's also try `map.replace` method and see is there any change on map value. – newuserua_ext Dec 06 '22 at 08:04
  • @Gurkanİlleez hey, i pasted the configuration [here](https://textdoc.co/IwUx56QVXFWCrNPi), but doesn't seem like there's client-side caching, perhaps i'm wrong (edit -- my vpn doesn't allow me to access text-sharing sites, will get back to you) – waffledood Dec 06 '22 at 08:13
  • @newuserua_ext hey `map.replace()` doesn't work. if i insert the same `HashMap` object (after modifying it) into `IMap`, it gets saved to the Hazelcast cache, but if i insert a new `HashMap` object into `IMap`, it doesn't get saved. any idea why? bpth of the `HashMap` objects were inserted into the same key – waffledood Dec 06 '22 at 08:22
  • 1
    +1 to the Map Listener suggestion. What's also worth trying is making the value an integer/string/long, as this'll help confirm if the problem is with updates or with updates to a collection. If still stuck, the Hazelcast Community Slack channel might get you more interactive help – Neil Stevenson Dec 06 '22 at 08:29
  • hi all, just wanted to update that i think i've found a solution, we were using the `HashMap` initially retrieved from `IMap` at the start of the application's run, instead of actively retrieving `HashMap` from `IMap`. hence we were referring to a `HashMap` that was never getting updated – waffledood Dec 06 '22 at 10:03

0 Answers0