Search in sources :

Example 21 with ProcedureCallback

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

the class TableHelper method loadTable.

/**
     * A fairly straighforward loader for tables with metadata and rows. Maybe this could
     * be faster or have better error messages? Meh.
     *
     * @param client Client connected to a VoltDB instance containing a table with same name
     * and schema as the VoltTable parameter named "t".
     * @param t A table with extra metadata and presumably some data in it.
     * @throws Exception
     */
public static void loadTable(Client client, VoltTable t) throws Exception {
    // ensure table is annotated
    assert (t.m_extraMetadata != null);
    // replicated tables
    if (t.m_extraMetadata.partitionColIndex == -1) {
        // using insert here
        client.callProcedure("@LoadMultipartitionTable", t.m_extraMetadata.name, (byte) 0, t);
    } else // partitioned tables
    {
        final AtomicBoolean failed = new AtomicBoolean(false);
        final CountDownLatch latch = new CountDownLatch(t.getRowCount());
        int columns = t.getColumnCount();
        String procedureName = t.m_extraMetadata.name.toUpperCase() + ".insert";
        // callback for async row insertion tracks response count + failure
        final ProcedureCallback insertCallback = new ProcedureCallback() {

            @Override
            public void clientCallback(ClientResponse clientResponse) throws Exception {
                latch.countDown();
                if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                    failed.set(true);
                }
            }
        };
        // async insert all the rows
        t.resetRowPosition();
        while (t.advanceRow()) {
            Object[] params = new Object[columns];
            for (int i = 0; i < columns; ++i) {
                params[i] = t.get(i, t.getColumnType(i));
            }
            client.callProcedure(insertCallback, procedureName, params);
        }
        // block until all inserts are done
        latch.await();
        // throw a generic exception if anything fails
        if (failed.get()) {
            throw new RuntimeException("TableHelper.load failed.");
        }
    }
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 22 with ProcedureCallback

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

the class TestFixedSQLSuite method subTestTicketEng1850_WhereOrderBy.

private void subTestTicketEng1850_WhereOrderBy() throws Exception {
    System.out.println("STARTING testTicketENG1850_WhereOrderBy");
    ProcedureCallback callback = new ProcedureCallback() {

        @Override
        public void clientCallback(ClientResponse clientResponse) throws Exception {
            if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                throw new RuntimeException("Failed with response: " + clientResponse.getStatusString());
            }
        }
    };
    Client client = getClient();
    int cid = 0;
    do {
        for (int aid = 0; aid < 5; aid++) {
            int pid = cid % 10;
            client.callProcedure(callback, "ENG1850.insert", cid++, aid, pid, (pid + aid));
        }
    } while (cid < 1000);
    client.drain();
    VoltTable r1 = client.callProcedure("@AdHoc", "select count(*) from ENG1850;").getResults()[0];
    assertEquals(1000, r1.asScalarLong());
    VoltTable r2 = client.callProcedure("@AdHoc", "select count(*) from ENG1850 where pid =2;").getResults()[0];
    assertEquals(100, r2.asScalarLong());
    VoltTable r3 = client.callProcedure("@AdHoc", "select * from ENG1850 where pid = 2 limit 1;").getResults()[0];
    //* enable for debugging */ System.out.println("r3\n" + r3);
    assertEquals(1, r3.getRowCount());
    // this failed, returning 0 rows.
    VoltTable r4 = client.callProcedure("@AdHoc", "select * from ENG1850 where pid = 2 order by pid, aid").getResults()[0];
    //* enable for debugging */ System.out.println("r4\n:" + r4);
    assertEquals(100, r4.getRowCount());
    // this is the failing condition reported in the defect report (as above but with the limit)
    VoltTable r5 = client.callProcedure("@AdHoc", "select * from ENG1850 where pid = 2 order by pid, aid limit 1").getResults()[0];
    //* enable for debugging */ System.out.println("r5\n" + r5);
    assertEquals(1, r5.getRowCount());
    truncateTable(client, "ENG1850");
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Example 23 with ProcedureCallback

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

the class DeletesClient method deleteDeceased.

static void deleteDeceased(Client client) {
    Date date = new Date();
    System.out.println(date.toString() + "\n\tDeleting deceased records...");
    m_expectedDeadDeletes = NUM_NAMES;
    long start_time = System.currentTimeMillis();
    for (int i = 0; i < NUM_NAMES; i++) {
        try {
            while (!client.callProcedure(new ProcedureCallback() {

                @Override
                public void clientCallback(ClientResponse response) {
                    if (response.getStatus() != ClientResponse.SUCCESS) {
                        System.out.println("failed delete deceased");
                        System.out.println(response.getStatusString());
                    } else {
                        m_totalRows -= response.getResults()[0].asScalarLong();
                    }
                    //we don't care if tx fail, but don't get stuck in yield
                    m_expectedDeadDeletes--;
                }
            }, "DeleteDeceased", m_names[i])) {
                try {
                    client.backpressureBarrier();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } catch (NoConnectionsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    while (m_expectedDeadDeletes != 0) {
        Thread.yield();
    }
    long elapsed = System.currentTimeMillis() - start_time;
    m_totalDeadDeletes += NUM_NAMES;
    m_totalDeadDeleteTime += elapsed;
    System.out.println("\tAfter dead deletes, total rows: " + m_totalRows);
    System.out.println("\tDeleting deceased: " + NUM_NAMES + " took " + elapsed + " millis");
    System.out.println("\t\t (" + ((NUM_NAMES * 1000) / elapsed) + " tps)");
    System.out.println("\tTotal delete TPS: " + (m_totalDeadDeletes * 1000) / m_totalDeadDeleteTime);
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) Date(java.util.Date)

Example 24 with ProcedureCallback

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

the class DeletesClient method countBatch.

static void countBatch(Client client, long batch) {
    Date date = new Date();
    System.out.println(date.toString() + "\n\tCounting batch: " + batch);
    m_expectedCounts = 1;
    long start_time = System.currentTimeMillis();
    for (int i = 0; i < 1; i++) {
        try {
            while (!client.callProcedure(new ProcedureCallback() {

                @Override
                public void clientCallback(ClientResponse response) {
                    if (response.getStatus() != ClientResponse.SUCCESS) {
                        System.out.println("failed count batch");
                        System.out.println(response.getStatusString());
                    } else {
                        System.out.println("\tBatch has " + response.getResults()[0].asScalarLong() + " items");
                    }
                    //we don't care if tx fail, but don't get stuck in yield
                    m_expectedCounts--;
                }
            }, "CountBatchSize", "", batch)) {
                try {
                    client.backpressureBarrier();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } catch (NoConnectionsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    while (m_expectedCounts != 0) {
        Thread.yield();
    }
    long elapsed = System.currentTimeMillis() - start_time;
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) Date(java.util.Date)

Example 25 with ProcedureCallback

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

the class AsyncBenchmark method doBenchmark.

// There are poolSize rowid_groups in the database (default = 100,000)
// Each rowid_group has 1000 unique rowids such that (rowid_group, rowid) is unique.
// This gives 100M records in the DB by default.
private static void doBenchmark(String procedure, final int poolSize, final Random rand, long wait) throws Exception {
    final int totalPartitions = 4;
    final int maxGroupsPerPartition = 1000;
    // ~1% chance of cold data
    boolean coldData = (Math.abs(rand.nextLong()) % 100) <= 1;
    long rowid_group = coldData ? Math.abs(rand.nextLong()) % poolSize : Math.abs(rand.nextLong()) % (totalPartitions * maxGroupsPerPartition);
    long rowid = Math.abs(rand.nextLong()) % 1000;
    Con.executeAsync(new ProcedureCallback() {

        @Override
        public void clientCallback(ClientResponse response) throws Exception {
            // Track the result of the request (Success, Failure)
            if (response.getStatus() == ClientResponse.SUCCESS)
                TrackingResults.incrementAndGet(0);
            else
                TrackingResults.incrementAndGet(1);
        }
    }, procedure, rowid, rowid_group, new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ").getBytes());
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse)

Aggregations

ProcedureCallback (org.voltdb.client.ProcedureCallback)29 ClientResponse (org.voltdb.client.ClientResponse)28 JSONException (org.json_voltpatches.JSONException)9 ExecutionException (java.util.concurrent.ExecutionException)8 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)8 NodeExistsException (org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException)8 JSONObject (org.json_voltpatches.JSONObject)7 IOException (java.io.IOException)6 Client (org.voltdb.client.Client)6 VoltTable (org.voltdb.VoltTable)5 NoConnectionsException (org.voltdb.client.NoConnectionsException)5 Date (java.util.Date)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ByteBuffer (java.nio.ByteBuffer)2 TreeMap (java.util.TreeMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Timestamp (java.sql.Timestamp)1