Github user arunmahadevan commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1950#discussion_r109658382
  
    --- Diff: 
external/storm-redis/src/main/java/org/apache/storm/redis/state/RedisKeyValueState.java
 ---
    @@ -152,70 +170,72 @@ public V get(K key, V defaultValue) {
         @Override
         public V delete(K key) {
             LOG.debug("delete key '{}'", key);
    -        String redisKey = encoder.encodeKey(key);
    +        byte[] redisKey = encoder.encodeKey(key);
             V curr = get(key);
    -        pendingPrepare.put(redisKey, RedisEncoder.TOMBSTONE);
    +        pendingPrepare.put(new ByteArrayWrapper(redisKey), 
RedisEncoder.TOMBSTONE);
             return curr;
         }
     
         @Override
         public Iterator<Map.Entry<K, V>> iterator() {
    -        return new RedisKeyValueStateIterator<K, V>(namespace, 
jedisContainer, pendingPrepare.entrySet().iterator(), 
pendingCommit.entrySet().iterator(),
    +        return new RedisKeyValueStateIterator<K, V>(namespace, container, 
pendingPrepare.entrySet().iterator(), pendingCommit.entrySet().iterator(),
                     ITERATOR_CHUNK_SIZE, encoder.getKeySerializer(), 
encoder.getValueSerializer());
         }
     
         @Override
         public void prepareCommit(long txid) {
             LOG.debug("prepareCommit txid {}", txid);
             validatePrepareTxid(txid);
    -        JedisCommands commands = null;
    +        RedisCommands commands = null;
             try {
    -            Map<String, String> currentPending = pendingPrepare;
    -            pendingPrepare = new ConcurrentHashMap<>();
    -            commands = jedisContainer.getInstance();
    +            Map<ByteArrayWrapper, byte[]> currentPending = pendingPrepare;
    +            pendingPrepare = createPendingPrepareMap();
    +            commands = container.getInstance();
                 if (commands.exists(prepareNamespace)) {
                     LOG.debug("Prepared txn already exists, will merge", txid);
    -                for (Map.Entry<String, String> e: 
pendingCommit.entrySet()) {
    +                for (Map.Entry<ByteArrayWrapper, byte[]> e: 
pendingCommit.entrySet()) {
                         if (!currentPending.containsKey(e.getKey())) {
                             currentPending.put(e.getKey(), e.getValue());
                         }
                     }
                 }
                 if (!currentPending.isEmpty()) {
    -                commands.hmset(prepareNamespace, currentPending);
    +                commands.hmset(prepareNamespace, 
ByteArrayUtil.Maps.newHashMapUnwrappingKey(currentPending));
    --- End diff --
    
    maybe you can avoid the wrapping/unwrapping and extra copying if you use a 
TreeMap with a comparator that compares the byte array. (e.g. 
`ConcurrentSkipListMap<>(com.google.common.primitives.UnsignedBytes.lexicographicalComparator())`
 since we want concurrency).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to