6

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));
}
4

1 に答える 1

0

Amazon によって作成された変更された ElastiCache クラスター クライアントを使用します。

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

ドキュメントによると、ElastiCache Cluster Client をダウンロードするには:

  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 を 1 年以上問題なく使用しています。

于 2014-01-16T20:57:27.960 に答える