Amazon ElasticCache Autodiscovery - Client is not initialized
Asked Answered
G

3

7

I am trying to test Amazon's new Memcached client with AutoDiscovery. I have one memcached node which I am able to connect to using XMemcached 1.3.5 as well as a standard SpyMemcached library.

I am following the instructions here: http://docs.amazonwebservices.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html

The code is almost identical to the example and is:

String configEndpoint = "<server name>.rgcl8z.cfg.use1.cache.amazonaws.com";
Integer clusterPort = 11211;
MemcachedClient client = new MemcachedClient(new InetSocketAddress(configEndpoint, clusterPort));
client.set("theKey", 3600, "This is the data value");

I see the following in the logs when I create the connection. The error happens when I try to set a value:

2013-01-04 22:05:30.445 INFO net.spy.memcached.MemcachedConnection:  Added {QA sa=/<ip>:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2013-01-04 22:05:32.861 INFO net.spy.memcached.ConfigurationPoller:  Starting configuration poller.
2013-01-04 22:05:32.861 INFO net.spy.memcached.ConfigurationPoller:  Endpoint to use for configuration access in this poll NodeEndPoint - HostName:<our-server>.rgcl8z.cfg.use1.cache.amazonaws.com IpAddress:<ip> Port:11211
2013-01-04 22:05:32.950 WARN net.spy.memcached.MemcachedClient:  Configuration endpoint timed out for config call. Leaving the initialization work to configuration poller.
Exception in thread "main" java.lang.IllegalStateException: Client is not initialized
at net.spy.memcached.MemcachedClient.checkState(MemcachedClient.java:1623)
at net.spy.memcached.MemcachedClient.enqueueOperation(MemcachedClient.java:1617)
at net.spy.memcached.MemcachedClient.asyncStore(MemcachedClient.java:474)
at net.spy.memcached.MemcachedClient.set(MemcachedClient.java:905)
at com.thinknear.venice.initializers.VeniceAssets.main(VeniceAssets.java:227)
  • I've tried this both locally and on a EC2 instance (I can connect using other libraries to the nodes)
  • I've tried using both 1.4.5 and 1.4.14 Memcached engines
  • I relaxed the security group constraints as well just in case

Any thoughts on why the config endpoint would be timing out?

Grillwork answered 5/1, 2013 at 6:9 Comment(4)
I found the solution to my own problem. Looks like my security groups were not setup correctly. Once I fixed my security groups and deployed my code to our EC2 instance it was able to connect.Grillwork
Could you please add as how did you fix your security group. i am facing same issue and i am new to amazon services. ThanksFrameup
@Frameup I am also facing the same issue and would be interested in how you fixed your security group. I have tried opening them to the world but it still doesn't workFortuitous
Unfortunately, I can't quite remember and I left the company where I made the change. I would check to see if the outbound ports are opened up on the EC2 machine security group and that the inbound ports on the elastic cache security group are opened up.Grillwork
T
9

Client is not initialised: You can not directly connect to amazon elastic cache node through your local machine you can only access it through your ec2 machiene.If you want to check you can telnet from your local machine it will not connect I also suufered from the same problem .You can telnet it from your Ec2 machine.so try your code at ec2 machine it will work.

Turk answered 17/1, 2013 at 7:17 Comment(1)
I am using spymemcache which is local so my code should execute without this exception as on local my code can access memcache.Sorcery
S
0

Do telnet on memcache server to check connectivity ,in mine case it was not listed so was not able to made connection , problem solved by listing my server to memcache.

Selina answered 26/7, 2013 at 5:39 Comment(0)
P
0

The Client is not initialized error indicates that you cannot connect to your ElastiCache Memcached cluster. The 2 scenarios you might fall into are:

  1. You can't connect from your EC2 instance
  2. You can't connect from your local machine

Case 1 - EC2 instance

This will mean that your security groups won't be set up properly. Find your ElastiCache cluster, click on Network and Security, then on a security group, and then try adding a new (very open, initially) Inbound rule. Then follow Testing Memcached with telnet (below), and gradually narrow your Inbound rule.

Case 2 - Local machine

By default, ElastiCache clusters can only be connected to from other AWS resources. You can either open up your security groups to allow public access (not ideal, but possible for fixed IPs). Or you can simply run an SSH port forwarding command, and connect via your EC2 instance. E.g:

ssh -A -N -L 11211:<your memcached cluster/node endpoint>:11211 <your EC2 instance that you use to connect to memcached>

e.g:

ssh -A -N -L 11211:my-dev-cache.eublah.cfg.use1.cache.amazonaws.com:11211 10.190.10.10

and then follow Testing Memcached with telnet (below) to test it.

Testing Memcached with telnet

Install telnet, and then follow these instructions to test your connection to your memcached cluster: https://aws.amazon.com/premiumsupport/knowledge-center/elasticache-connection-test/.

E.g:

telnet 127.0.0.1 11211 # where 127.0.0.1 is the host/EC2 instance you want to connect to
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set a 0 0 5
hello
STORED
get a
VALUE a 0 5
hello
END
quit
Connection closed by foreign host.

If you can't get a connection, then it will never say Connected to <hostname>.

Platelet answered 21/3, 2023 at 7:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.