-
Notifications
You must be signed in to change notification settings - Fork 280
Closed
Description
XMemcachedClient.invalidateNamespace(String) not work if XMemcachedClient.sanitizeKeys=true.
The reason is, namespace will be encoded when invalidating while it will not be encoded when getting.
public void invalidateNamespace(String ns, long opTimeout)
throws MemcachedException, InterruptedException, TimeoutException {
String key = this.getNSKey(ns);
this.incr(key, 1, System.currentTimeMillis(), opTimeout); // this method calls preProcessKey, which encodes ns
}
...
private <T> Object get0(String key, final long timeout, final CommandType cmdType,
final Transcoder<T> transcoder)
throws TimeoutException, InterruptedException, MemcachedException {
key = this.preProcessKey(key); // calls getNamespace
byte[] keyBytes = ByteUtils.getBytes(key);
ByteUtils.checkKey(keyBytes);
return this.fetch0(key, keyBytes, cmdType, timeout, transcoder);
}
...
public String getNamespace(String ns)
throws TimeoutException, InterruptedException, MemcachedException {
String key = this.keyProvider.process(this.getNSKey(ns));
byte[] keyBytes = ByteUtils.getBytes(key);
ByteUtils.checkKey(keyBytes);
Object item = this.fetch0(key, keyBytes, CommandType.GET_ONE, this.opTimeout, this.transcoder); // get namespace without encoding
while (item == null) {
item = String.valueOf(System.nanoTime());
boolean added = this.add0(key, 0, item, this.transcoder, this.opTimeout);
if (!added) {
item = this.fetch0(key, keyBytes, CommandType.GET_ONE, this.opTimeout, this.transcoder);
}
}
String namespace = item.toString();
if (!ByteUtils.isNumber(namespace)) {
throw new IllegalStateException(
"Namespace key already has value.The key is:" + key + ",and the value is:" + namespace);
}
return namespace;
}