Search in sources :

Example 1 with AsyncResultSet

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();
}
Also used : KCVMutation(org.janusgraph.diskstorage.keycolumnvalue.KCVMutation) DistributedStoreManager(org.janusgraph.diskstorage.common.DistributedStoreManager) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionException(java.util.concurrent.ExecutionException) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) List(java.util.List) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Map(java.util.Map) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) CQLKeyColumnValueStore(org.janusgraph.diskstorage.cql.CQLKeyColumnValueStore) Optional(java.util.Optional) ConsumerWithBackendException(org.janusgraph.diskstorage.cql.function.ConsumerWithBackendException) LinkedList(java.util.LinkedList) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) CompletableFuture(java.util.concurrent.CompletableFuture) CQLKeyColumnValueStore(org.janusgraph.diskstorage.cql.CQLKeyColumnValueStore) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ExecutionException(java.util.concurrent.ExecutionException) LinkedList(java.util.LinkedList)

Example 2 with AsyncResultSet

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);
    }
}
Also used : BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Example 3 with AsyncResultSet

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);
    }
}
Also used : BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Aggregations

AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)3 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)2 BoundStatementBuilder (com.datastax.oss.driver.api.core.cql.BoundStatementBuilder)2 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)1 DistributedStoreManager (org.janusgraph.diskstorage.common.DistributedStoreManager)1 CQLKeyColumnValueStore (org.janusgraph.diskstorage.cql.CQLKeyColumnValueStore)1 ConsumerWithBackendException (org.janusgraph.diskstorage.cql.function.ConsumerWithBackendException)1 KCVMutation (org.janusgraph.diskstorage.keycolumnvalue.KCVMutation)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1 TimestampProvider (org.janusgraph.diskstorage.util.time.TimestampProvider)1