use of com.datastax.oss.driver.api.core.cql.AsyncResultSet in project janusgraph by JanusGraph.
the class CQLSimpleMutateManyUnloggedFunction method mutate.
@Override
protected Optional<Throwable> mutate(DistributedStoreManager.MaskedTimestamp commitTime, Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) {
List<CompletableFuture<AsyncResultSet>> resultList = new LinkedList<>();
mutations.forEach((tableName, tableMutations) -> {
final CQLKeyColumnValueStore columnValueStore = getColumnValueStore(tableName);
tableMutations.forEach((key, keyMutations) -> toGroupedBatchableStatementsSequenceIterator(commitTime, keyMutations, columnValueStore, key).forEach(group -> {
CompletableFuture<AsyncResultSet> completableFuture = execAsyncUnlogged(group, txh);
resultList.add(completableFuture);
}));
});
for (CompletableFuture<AsyncResultSet> resultPart : resultList) {
try {
resultPart.get();
} catch (InterruptedException | ExecutionException e) {
return Optional.of(e);
}
}
return Optional.empty();
}
use of com.datastax.oss.driver.api.core.cql.AsyncResultSet in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method deletePartitionAsync.
private void deletePartitionAsync(TenantId tenantId, final QueryCursor cursor, final SimpleListenableFuture<Void> resultFuture) {
if (!cursor.hasNextPartition()) {
resultFuture.set(null);
} else {
PreparedStatement proto = getDeletePartitionStmt();
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
stmtBuilder.setString(0, cursor.getEntityType());
stmtBuilder.setUuid(1, cursor.getEntityId());
stmtBuilder.setLong(2, cursor.getNextPartition());
stmtBuilder.setString(3, cursor.getKey());
BoundStatement stmt = stmtBuilder.build();
Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
@Override
public void onSuccess(@Nullable AsyncResultSet result) {
deletePartitionAsync(tenantId, cursor, resultFuture);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to delete data for query {}-{}", stmt, t);
}
}, readResultsProcessingExecutor);
}
}
use of com.datastax.oss.driver.api.core.cql.AsyncResultSet in project thingsboard by thingsboard.
the class CassandraBaseTimeseriesDao method deleteAsync.
private void deleteAsync(TenantId tenantId, final QueryCursor cursor, final SimpleListenableFuture<Void> resultFuture) {
if (!cursor.hasNextPartition()) {
resultFuture.set(null);
} else {
PreparedStatement proto = getDeleteStmt();
BoundStatementBuilder stmtBuilder = new BoundStatementBuilder(proto.bind());
stmtBuilder.setString(0, cursor.getEntityType());
stmtBuilder.setUuid(1, cursor.getEntityId());
stmtBuilder.setString(2, cursor.getKey());
stmtBuilder.setLong(3, cursor.getNextPartition());
stmtBuilder.setLong(4, cursor.getStartTs());
stmtBuilder.setLong(5, cursor.getEndTs());
BoundStatement stmt = stmtBuilder.build();
Futures.addCallback(executeAsyncWrite(tenantId, stmt), new FutureCallback<AsyncResultSet>() {
@Override
public void onSuccess(@Nullable AsyncResultSet result) {
deleteAsync(tenantId, cursor, resultFuture);
}
@Override
public void onFailure(Throwable t) {
log.error("[{}][{}] Failed to delete data for query {}-{}", stmt, t);
}
}, readResultsProcessingExecutor);
}
}
Aggregations