Hi,
I’m trying to understand how the resolution of the right node happens when you specify the cname for the cluster.
PresenceCache getPresenceCache(CacheConfig config)
{
List<InetSocketAddress> servers = "abc.4yrs7l.cfg.use1.cache.amazonaws.com:11211";
try {
return new MemcachedPresenceCache(new MemcachedClient(servers));
}
catch (IOException e) {
throw Throwables.propagate(e);
}
}
So in the above code, given the cname, I want to know how the key decides to go to a particular node. This cname has 2 nodes in it. I tried debugging, so every time you start a service, one of the node IP address is returned. Here the nodes.length is 1 and not 2. Hence I’m thinking may be the keys are written to whatever IP address the code resolves to when the application starts and then it tries reading and writing from the same node, instead of resolving to the actual node where the key lies.
private int getServerForKey(String key) {
int rv = (int) (hashAlg.hash(key) % nodes.length);
assert rv >= 0 : "Returned negative key for key " + key;
assert rv < nodes.length : "Invalid server number " + rv + " for key "
+ key;
return rv;
}
Here, it says that using the right library for java which spymemcached here, the auto discovery is already enabled. https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/AutoDiscovery.Using.ModifyApp.Java.html
But as per the above code, it everytime goes to the same node which the DNS resolves the CNAME to, when the service starts.
I’m using this dependency.
spy
spymemcached
2.8.1
Kindly help me in understanding this.
Thanks in advance.