I've been trying to play with Elasticsearch as a drop in replacement for Memcached. I've installed the memcached transport and it looks like it started fine and is on the right port. However if I attempt to use the java spy.memcahed client library I'm not able to cache things.
Instead I get errors like:
2014-10-01 08:22:31.579 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-10-01 08:22:31.586 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@76fb509a
2014-10-01 08:22:31.679 INFO net.spy.memcached.MemcachedConnection: Reconnecting due to exception on {QA sa=localhost/127.0.0.1:11211, #Rops=2, #Wops=0, #iq=0, topRop=Cmd: 2 Opaque: 2 Key: foo Cas: 0 Exp: 1000 Flags: 0 Data Length: 3, topWop=null, toWrite=0, interested=1}
java.io.IOException: Disconnected unexpected, will reconnect.
over and over.
On the Elasticsearch side I get an error of
[2014-10-01 08:22:31,675][ERROR][memcached.netty ] [Living Hulk] Unsupported opcode [0x2], ignoring and closing connection
Here is my client configuration:
ConnectionFactoryBuilder factory = new ConnectionFactoryBuilder();
factory.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY);
SerializingTranscoder t = new SerializingTranscoder(1000000);
t.setCompressionThreshold(1024);
factory.setTranscoder(t);
factory.setOpTimeout(1000);
factory.setTimeoutExceptionThreshold(1998);
factory.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH);
factory.setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT);
factory.setFailureMode(FailureMode.Redistribute);
factory.setUseNagleAlgorithm(false);
It turns out this error was because I was calling "ADD" (0x2) on the client. The transport doesn't currently support ADD. There is a issue on GitHub for it: https://github.com/elasticsearch/elasticsearch-transport-memcached/issues/7
Note that switching to SET fixes this particular problem but there are other issues on GET that spy.memcache has issues with.