6

我在從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)); 
} 
+0

你可以發佈你的代碼嗎?沒有看到你在做什麼,就無法診斷這個問題。堆棧跟蹤只是說操作需要很長時間才能完成。 – mikewied

+0

@mikewied請參閱具有代碼段的更新問題。謝謝。 – Chantz

+0

你的代碼顯示正確,沒有任何東西會跳出來。我只是再次檢查地址/端口組合是否正確。如果是,則嘗試從該代碼運行的同一位置遠程登錄到羣集中的某臺機器,然後檢查是否可以執行get操作。 – mikewied

回答

0

使用亞馬遜生產的改性ElastiCache集羣客戶端。

http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html#AutoDiscovery.ClusterClient

根據該文件,下載ElastiCache集羣客戶端:

  1. 登錄到AWS管理控制檯,並在https://console.aws.amazon.com/elasticache/打開ElastiCache控制檯。
  2. 在ElastiCache控制檯中,單擊下載ElastiCache羣集客戶端。

適用於Java的ElastiCache集羣客戶端的源代碼位於https://github.com/amazonwebservices/aws-elasticache-cluster-client-memcached-for-java。這個庫基於流行的Spymemcached客戶端。 ElastiCache羣集客戶端在Amazon軟件許可下發布。您可以自由修改源代碼,只要您認爲合適;您甚至可以將代碼合併到其他開源Memcached庫或您自己的客戶端代碼中。

目前版本爲1.0.1。一年多來,我一直在使用1.0版本,沒有任何問題。

相關問題