Skip to content

RLocalCachedMap with RTransaction locks the Object  #4605

Open

Description

@shivangmittal01

As suggested by @mrniko in #4587 I am trying to use RTransactions to insert records in bulk in Redis. But the transaction seems to be locking the keys forever. Is this the right way to do it? I am not able to find the details around LocalCachedMapDisabledKey and need help in inserting millions of records in Redis with LocalCachedMap benefits. Getting this error when app starts: Failed to instantiate [com.apollopharmacy.inventorymanagementservice.repository.cache.InventoryCacheRepository]: Constructor threw exception; nested exception is java.lang.ClassCastException: class java.lang.String cannot be cast to class org.redisson.cache.LocalCachedMapDisabledKey (java.lang.String is in module java.base of loader 'bootstrap'; org.redisson.cache.LocalCachedMapDisabledKey is in unnamed module of loader 'app')

var codec = new TypedJsonJacksonCodec(String.class, ItemInventory.class, mapper);
inventoryCodec = new CompositeCodec(StringCodec.INSTANCE, codec);
pendingSyncCodec = new TypedJsonJacksonCodec(String.class, SyncPendingItem.class, mapper);

options = LocalCachedMapOptions.defaults()
                .cacheSize(1_00_000)
                .evictionPolicy(LocalCachedMapOptions.EvictionPolicy.LRU)
                .syncStrategy(LocalCachedMapOptions.SyncStrategy.UPDATE);

inventoryMap = redissonClient.getLocalCachedMap(REDIS_INVENTORY_MAP, inventoryCodec, options);

 RTransaction transaction = redissonClient.createTransaction(TransactionOptions.defaults().responseTimeout(10, TimeUnit.SECONDS));
  try {
            var itemInventoryRMap = transaction.getLocalCachedMap(inventoryRMap);
            myList.forEach(t -> itemInventoryRMap.fastPut(t.getKey(), t));
            transaction.commit();
   } catch (Exception e) {
            transaction.rollback();
        }

Is there an issue with inventoryCodec?
Screenshot 2022-10-17 at 8 08 01 PM

Activity

  1. shivangmittal01 commented on Oct 18, 2022

    @shivangmittal01
    Author

    @mrniko can we do the same with RlOcalCachedMap.putAll() ? will it load in bulk and also notify the other instances? Curious to know the difference between RBatch and putAll

  2. ofir-popowski commented on Jan 9, 2023

    @ofir-popowski

    I'm experiencing a similar issue.
    We have a requirement where we need to entirely reload 2 different RLocalCachedMap when we consume an event.
    pseudocode:

    val transaction = redissonClient.createTransaction(TransactionOptions.defaults())
    transaction.getLocalCachedMap(map1).clear()
    transaction.getLocalCachedMap(map1).putAll(valuesForMap1)
    
    transaction.getLocalCachedMap(map2).clear()
    transaction.getLocalCachedMap(map2).putAll(valuesForMap2)

    Upon commit, I'm then seeing logs like:

    Caused by: java.lang.ClassCastException: class org.redisson.transaction.operation.DeleteOperation cannot be cast to class org.redisson.transaction.operation.map.MapOperation (org.redisson.transaction.operation.DeleteOperation and org.redisson.transaction.operation.map.MapOperation are in unnamed module of loader 'app')
    

    Removing the transaction part results in 0 errors

  3. added this to the 3.19.2 milestone on Jan 10, 2023
  4. modified the milestones: 3.19.2, 3.19.3, 3.19.4 on Feb 2, 2023
  5. modified the milestones: 3.19.4, 3.20.1 on Mar 2, 2023
  6. modified the milestones: 3.20.1, 3.20.2 on Mar 28, 2023
  7. modified the milestones: 3.21.0, 3.21.1 on May 1, 2023
  8. modified the milestones: 3.21.1, 3.21.2 on May 12, 2023
  9. modified the milestones: 3.21.2, 3.12.x on May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions