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

    https://github.com/apache/storm/pull/1950#discussion_r124186673
  
    --- Diff: 
external/storm-redis/src/main/java/org/apache/storm/redis/state/RedisKeyValueState.java
 ---
    @@ -64,75 +75,83 @@ public RedisKeyValueState(String namespace, 
JedisPoolConfig poolConfig) {
         }
     
         public RedisKeyValueState(String namespace, JedisPoolConfig 
poolConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
    -        this(namespace, JedisCommandsContainerBuilder.build(poolConfig), 
keySerializer, valueSerializer);
    +        this(namespace, RedisCommandsContainerBuilder.build(poolConfig), 
keySerializer, valueSerializer);
         }
     
    -    public RedisKeyValueState(String namespace, 
JedisCommandsInstanceContainer jedisContainer,
    +    public RedisKeyValueState(String namespace, JedisClusterConfig 
jedisClusterConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer) 
{
    +        this(namespace, 
RedisCommandsContainerBuilder.build(jedisClusterConfig), keySerializer, 
valueSerializer);
    +    }
    +
    +    public RedisKeyValueState(String namespace, 
RedisCommandsInstanceContainer container,
                                   Serializer<K> keySerializer, Serializer<V> 
valueSerializer) {
    -        this.namespace = namespace;
    -        this.prepareNamespace = namespace + "$prepare";
    +        this.namespace = SafeEncoder.encode(namespace);
    +        this.prepareNamespace = SafeEncoder.encode(namespace + "$prepare");
             this.txidNamespace = namespace + "$txid";
    -        this.encoder = new RedisEncoder<K, V>(keySerializer, 
valueSerializer);
    -        this.jedisContainer = jedisContainer;
    -        this.pendingPrepare = new ConcurrentHashMap<>();
    +        this.encoder = new DefaultStateEncoder<K, V>(keySerializer, 
valueSerializer);
    +        this.container = container;
    +        this.pendingPrepare = createPendingPrepareMap();
             initTxids();
             initPendingCommit();
         }
     
         private void initTxids() {
    -        JedisCommands commands = null;
    +        RedisCommands commands = null;
             try {
    -            commands = jedisContainer.getInstance();
    +            commands = container.getInstance();
                 if (commands.exists(txidNamespace)) {
                     txIds = commands.hgetAll(txidNamespace);
                 } else {
                     txIds = new HashMap<>();
                 }
                 LOG.debug("initTxids, txIds {}", txIds);
             } finally {
    -            jedisContainer.returnInstance(commands);
    +            container.returnInstance(commands);
             }
         }
     
         private void initPendingCommit() {
    -        JedisCommands commands = null;
    +        RedisCommands commands = null;
             try {
    -            commands = jedisContainer.getInstance();
    +            commands = container.getInstance();
                 if (commands.exists(prepareNamespace)) {
                     LOG.debug("Loading previously prepared commit from {}", 
prepareNamespace);
    -                pendingCommit = 
Collections.unmodifiableMap(commands.hgetAll(prepareNamespace));
    +                NavigableMap<byte[], byte[]> pendingCommitMap = 
createPendingCommitMap();
    +                
pendingCommitMap.putAll(commands.hgetAll(prepareNamespace));
    +                pendingCommit = 
Maps.unmodifiableNavigableMap(pendingCommitMap);
                 } else {
                     LOG.debug("No previously prepared commits.");
    -                pendingCommit = Collections.emptyMap();
    +                pendingCommit = createPendingCommitMap();
    --- End diff --
    
    Good point. Will address. Btw I'll try to avoid JDK 8 thing right now 
unless it is only applied to the master branch.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to