我在从EC2实例获取/设置ElastiCache群集时遇到问题。我越来越 - SEVERE: net.spy.memcached.OperationTimeoutException: Timeout waiting for value
- 错误。无法连接到AWS ElastiCache群集使用Membase客户端lib进行memcached
当我试图获得或设置一个值。我在本地机器上使用了相同的代码(尽管与本地memcached服务器通信),一切正常。完整的堆栈跟踪可以在这里找到 - http://pastebin.com/tYcCJ6cj
我第一次看到,我可以至少得到一个集群中的所有节点的IP地址,以便我可以养活它在我的Membase的客户&我确实能够找到出节点的IP地址。 我还确保将所有EC2安全组都添加到默认缓存群集安全组中。
任何指针都会很有帮助。
UPDATE
的代码片段用来获取特定的记录。
public String getCachedValue(String namespace, String key) {
String value = null;
try {
MemcachedClient client
= CacheConnectionUtil.connectToElastiCacheMemcachedServer();
// Point of origin for the exception.
return (String) client.get(namespace + "$" + hashKey(key));
} catch (IOException e) {
e.printStackTrace();
}
return value;
}
代码片段用于连接到ElastiCache服务器
private static MemcachedClient connectToElastiCacheMemcachedServer()
throws IOException {
DescribeCacheClustersResult cacheClustersInfo = null;
DescribeCacheClustersRequest cacheClusterRequest
= new DescribeCacheClustersRequest();
cacheClusterRequest.setShowCacheNodeInfo(true);
try {
cacheClustersInfo = AWSConnectionUtil
.getElastiCacheObject(null)
.describeCacheClusters(cacheClusterRequest);
} catch (Exception e) {
e.printStackTrace();
throw new IOException("Unable to connect to ElastiCache Cluster.", e);
}
if (cacheClustersInfo == null) {
throw new IOException("ElastiCache Cluster Info Object is null.");
}
List<CacheCluster> clusters = cacheClustersInfo.getCacheClusters();
if (clusters == null || clusters.isEmpty()) {
throw new IOException("No ElastiCache Clusters available.");
}
List<String> serverList = new ArrayList<String>();
for (CacheCluster cluster : clusters) {
if (cluster != null
&& AWSConstants
.CACHE_CLUSTER_ID
.equalsIgnoreCase(cluster.getCacheClusterId())) {
List<CacheNode> nodes = cluster.getCacheNodes();
if (nodes != null) {
for (CacheNode node : nodes) {
if (node != null) {
Endpoint endpoint = node.getEndpoint();
if (endpoint != null
&& endpoint.getAddress() != null) {
serverList.add(endpoint.getAddress()
+ ":"
+ endpoint.getPort());
}
}
}
}
}
}
if (serverList.isEmpty()) {
throw new IOException("No Cached nodes available for cluster - "
+ AWSConstants.CACHE_CLUSTER_ID);
}
return new MemcachedClient(AddrUtil.getAddresses(serverList));
}
你可以发布你的代码吗?没有看到你在做什么,就无法诊断这个问题。堆栈跟踪只是说操作需要很长时间才能完成。 – mikewied
@mikewied请参阅具有代码段的更新问题。谢谢。 – Chantz
你的代码显示正确,没有任何东西会跳出来。我只是再次检查地址/端口组合是否正确。如果是,则尝试从该代码运行的同一位置远程登录到群集中的某台机器,然后检查是否可以执行get操作。 – mikewied