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;
});
}
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;
}
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;
}
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());
}
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());
}
Aggregations