Search in sources :

Example 1 with ClientResponseWithPartitionKey

use of org.voltdb.client.ClientResponseWithPartitionKey in project voltdb by VoltDB.

the class ContinuousDeleter method run.

@Override
public void run() {
    // Will be set to true if any partition needs to delete more rows to meet the goals.
    AtomicBoolean unfinished = new AtomicBoolean(false);
    // Default yield time between deletes. May be shortened if there are a ton of tuples that need deleting.
    long yieldTimeMs = app.config.deleteyieldtime;
    try {
        // Get the targets from the main app class. Only one will be used, depending on whether the user is deleting
        // old rows by date or by row count.
        TimestampType dateTarget = app.getTargetDate();
        long rowTarget = app.getTargetRowsPerPartition();
        // Send the procedure call to all partitions and get results from each partitions.
        ClientResponseWithPartitionKey[] responses;
        if (app.config.historyseconds > 0) {
            responses = app.client.callAllPartitionProcedure("DeleteAfterDate", dateTarget, app.config.deletechunksize);
        } else /* if (app.config.maxrows > 0) */
        {
            responses = app.client.callAllPartitionProcedure("DeleteOldestToTarget", rowTarget, app.config.deletechunksize);
        }
        app.updatePartitionCount(responses.length);
        for (ClientResponseWithPartitionKey resp : responses) {
            if (resp.response.getStatus() == ClientResponse.SUCCESS) {
                long tuplesDeleted = resp.response.getResults()[0].asScalarLong();
                app.addToDeletedTuples(tuplesDeleted);
                // If the procedure deleted up to its limit, reduce the time before the deletes process runs again.
                if (tuplesDeleted >= app.config.deletechunksize) {
                    unfinished.set(true);
                }
            } else {
                failureCount.incrementAndGet();
            }
        }
        // WindowingApp and schedule two of them to run concurrently.
        if (unfinished.get()) {
            yieldTimeMs = 0;
        }
    } catch (Exception e) {
        failureCount.incrementAndGet();
    } catch (Throwable t) {
        t.printStackTrace();
    // Live dangerously and ignore this.
    } finally {
        // Use a finally block to ensure this task is re-scheduled.
        app.scheduler.schedule(this, yieldTimeMs, TimeUnit.MILLISECONDS);
    }
}
Also used : ClientResponseWithPartitionKey(org.voltdb.client.ClientResponseWithPartitionKey) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimestampType(org.voltdb.types.TimestampType)

Example 2 with ClientResponseWithPartitionKey

use of org.voltdb.client.ClientResponseWithPartitionKey in project YCSB by brianfrankcooper.

the class VoltClient4 method scan.

@Override
public Status scan(String keyspace, String lowerBound, int recordCount, Set<String> columns, Vector<HashMap<String, ByteIterator>> result) {
    try {
        if (useScanAll) {
            byte[] ks = keyspace.getBytes(UTF8);
            ClientResponse response = mclient.callProcedure("ScanAll", ks, lowerBound.getBytes(UTF8), recordCount);
            if (response.getStatus() != ClientResponse.SUCCESS) {
                return Status.ERROR;
            }
            result.ensureCapacity(recordCount);
            VoltTable outputTable = response.getResults()[0];
            outputTable.resetRowPosition();
            while (outputTable.advanceRow()) {
                result.add(unpackRowDataHashMap(outputTable, columns));
            }
        } else {
            byte[] ks = keyspace.getBytes(UTF8);
            ClientResponseWithPartitionKey[] response = mclient.callAllPartitionProcedure("Scan", ks, lowerBound.getBytes(UTF8), recordCount);
            for (int i = 0; i < response.length; i++) {
                if (response[i].response.getStatus() != ClientResponse.SUCCESS) {
                    return Status.ERROR;
                }
            }
            result.ensureCapacity(recordCount);
            VoltDBTableSortedMergeWrangler smw = new VoltDBTableSortedMergeWrangler(response);
            VoltTable outputTable = smw.getSortedTable(1, recordCount);
            outputTable.resetRowPosition();
            while (outputTable.advanceRow()) {
                result.add(unpackRowDataHashMap(outputTable, columns));
            }
        }
        return Status.OK;
    } catch (Exception e) {
        logger.error("Error while calling SCAN", e);
        return Status.ERROR;
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ClientResponseWithPartitionKey(org.voltdb.client.ClientResponseWithPartitionKey) VoltDBTableSortedMergeWrangler(site.ycsb.db.voltdb.sortedvolttable.VoltDBTableSortedMergeWrangler) VoltTable(org.voltdb.VoltTable) NoConnectionsException(org.voltdb.client.NoConnectionsException) DBException(site.ycsb.DBException)

Aggregations

ClientResponseWithPartitionKey (org.voltdb.client.ClientResponseWithPartitionKey)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 VoltTable (org.voltdb.VoltTable)1 ClientResponse (org.voltdb.client.ClientResponse)1 NoConnectionsException (org.voltdb.client.NoConnectionsException)1 TimestampType (org.voltdb.types.TimestampType)1 DBException (site.ycsb.DBException)1 VoltDBTableSortedMergeWrangler (site.ycsb.db.voltdb.sortedvolttable.VoltDBTableSortedMergeWrangler)1