“client not initialized” error when using SSMCache with AWS elasticache autodiscovery

777 views
Skip to first unread message

Maanasa Srinivasulu

unread,
Jun 15, 2015, 2:09:49 AM6/15/15
to simple-sprin...@googlegroups.com

When I use spring-cache with aws elasticache, I get this error -

WARN  c.g.code.ssm.spring.SSMCache - An error has ocurred for cache defaultCache and key module#1_8250
java
.lang.IllegalStateException: Client is not initialized
        at net
.spy.memcached.MemcachedClient.checkState(MemcachedClient.java:1623) ~[elasticache-java-cluster-client.jar:na]
        at net
.spy.memcached.MemcachedClient.enqueueOperation(MemcachedClient.java:1617) ~[elasticache-java-cluster-client.jar:na]
        at net
.spy.memcached.MemcachedClient.asyncStore(MemcachedClient.java:474) ~[elasticache-java-cluster-client.jar:na]
        at net
.spy.memcached.MemcachedClient.set(MemcachedClient.java:905) ~[elasticache-java-cluster-client.jar:na]
        at net
.spy.memcached.MemcachedClient.set(MemcachedClient.java:161) ~[elasticache-java-cluster-client.jar:na]
        at com
.google.code.ssm.providers.elasticache.MemcacheClientWrapper.set(MemcacheClientWrapper.java:274) ~[aws-elasticache-provider.jar:na]
        at com
.google.code.ssm.CacheImpl.set(CacheImpl.java:285) ~[simple-spring-memcached.jar:na]
        at com
.google.code.ssm.CacheImpl.set(CacheImpl.java:128) ~[simple-spring-memcached.jar:na]
        at com
.google.code.ssm.spring.SSMCache.put(SSMCache.java:159) ~[spring-cache.jar:na]


My config is as follows-

<bean name="cacheManager" class="com.google.code.ssm.spring.SSMCacheManager">
       
<property name="caches">
               
<set>
                       
<bean class="com.google.code.ssm.spring.SSMCache">
                               
<constructor-arg name="cache" index="0" ref="defaultMemcachedClient" />
                               
<!-- 5 minutes -->
                               
<constructor-arg name="expiration" index="1" value="3600" />
                               
<!-- @CacheEvict(..., "allEntries" = true) won't work because allowClear is false,
                                so we won't flush accidentally all entries from memcached instance -->

                               
<constructor-arg name="allowClear" index="2" value="false" />
                       
</bean>
               
</set>
       
</property>
       
</bean>
       
       
<bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
               
<property name="cacheName" value="defaultCache" />
       
<property name="cacheClientFactory">
               
<bean name="cacheClientFactory" class="com.google.code.ssm.providers.elasticache.MemcacheClientFactoryImpl" />
       
</property>
               
<property name="addressProvider">
               
<bean class="com.google.code.ssm.config.DefaultAddressProvider">
                       
<property name="address" value="127.0.0.1:11211" />
               
</bean>
       
</property>
       
<property name="configuration">
               
<bean class="com.google.code.ssm.providers.elasticache.ElastiCacheConfiguration">
                       
<property name="consistentHashing" value="true" />
                       
<property name="clientMode" value="#{T(net.spy.memcached.ClientMode).Dynamic}" />
               
</bean>
       
</property>
       
</bean>


The same config is working when I access memcache directly (using get and set methods). It just does not work for spring-cache (@Cacheable) annotations.


NOTE: the DefaultAddressProvider here is just a fallback. I have a bean defined in java code which uses the config file for autodiscovery. 


My usage is :

@Cacheable(
      value = "defaultCache",
      key = "#accountIdStr  +  #allArgs  + #id")
  public @ResponseBody Object getDataFor(final HttpServletRequest request, final HttpServletResponse response,
      @PathVariable(URLConstants.ACCOUNT_ID_STR) final String accountIdStr, final @CustomArgumentAnnotation CustomArgument allArgs,
      final @RequestParam(value = URLConstants.QueryParams.ID_STR, required = true, defaultValue = "1") String id)
  { }



I have ensured that the security group has the memcache port specified in Inbound and I am running my code in EC2. 








Jakub Białek

unread,
Jun 15, 2015, 2:44:50 AM6/15/15
to simple-sprin...@googlegroups.com
The error is not related to SSM but means that MemcachedClient from elasticache-java-cluster-client is not initialized. You can examine source code to check possible reasons: http://grepcode.com/file/repo1.maven.org/maven2/com.amazonaws/elasticache-java-cluster-client/1.0.61.0/net/spy/memcached/MemcachedClient.java#MemcachedClient.0isConfigurationInitialized

Check your logs for earlier errors/warns. Maybe there's a timeout when fetching config from server: "Configuration endpoint timed out for config call. Leaving the initialization work to configuration poller.".

-- Ragnor


--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-meme...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

Maanasa Srinivasulu

unread,
Jun 15, 2015, 3:00:31 AM6/15/15
to simple-sprin...@googlegroups.com
I do not see this message in the logs. As I mentioned earlier parallely I am able to access the memcache directly (using get and set methods). I hope there is no correlation here - using annotations and direct access. 
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.

Jakub Białek

unread,
Jun 15, 2015, 3:04:39 AM6/15/15
to simple-sprin...@googlegroups.com
How exactly do you access the memcached directly? A code snippet will be useful.

-- Ragnor

To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-meme...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-meme...@googlegroups.com.

Maanasa Srinivasulu

unread,
Jun 15, 2015, 3:11:30 AM6/15/15
to simple-sprin...@googlegroups.com
code snippet where memcache is accessed directly.  
//setup memcache
final MemcachedClient
memcache = new MemcachedClient(new InetSocketAddress(memcacheClusterEndPoint, memcacheClusterPort));

//get from memcache

final Future<Object> f = memcache.asyncGet(userId);

//set to memcache
memcache
.set(userId, 3600, newMemObj); //where newMemObj is of type MemcacheNotificationObject


Here I am able to successfully use memcache. However in another package when I try using @Cacheable , I get the not initialized error
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.

Jakub Białek

unread,
Jun 15, 2015, 3:14:52 AM6/15/15
to simple-sprin...@googlegroups.com
Are you sure that for SSM configuration the same memcacheClusterEndPoint and memcacheClusterPort are used like for direct access? Try to use them also in XML configuration for DefaultAddressProvider.

-- Ragnor

To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-meme...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-meme...@googlegroups.com.

To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-meme...@googlegroups.com.

Maanasa Srinivasulu

unread,
Jun 15, 2015, 4:26:10 AM6/15/15
to simple-sprin...@googlegroups.com
Seems like this is the issue. Will look into it. Thank you so much
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.

To post to this group, send email to simple-sprin...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-spring-memecached.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "simple-spring-memecached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-spring-memecached+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages