Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalidateNamespace not work when sanitizeKeys is true #85

Closed
Boreas-y opened this issue Jul 3, 2018 · 2 comments
Closed

invalidateNamespace not work when sanitizeKeys is true #85

Boreas-y opened this issue Jul 3, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@Boreas-y
Copy link

Boreas-y commented Jul 3, 2018

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;
  }
@killme2008
Copy link
Owner

Thanks, it's a bug, i will fix it ASAP.

@killme2008
Copy link
Owner

Fixed in 2.4.5

https://github.com/killme2008/xmemcached/releases/tag/xmemcached-2.4.5

It may take some time to be synced into maven central repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants