Search in sources :

Example 1 with AdminResult

use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.

the class DefaultTopologyMonitor method refreshNodeList.

@Override
public CompletionStage<Iterable<NodeInfo>> refreshNodeList() {
    if (closeFuture.isDone()) {
        return CompletableFutures.failedFuture(new IllegalStateException("closed"));
    }
    LOG.debug("[{}] Refreshing node list", logPrefix);
    DriverChannel channel = controlConnection.channel();
    EndPoint localEndPoint = channel.getEndPoint();
    savePort(channel);
    CompletionStage<AdminResult> localQuery = query(channel, "SELECT * FROM system.local");
    CompletionStage<AdminResult> peersV2Query = query(channel, "SELECT * FROM system.peers_v2");
    CompletableFuture<AdminResult> peersQuery = new CompletableFuture<>();
    peersV2Query.whenComplete((r, t) -> {
        if (t != null) {
            // If system.peers_v2 does not exist, downgrade to system.peers
            if (t instanceof UnexpectedResponseException && ((UnexpectedResponseException) t).message instanceof Error) {
                Error error = (Error) ((UnexpectedResponseException) t).message;
                if (error.code == ProtocolConstants.ErrorCode.INVALID || // 6.0.2 with search enabled)
                (error.code == ProtocolConstants.ErrorCode.SERVER_ERROR && error.message.contains("Unknown keyspace/cf pair (system.peers_v2)"))) {
                    // We should not attempt this query in the future.
                    this.isSchemaV2 = false;
                    CompletableFutures.completeFrom(query(channel, "SELECT * FROM system.peers"), peersQuery);
                    return;
                }
            }
            peersQuery.completeExceptionally(t);
        } else {
            peersQuery.complete(r);
        }
    });
    return localQuery.thenCombine(peersQuery, (controlNodeResult, peersResult) -> {
        List<NodeInfo> nodeInfos = new ArrayList<>();
        AdminRow localRow = controlNodeResult.iterator().next();
        InetSocketAddress localBroadcastRpcAddress = getBroadcastRpcAddress(localRow, localEndPoint);
        nodeInfos.add(nodeInfoBuilder(localRow, localBroadcastRpcAddress, localEndPoint).build());
        for (AdminRow peerRow : peersResult) {
            if (isPeerValid(peerRow)) {
                InetSocketAddress peerBroadcastRpcAddress = getBroadcastRpcAddress(peerRow, localEndPoint);
                if (peerBroadcastRpcAddress != null) {
                    NodeInfo nodeInfo = nodeInfoBuilder(peerRow, peerBroadcastRpcAddress, localEndPoint).build();
                    nodeInfos.add(nodeInfo);
                }
            }
        }
        return nodeInfos;
    });
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Error(com.datastax.oss.protocol.internal.response.Error) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult) CompletableFuture(java.util.concurrent.CompletableFuture) UnexpectedResponseException(com.datastax.oss.driver.internal.core.adminrequest.UnexpectedResponseException) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 2 with AdminResult

use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.

the class SchemaAgreementCheckerTest method mockResult.

private AdminResult mockResult(AdminRow... rows) {
    AdminResult result = mock(AdminResult.class);
    when(result.iterator()).thenReturn(Iterators.forArray(rows));
    return result;
}
Also used : AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult)

Example 3 with AdminResult

use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.

the class DefaultTopologyMonitorTest method mockResult.

private AdminResult mockResult(AdminRow... rows) {
    AdminResult result = mock(AdminResult.class);
    when(result.iterator()).thenReturn(Iterators.forArray(rows));
    return result;
}
Also used : AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult)

Example 4 with AdminResult

use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.

the class ReprepareOnUpTest method should_reprepare_all_if_system_table_empty.

@Test
public void should_reprepare_all_if_system_table_empty() {
    MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
    reprepareOnUp.start();
    MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
    assertThat(adminQuery).isNotNull();
    assertThat(adminQuery.request).isInstanceOf(Query.class);
    assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
    // server knows no ids:
    adminQuery.resultFuture.complete(new AdminResult(preparedIdRows(), null, DefaultProtocolVersion.DEFAULT));
    for (char c = 'a'; c <= 'f'; c++) {
        adminQuery = reprepareOnUp.queries.poll();
        assertThat(adminQuery).isNotNull();
        assertThat(adminQuery.request).isInstanceOf(Prepare.class);
        assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
        adminQuery.resultFuture.complete(null);
    }
    assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
Also used : Query(com.datastax.oss.protocol.internal.request.Query) Prepare(com.datastax.oss.protocol.internal.request.Prepare) AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult) Test(org.junit.Test)

Example 5 with AdminResult

use of com.datastax.oss.driver.internal.core.adminrequest.AdminResult in project java-driver by datastax.

the class ReprepareOnUpTest method should_limit_number_of_statements_reprepared_in_parallel.

@Test
public void should_limit_number_of_statements_reprepared_in_parallel() {
    when(defaultProfile.getInt(DefaultDriverOption.REPREPARE_MAX_PARALLELISM)).thenReturn(3);
    MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
    reprepareOnUp.start();
    MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
    assertThat(adminQuery).isNotNull();
    assertThat(adminQuery.request).isInstanceOf(Query.class);
    assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
    // server knows no ids => will reprepare all 6:
    adminQuery.resultFuture.complete(new AdminResult(preparedIdRows(), null, DefaultProtocolVersion.DEFAULT));
    // 3 statements have enqueued, we've not completed the queries yet so no more should be sent:
    assertThat(reprepareOnUp.queries.size()).isEqualTo(3);
    // As we complete each statement, another one should enqueue:
    for (char c = 'a'; c <= 'c'; c++) {
        adminQuery = reprepareOnUp.queries.poll();
        assertThat(adminQuery).isNotNull();
        assertThat(adminQuery.request).isInstanceOf(Prepare.class);
        assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
        adminQuery.resultFuture.complete(null);
        assertThat(reprepareOnUp.queries.size()).isEqualTo(3);
    }
    // Complete the last 3:
    for (char c = 'd'; c <= 'f'; c++) {
        adminQuery = reprepareOnUp.queries.poll();
        assertThat(adminQuery).isNotNull();
        assertThat(adminQuery.request).isInstanceOf(Prepare.class);
        assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
        adminQuery.resultFuture.complete(null);
    }
    assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
Also used : Query(com.datastax.oss.protocol.internal.request.Query) Prepare(com.datastax.oss.protocol.internal.request.Prepare) AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult) Test(org.junit.Test)

Aggregations

AdminResult (com.datastax.oss.driver.internal.core.adminrequest.AdminResult)11 Test (org.junit.Test)6 Prepare (com.datastax.oss.protocol.internal.request.Prepare)4 Query (com.datastax.oss.protocol.internal.request.Query)4 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)3 Version (com.datastax.oss.driver.api.core.Version)2 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)2 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2 EndPoint (com.datastax.oss.driver.api.core.metadata.EndPoint)2 Node (com.datastax.oss.driver.api.core.metadata.Node)2 AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)2 UnexpectedResponseException (com.datastax.oss.driver.internal.core.adminrequest.UnexpectedResponseException)2 Error (com.datastax.oss.protocol.internal.response.Error)2 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 CompletionStage (java.util.concurrent.CompletionStage)2 DseNodeProperties (com.datastax.dse.driver.api.core.metadata.DseNodeProperties)1 Assertions.assertThat (com.datastax.oss.driver.Assertions.assertThat)1 Assertions.assertThatStage (com.datastax.oss.driver.Assertions.assertThatStage)1