次の方法で共有


NoHostAvailableException と NoNodeAvailableException のトラブルシューティング

NoHostAvailableException は最上位レベルのラッパー例外であり、考えられる原因と内部例外が多数あり、その多くがクライアントに関連している可能性があります。 この例外は、クラスターや接続設定に問題がある場合、または 1 つ以上の Cassandra ノードが使用できない場合に発生する傾向があります。

この記事では、この例外が発生する理由を探り、使用されているクライアント ドライバーに関する具体的な詳細について説明します。

ドライバーの設定

NoHostAvailableException の最も一般的な原因の 1 つは、既定のドライバー設定です。 この記事の最後に記載されている 設定 を使用することをお勧めします。 説明情報を次に示します。

  • ホストごとの接続の既定値は 1 ですが、Azure Cosmos DB では推奨しません。 最小値は 10 にすることをお勧めします。 より集約された要求ユニット (RU) が提供されますが、接続数を増やしてください。 一般的なガイドラインは、200,000 RU あたり 10 接続です。
  • Azure Cosmos DB 再試行ポリシーを使用して、断続的な調整を処理します。 詳しくは、「Azure Cosmos DB の拡張機能」をご覧ください。
  • マルチ リージョン アカウントの場合は、拡張機能の Azure Cosmos DB 負荷分散ポリシーを使用します。
  • 読み取り要求のタイムアウトは 1 分を超える値に設定する必要があります。 90 秒をお勧めします。

例外メッセージ

推奨される変更を行った後も例外が解決しない場合は、次の 3 つのセクションで例外メッセージを確認してください。 エラー ログにこれらの例外メッセージが含まれている場合は、その例外に対する推奨事項に従ってください。

BusyPoolException

このクライアント側のエラーは、ホストの要求接続の最大数に達したかどうかを示します。 キューからの要求を削除できない場合は、このエラーが表示される可能性があります。 ホストあたりの接続数が最小の 10 に設定されている場合、例外はサーバー側の待機時間が長い場合に発生する可能性があります。

Java driver v3 exception:
All host(s) tried for query failed (tried: :10350 (com.datastax.driver.core.exceptions.BusyPoolException: [:10350] Pool is busy (no available connection and the queue has reached its max size 256)))
All host(s) tried for query failed (tried: :10350 (com.datastax.driver.core.exceptions.BusyPoolException: [:10350] Pool is busy (no available connection and timed out after 5000 MILLISECONDS)))
C# driver 3:
All hosts tried for query failed (tried :10350: BusyPoolException 'All connections to host :10350 are busy, 2048 requests are in-flight on each 10 connection(s)')

推奨

max requests per connection をチューニングする代わりに 、connections per host を少なくとも 10 に設定してください。 コード サンプルのセクションを参照してください。

TooManyRequest(429)

要求レートが大きすぎると OverloadException がスローされます。これは、テーブルに十分なスループットがプロビジョニングされていない場合や、RU 予算を超えた場合に発生する可能性があります。 詳細については、大規模な要求サーバー側の再試行 に関するページを参照してください。

推奨

以下のオプションの 1 つを選択します。

  • 調整が永続的な場合は、プロビジョニングされた RU を増やします。
  • 調整が断続的な場合は、Azure Cosmos DB 再試行ポリシーを使用します。
  • 拡張機能ライブラリを参照できない場合は、サーバー側の再試行を有効 にします。

クエリを試行したすべてのホストが失敗した

クライアントがプライマリ連絡先ポイント リージョン以外のリージョンに接続するように設定されている場合、起動時の最初の数秒の間に、次のいずれかの例外メッセージが表示されます。

  • Java ドライバー 3: Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (no host was tried)at cassandra.driver.core@3.10.2/com.datastax.driver.core.exceptions.NoHostAvailableException.copy(NoHostAvailableException.java:83)

  • Java ドライバー 4: No node was available to execute the query

  • C# ドライバー 3: System.ArgumentException: Datacenter West US does not match any of the nodes, available datacenters: West US 2

推奨

Java ドライバー 3 および Java ドライバー 4 で CosmosLoadBalancingPolicy を使用してください。 このポリシーは、指定されたローカル データが使用できないプライマリ書き込みリージョンの連絡先ポイントにフォール バックします。

Note

上記の推奨事項で問題を解決できない場合は、Azure Cosmos DB サポートにお問い合わせください。 例外メッセージ、例外スタックトレース、datastax ドライバー ログ、ユニバーサル障害時刻、一貫性のある障害または断続的なエラー、失敗したキースペースとテーブル、失敗した要求の種類、SDK バージョンの詳細を必ず指定してください。

コード サンプル

Java Driver 3 の設定

   // socket options with default values
    // https://docs.datastax.com/en/developer/java-driver/3.6/manual/socket_options/
    SocketOptions socketOptions = new SocketOptions()
        .setReadTimeoutMillis(90000); // default 12000

    // connection pooling options (default values are 1s)
    // https://docs.datastax.com/en/developer/java-driver/3.6/manual/pooling/
    PoolingOptions poolingOptions = new PoolingOptions()
        .setCoreConnectionsPerHost(HostDistance.LOCAL, 10) // default 1
        .setMaxConnectionsPerHost(HostDistance.LOCAL, 10) // default 1
        .setCoreConnectionsPerHost(HostDistance.REMOTE, 10) // default 1
        .setMaxConnectionsPerHost(HostDistance.REMOTE, 10); //default 1

    // Azure Cosmos DB load balancing policy
    String Region = "West US";
    CosmosLoadBalancingPolicy cosmosLoadBalancingPolicy = CosmosLoadBalancingPolicy.builder()
        .withWriteDC(Region)
        .withReadDC(Region)
        .build();

    // Azure Cosmos DB retry policy
    CosmosRetryPolicy retryPolicy = CosmosRetryPolicy.builder()
        .withFixedBackOffTimeInMillis(5000)
        .withGrowingBackOffTimeInMillis(1000)
        .withMaxRetryCount(5)
        .build();

    Cluster cluster = Cluster.builder()
        .addContactPoint(EndPoint).withPort(10350)
        .withCredentials(UserName, Password)
        .withSSL(sslOptions)
        .withSocketOptions(socketOptions)
        .withPoolingOptions(poolingOptions)
        .withLoadBalancingPolicy(cosmosLoadBalancingPolicy)
        .withRetryPolicy(retryPolicy)
        .build();

Java Driver 4 の設定

    // driver configurations
    // https://docs.datastax.com/en/developer/java-driver/4.6/manual/core/configuration/
    ProgrammaticDriverConfigLoaderBuilder configBuilder = DriverConfigLoader.programmaticBuilder();

    // connection settings
    // https://docs.datastax.com/en/developer/java-driver/4.6/manual/core/pooling/
    configBuilder
        .withInt(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, 10) // default 1
        .withInt(DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE, 10) // default 1
        .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(90)) // default 2
        .withClass(DefaultDriverOption.RECONNECTION_POLICY_CLASS, ConstantReconnectionPolicy.class) // default ExponentialReconnectionPolicy
        .withBoolean(DefaultDriverOption.METADATA_TOKEN_MAP_ENABLED, false); // default true

    // load balancing settings
    // https://docs.datastax.com/en/developer/java-driver/4.6/manual/core/load_balancing/
    String Region = "West US";
    List<String> preferredRegions = new ArrayList<String>();
    preferredRegions.add(Region);
    configBuilder
        .withClass(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, CosmosLoadBalancingPolicy.class)
        .withBoolean(CosmosLoadBalancingPolicyOption.MULTI_REGION_WRITES, false)
        .withStringList(CosmosLoadBalancingPolicyOption.PREFERRED_REGIONS, preferredRegions);

    // retry policy
    // https://docs.datastax.com/en/developer/java-driver/4.6/manual/core/retries/
    configBuilder
        .withClass(DefaultDriverOption.RETRY_POLICY_CLASS, CosmosRetryPolicy.class)
        .withInt(CosmosRetryPolicyOption.FIXED_BACKOFF_TIME, 5000)
        .withInt(CosmosRetryPolicyOption.GROWING_BACKOFF_TIME, 1000)
        .withInt(CosmosRetryPolicyOption.MAX_RETRIES, 5);

    CqlSession session = CqlSession.builder()
        .withSslContext(sc)
        .addContactPoint(new InetSocketAddress(EndPoint, Port))
        .withAuthCredentials(UserName, Password)
        .withLocalDatacenter(Region)
        .withConfigLoader(configBuilder.build())
        .build();

C# v3 ドライバーの設定

    PoolingOptions poolingOptions = PoolingOptions.Create()
        .SetCoreConnectionsPerHost(HostDistance.Local, 10) // default 2
        .SetMaxConnectionsPerHost(HostDistance.Local, 10) // default 8
        .SetCoreConnectionsPerHost(HostDistance.Remote, 10) // default 1
        .SetMaxConnectionsPerHost(HostDistance.Remote, 10); // default 2

    SocketOptions socketOptions = new SocketOptions()
        .SetReadTimeoutMillis(90000); // default 12000

    buildCluster = Cluster.Builder()
        .AddContactPoint(Program.ContactPoint)
        .WithPort(Program.CosmosCassandraPort)
        .WithCredentials(Program.UserName, Program.Password)
        .WithPoolingOptions(poolingOptions)
        .WithSocketOptions(socketOptions)
        .WithReconnectionPolicy(new ConstantReconnectionPolicy(1000)) // default ExponentialReconnectionPolicy
        .WithSSL(sslOptions);

次のステップ