killme2008 / killme2008/xmemcached

when one memcached node Dns Change to new IP then the HashAlgorithm.KETAMA_HASH always use the old IP to calc getSessionByKey

Open
#121 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
764
Forks
271
PR merge metrics
No merged PRs in 30d

Description

Hi,author:
in my case ,i use KetamaMemcachedSessionLocator init MemcacheClient code like:
` MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(hostList));
builder.setFailureMode(false);
builder.setSessionLocator(new KetamaMemcachedSessionLocator());
`
the hostList use domain,like this: host1.test.com:11211 host2:test.com:11211 host3.test.com:11211,and the dns like:
192.168.1.11 host1.test.com
192.168.1.12 host2.test.com
192.168.1.13 host4.test.com

when the host2.test.com(192.168.1.12) was down,i use another ip to host2.test.com like
192.168.1.14 host2.test.com

xmemcached can auto connnect to the new ip,and update InetSocketAddressWrapper.inetSocketAddress but it does not refresh InetSocketAddressWrapper.remoteAddressStr,code in :
`// updated resolve addr
addrWrapper.setResolvedSocketAddress(remoteSocketAddress);
`
if we have more than one client , and some nodes has restart and use the new IP init ,then the same key come from diff client has diffrent hash key,this is not we want it.

Maybe you would suggest use gwhalinMemcachedJavaClientCompatibiltyConsistent = true to solve this problem code like this:
`
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(hostList));
//when fail ,fast remove unable node
builder.setFailureMode(false);
// Using consistent hash algorithm
builder.setSessionLocator(new KetamaMemcachedSessionLocator(HashAlgorithm.KETAMA_HASH,false,true));
`
but we must think that : on line product environment,the memcached distribute node has all init data and only small amount request will miss and load from db,if we change the init hash algorithm,we must rebuild the data.

so the best way to solve this case,use can fix the code like this: MemcachedConnector.addMainSession
` // updated resolve addr
addrWrapper.setResolvedSocketAddress(remoteSocketAddress);
// fix when same dns name point to diff ip
addrWrapper.setRemoteAddressStr(String.valueOf(remoteSocketAddress));`
this like add a new memcached node ,and the behavior of reconnect and restart is consistent

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in MemcachedConnector.addMainSession and inspect how InetSocketAddressWrapper updates resolvedSocketAddress and remoteAddressStr during DNS reconnects. Confirm that the hostname's new resolved address is reflected consistently in KetamaMemcachedSessionLocator hashing, including the multi-client scenario described.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, memcached
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.