2

In Hazelcast IMap when I delete a certain key and immediately add the same key with different data and then get that data in less than a second, Hazelcast IMap return old data.

For example

1) I am deleting a key with value {key : String, value : serialized object}

2) Now I add the value against the same key in less than a second with value {key : String, value : serialized object}

3) At this time I try to get the key get{key : String} which return the same value as in point 1.

To avoid this error(workaround), I have tried adding Thread.sleep(1000L). This seems to work but doesn't provide consistency.

Also used evict, remove methods for IMap. Nothing seems to work in this case.

Hazelcast.xml configuration is default config. At Client side hazelcastClient.xml is also with default config.

method api()
{
    if(userIsAlreadyLogin)
    {
        forcelogout()
    }

    handleValidUserlogin()
}

method forcelogout()
{
    removeUserDetails()
}

removeUserDetails()
{
    IMap.lock()
    IMap.delete(key : String, value : serialized object)
    IMap.unlock()
}

method handleValidUserlogin()
{
    IMap.get() //Printing values after deletion 
    IMap.put(key : String, value : serialized object)
    IMap.get()
}
Tatkal
  • 568
  • 4
  • 9
  • 29
  • Hi, I'm unable to reproduce this. Could please provide the reproducer? My code: ` IMap map = client.getMap("default"); String key = "person"; Person person = new Person("Jiri", 27); map.put(key, person); map.delete(key); Person person2 = new Person("Jaromir", 30); map.put(key, person2); System.out.println(map.get(key)); ` – jholusa Mar 27 '19 at 08:25
  • Do you have read-backup-data set to true? (This is not the default). If so, there will be a window of time between the time the entry is updated and the time the backup is written where clients reading from the backup could see stale data. (And setting read-backup-data to true indicates you're OK with this). – Mike Yawn Mar 27 '19 at 09:15
  • @MikeYawn where should I configure this read-backup-data....Client side or server side xml file? I found in server side xml file as backup-count....is this the same as you suggested? – Tatkal Mar 27 '19 at 09:22
  • read-backup-data would be configured on the server side, as an element within map config (along with backup-count and async-backup-count). I posted that comment without noticing you'd specifically said you had default config on the client and server side ... if you're using default then this doesn't explain your issue, and I'm trying to think of another scenario that might fit. – Mike Yawn Mar 27 '19 at 09:25
  • I have tried using config as you have suggested and sadly it doesn't work – Tatkal Mar 27 '19 at 09:40
  • @MikeYawn any more suggestions? – Tatkal Mar 27 '19 at 11:01
  • 1
    If you can create a small piece of example code that demonstrates the problem that's probably the only way we'll be able to diagnose, as it looks like @jholusa wasn't able to reproduce based on just the problem description. – Mike Yawn Mar 27 '19 at 13:52
  • Unable to reproduce. Do you have near cache enabled? Also, don't need to delete the key. just put the new key/val entry. – Abhishek Tyagi Mar 28 '19 at 07:42
  • @AbhishekTyagi I have added code snippet in my question and also tried as you suggested and it didn't work – Tatkal Mar 28 '19 at 08:55

0 Answers0