vaseems / xmemcached

Automatically exported from code.google.com/p/xmemcached
Apache License 2.0
0 stars 0 forks source link

自定义KeyProvider带着incr方法死循环 #241

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
public long incr(String key, long delta, long initValue, long timeout,
            int exp) throws TimeoutException, InterruptedException,
            MemcachedException {
        key = this.preProcessKey(key);
        return this.sendIncrOrDecrCommand(key, delta, initValue,
                CommandType.INCR, false, timeout, exp);
    }

sendIncrOrDecrCommand方法
if (((String) result).equals("NOT_FOUND")) {
    if (this.add(key, exp, String.valueOf(initValue),this.opTimeout)) {
         return initValue;
    } else {
         return this.sendIncrOrDecrCommand(key, delta,initValue, cmdType, 
                      noreply, operationTimeout,exp);
    }
}

add方法;
key = this.preProcessKey(key);
byte[] keyBytes = this.checkStoreArguments(key, exp, value);
return this.sendStoreCommand(this.commandFactory.createAddCommand(key,
                keyBytes, exp, value, false, transcoder), timeout);

自定义的KeyProvider:
public String process(String key) {
    return "xmc_"+ key;
}

假如我们原始Key=abc,调用incr方法,首先调用KeyProvider的process��
�法把key变为了xmc_abc,然后调用sendIncrOrDecrCommand方法,如果这
时候memcached 
server返回NOT_FOUND,就会调用add方法,而add又会调用一次KeyProvi
der的process方法,这时候key变成了xmc_xmc_abc,这样就出问题了��
�下次再调用incr方法就会陷入死循环,报出stackOverflow异常。

Original issue reported on code.google.com by cray...@gmail.com on 10 Dec 2012 at 5:43

GoogleCodeExporter commented 9 years ago
我觉得不应该直接调用add方法,而应该调用更底层的方法:se
ndStoreCommand或再提供一个单独的方法

Original comment by cray...@gmail.com on 11 Dec 2012 at 1:31

GoogleCodeExporter commented 9 years ago
@cray424
是有这个问题,感谢报告,我在这周末的发布中会修复。

Original comment by killme2...@gmail.com on 11 Dec 2012 at 2:47

GoogleCodeExporter commented 9 years ago
修改该问题的版本发布了吗?

Original comment by cray...@gmail.com on 28 Dec 2012 at 11:54

GoogleCodeExporter commented 9 years ago
1.3.9发布,已修复。

Original comment by killme2...@gmail.com on 11 Jan 2013 at 11:46