我在從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