Skip to content

Commit 2f689e3

Browse files
authored
Merge pull request #97 from Netflix/feature/base85
Fixed a bug with hashedkey where we were dueting it by default.
2 parents 26109f3 + b6f86e1 commit 2f689e3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

evcache-core/src/main/java/com/netflix/evcache/EVCacheKey.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package com.netflix.evcache;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
39
import com.netflix.archaius.api.Property;
410
import com.netflix.evcache.util.KeyHasher;
511
import com.netflix.evcache.util.KeyHasher.HashingAlgorithm;
6-
import java.util.HashMap;
7-
import java.util.Map;
812

913
public class EVCacheKey {
14+
private static final Logger log = LoggerFactory.getLogger(EVCacheKey.class);
1015
private final String appName;
1116
private final HashingAlgorithm hashingAlgorithmAtAppLevel;
1217
private final Property<Boolean> shouldEncodeHashKeyAtAppLevel;
@@ -58,6 +63,7 @@ private String getCanonicalKeyForDuet() {
5863
if (null == canonicalKeyForDuet) {
5964
final int duetKeyLength = appName.length() + 1 + canonicalKey.length();
6065
canonicalKeyForDuet = new StringBuilder(duetKeyLength).append(appName).append(':').append(canonicalKey).toString();
66+
if (log.isDebugEnabled()) log.debug("canonicalKeyForDuet : " + canonicalKeyForDuet);
6167
}
6268

6369
return canonicalKeyForDuet;
@@ -94,7 +100,9 @@ public String getHashKey(boolean isDuet, HashingAlgorithm hashingAlgorithm, Bool
94100
baseEnoder = encoder;
95101
}
96102

97-
return isDuet ? getHashKeyForDuet(hashingAlgorithm, shouldEncodeHashKey, maxDigestBytes, maxHashLength, baseEnoder) : getHashKey(hashingAlgorithm, shouldEncodeHashKey, maxDigestBytes, maxHashLength, baseEnoder);
103+
final String rKey = isDuet ? getHashKeyForDuet(hashingAlgorithm, shouldEncodeHashKey, maxDigestBytes, maxHashLength, baseEnoder) : getHashKey(hashingAlgorithm, shouldEncodeHashKey, maxDigestBytes, maxHashLength, baseEnoder);
104+
if (log.isDebugEnabled()) log.debug("Key : " + rKey);
105+
return rKey;
98106
}
99107

100108
// overlays app level hashing algorithm and client level hashing algorithm
@@ -104,7 +112,9 @@ public String getDerivedKey(boolean isDuet, HashingAlgorithm hashingAlgorithm, B
104112
hashingAlgorithm = hashingAlgorithmAtAppLevel;
105113
}
106114

107-
return null == hashingAlgorithm || hashingAlgorithm == HashingAlgorithm.NO_HASHING ? getCanonicalKey(isDuet) : getHashKey(isDuet, hashingAlgorithm, shouldEncodeHashKey, maxDigestBytes, maxHashLength, baseEnoder);
115+
final String derivedKey = null == hashingAlgorithm || hashingAlgorithm == HashingAlgorithm.NO_HASHING ? getCanonicalKey(isDuet) : getHashKey(isDuet, hashingAlgorithm, shouldEncodeHashKey, maxDigestBytes, maxHashLength, baseEnoder);
116+
if (log.isDebugEnabled()) log.debug("derivedKey : " + derivedKey);
117+
return derivedKey;
108118
}
109119

110120
private String getHashKey(HashingAlgorithm hashingAlgorithm, Boolean shouldEncodeHashKey, Integer maxDigestBytes, Integer maxHashLength, String encoder) {
@@ -115,9 +125,10 @@ private String getHashKey(HashingAlgorithm hashingAlgorithm, Boolean shouldEncod
115125
final String key = hashingAlgorithm.toString()+ maxDigestBytes != null ? maxDigestBytes.toString() : "-" + maxHashLength != null ? maxHashLength.toString() : "-" + encoder != null ? encoder : "-";
116126
String val = hashedKeysByAlgorithm.get(key);
117127
if(val == null) {
118-
val = KeyHasher.getHashedKeyEncoded(getCanonicalKeyForDuet(), hashingAlgorithm, maxDigestBytes, maxHashLength, encoder);
128+
val = KeyHasher.getHashedKeyEncoded(getCanonicalKey(false), hashingAlgorithm, maxDigestBytes, maxHashLength, encoder);
119129
hashedKeysByAlgorithm.put(key , val);
120130
}
131+
if (log.isDebugEnabled()) log.debug("getHashKey : " + val);
121132
// TODO: Once the issue around passing hashedKey in bytes[] is figured, we will start using (nullable) shouldEncodeHashKey, and call KeyHasher.getHashedKeyInBytes() accordingly
122133
return val;
123134
}
@@ -133,6 +144,7 @@ private String getHashKeyForDuet(HashingAlgorithm hashingAlgorithm, Boolean shou
133144
val = KeyHasher.getHashedKeyEncoded(getCanonicalKeyForDuet(), hashingAlgorithm, maxDigestBytes, maxHashLength, encoder);
134145
hashedKeysByAlgorithmForDuet.put(key , val);
135146
}
147+
if (log.isDebugEnabled()) log.debug("getHashKeyForDuet : " + val);
136148
// TODO: Once the issue around passing hashedKey in bytes[] is figured, we will start using (nullable) shouldEncodeHashKey, and call KeyHasher.getHashedKeyInBytes() accordingly
137149
return val;
138150
}

0 commit comments

Comments
 (0)