EC2 インスタンスから ElastiCache クラスターへの get/set に問題があります。--SEVERE: net.spy.memcached.OperationTimeoutException: Timeout waiting for value
エラーが発生しています。
値を取得または設定しようとしているとき。ローカル マシンで同じコードを使用しましたが (ローカルの memcached サーバーと通信していますが)、すべて正常に動作します。完全なスタックトレースはここにあります - http://pastebin.com/tYcCJ6cj
私は最初に、少なくともクラスタのすべてのノードの IP アドレスを取得して、それを membase クライアントにフィードできることを確認しました。実際にノードの IP アドレスを見つけることができます。また、すべての EC2 セキュリティ グループがデフォルトのキャッシュ クラスター セキュリティ グループにも追加されていることを確認しました。
これに関する指針は非常に役に立ちます。
アップデート
特定のレコードを取得するために使用されるコード スニペット。
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));
}