Github user HeartSaVioR commented on a diff in the pull request:
https://github.com/apache/storm/pull/1950#discussion_r109814880
--- 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 --
Great suggestion. I thought it is bad but didn't know about alternatives.
I'll try to replace that one.
---
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.
---