Search in sources :

Example 11 with NullCallback

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

the class GenerateCPPTestFiles method main.

/**
     * @param args
     */
public static void main(String[] args) throws Exception {
    boolean generateGeoMessages = true;
    String clientDataDirName = ".";
    long clusterStartTime = CLUSTER_START_TIME;
    int clusterRoundTripTime = CLUSTER_ROUND_TRIP_TIME;
    long clientData = CLIENT_DATA;
    int leaderIPAddr = LEADER_IP_ADDR;
    String buildString = BUILD_STRING;
    for (int idx = 0; idx < args.length; idx += 1) {
        if ("--client-dir".equals(args[idx])) {
            idx += 1;
            clientDataDirName = args[idx];
        } else if ("--clusterStartTime".equals(args[idx])) {
            idx += 1;
            clusterStartTime = Long.valueOf(args[idx]);
        } else if ("--clientData".equals(args[idx])) {
            idx += 1;
            clientData = Long.valueOf(args[idx]);
        } else if ("--leaderIPAddr".equals(args[idx])) {
            idx += 1;
            leaderIPAddr = Integer.valueOf(args[idx]);
        } else if ("--clusterRoundTripTime".equals(args[idx])) {
            idx += 1;
            clusterRoundTripTime = Integer.valueOf(args[idx]);
        } else if ("--no-geo-messages".equals(args[idx])) {
            generateGeoMessages = false;
        } else {
            abend("Unknown command line argument \"%s\"\n", args[idx]);
        }
    }
    // Make the client data directory if necessary.
    File clientDataDir = new File(clientDataDirName);
    if (clientDataDir.exists() && !clientDataDir.isDirectory()) {
        if (!clientDataDir.isDirectory()) {
            abend("Client data dir \"%s\" exists but is not a directory.\n", clientDataDirName);
        }
    } else {
        clientDataDir.mkdirs();
    }
    //
    // Capture a HASH_SHA256 style authentication message.  We do this by
    // creating a fake server, then, in a separate thread, creating an ordinary
    // client which connects to the fake server.  We read the authentication
    // request from the client, save it, send a faked authentication response,
    // close the server and join with the created thread.
    //
    ServerSocketChannel ssc = ServerSocketChannel.open();
    ssc.socket().bind(new InetSocketAddress("localhost", FAKE_SERVER_PORT));
    ClientConfig config = new ClientConfig("hello", "world", (ClientStatusListenerExt) null, ClientAuthScheme.HASH_SHA256);
    final org.voltdb.client.Client client = ClientFactory.createClient(config);
    Thread clientThread = new Thread() {

        @Override
        public void run() {
            try {
                client.createConnection("localhost", FAKE_SERVER_PORT);
                client.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    clientThread.setDaemon(true);
    clientThread.start();
    SocketChannel sc = ssc.accept();
    sc.socket().setTcpNoDelay(true);
    ByteBuffer authReqSHA256 = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    sc.configureBlocking(true);
    readMessage(authReqSHA256, sc);
    writeDataFile(clientDataDir, "authentication_request_sha256.msg", authReqSHA256);
    writeServerAuthenticationResponse(sc, true);
    ssc.close();
    clientThread.join(0);
    //
    // Now, create a fake server again, and login with the HASH_SHA1 scheme.
    // We save this authentication request as well.  The client in the
    // separate thread then sends some procedure invocation messages.  We
    // save all of these in files and then join with the client thread.
    //
    ssc = ServerSocketChannel.open();
    ssc.socket().bind(new InetSocketAddress("localhost", FAKE_SERVER_PORT));
    config = new ClientConfig("hello", "world", (ClientStatusListenerExt) null, ClientAuthScheme.HASH_SHA1);
    final org.voltdb.client.Client oclient = ClientFactory.createClient(config);
    Thread oclientThread = new Thread() {

        @Override
        public void run() {
            NullCallback ncb = new NullCallback();
            try {
                oclient.createConnection("localhost", FAKE_SERVER_PORT);
                oclient.callProcedure("Insert", "Hello", "World", "English");
                try {
                    oclient.callProcedure("Insert", "Hello", "World", "English");
                } catch (Exception e) {
                }
                oclient.callProcedure("Select", "English");
                //
                // Geo support.
                //
                // Insert a point and a polygon.
                oclient.callProcedure("InsertGeo", 200, GeographyValue.fromWKT(smallPolyTxt), GeographyPointValue.fromWKT(smallPointTxt));
                // Insert two nulls for points and polygons.
                oclient.callProcedure("InsertGeo", 201, null, null);
                // Select one row with a point and a polygon both.
                oclient.callProcedure("SelectGeo", 100);
                // Select another row with a different point and polygon.
                oclient.callProcedure("SelectGeo", 101);
                // Select one row with a null polygon and one non-null point.
                oclient.callProcedure("SelectGeo", 102);
                // Select one row with a non-null polygon and a null point.
                oclient.callProcedure("SelectGeo", 103);
                // Select one row with two nulls.
                oclient.callProcedure("SelectGeo", 104);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    oclientThread.setDaemon(true);
    oclientThread.start();
    sc = ssc.accept();
    sc.socket().setTcpNoDelay(true);
    ByteBuffer authReqSHA1 = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    sc.configureBlocking(true);
    readMessage(authReqSHA1, sc);
    writeDataFile(clientDataDir, "authentication_request.msg", authReqSHA1);
    writeServerAuthenticationResponse(sc, true);
    //
    // Read some call procedure messages.
    //
    // The client engages us in some witty banter, which we don't
    // actually care about for the purposes of this program.  But
    // we need to read past it, and acknowledge it anyway.  We are
    // acting as a server here.  We don't need to change the client
    // data at all.
    //
    ByteBuffer subscription_request = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    readMessage(subscription_request, sc);
    writeServerCallResponse(sc, getRequestClientData(subscription_request));
    ByteBuffer stats_request = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    readMessage(stats_request, sc);
    writeServerCallResponse(sc, getRequestClientData(stats_request));
    ByteBuffer syscat_request = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    readMessage(syscat_request, sc);
    writeServerCallResponse(sc, getRequestClientData(stats_request));
    //
    // Now, read the invocation requests from the client.  We can't
    // actually respond, so we fake up a response.  But this is good
    // enough for now, and we save the message.
    //
    String[] vanillaFileNames = new String[] { "invocation_request_success.msg", "invocation_request_fail_cv.msg", "invocation_request_select.msg" };
    Map<String, ByteBuffer> vanillaMessages = new HashMap<String, ByteBuffer>();
    for (String fileName : vanillaFileNames) {
        ByteBuffer responseMessage = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
        vanillaMessages.put(fileName, responseMessage);
        readMessage(responseMessage, sc);
        writeServerCallResponse(sc, getRequestClientData(responseMessage));
        // Set the client data.  The value here is not important, but it
        // needs to be shared between this and the client unit tests.
        setRequestClientData(responseMessage, clientData);
        writeDataFile(clientDataDir, fileName, responseMessage);
    }
    // Note that these names are somewhat stylized.  They name
    // the file which holds the request.  The response to this
    // request will be in a similarly named file, but with _request_
    // replaced by _response_.  So, make sure there is one _request_
    // substring in the file names.
    String[] geoFileNames = new String[] { "invocation_request_insert_geo.msg", "invocation_request_insert_geo_nulls.msg", "invocation_request_select_geo_both.msg", "invocation_request_select_geo_both_mid.msg", "invocation_request_select_geo_polynull.msg", "invocation_request_select_geo_ptnull.msg", "invocation_request_select_geo_bothnull.msg" };
    Map<String, ByteBuffer> geoMessages = new HashMap<String, ByteBuffer>();
    for (String filename : geoFileNames) {
        ByteBuffer requestMessage = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
        // We need to save these for later.
        geoMessages.put(filename, requestMessage);
        readMessage(requestMessage, sc);
        writeServerCallResponse(sc, getRequestClientData(requestMessage));
        setRequestClientData(requestMessage, clientData);
        if (generateGeoMessages) {
            writeDataFile(clientDataDir, filename, requestMessage);
        }
    }
    oclient.close();
    ssc.close();
    oclientThread.join();
    // Now, connect to a real server.  We are going to pretend to be a
    // client and write the messages we just read from the client, as we pretended to be
    // a server.  We will then capture the responses in files.
    SocketChannel voltsc = null;
    try {
        voltsc = SocketChannel.open(new InetSocketAddress("localhost", TRUE_SERVER_PORT));
        voltsc.socket().setTcpNoDelay(true);
        voltsc.configureBlocking(true);
        System.err.printf("Connected.\n");
    } catch (IOException ex) {
        abend("Can't connect to a server.  Is there a VoltDB server running?.\n");
    }
    // Write the authentication message and then
    // read the response.  We need the response.  The
    // Client will engage in witty repartee with the
    // server, but we neither see nor care about that.
    //
    // Note that for each of these responses we need to
    // set some parameters, so that they will not depend
    // on the particular context we executed.  This is the
    // cluster start time, the client data, the leader IP
    // address and the build string.  The client unit tests
    // will know these values.
    //
    ByteBuffer scratch = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    voltsc.write(authReqSHA1);
    readMessage(scratch, voltsc);
    setClusterStartTimestamp(scratch, clusterStartTime);
    setLeaderIPAddr(scratch, leaderIPAddr);
    setBuildString(scratch, buildString);
    writeDataFile(clientDataDir, "authentication_response.msg", scratch);
    for (String filename : vanillaFileNames) {
        // Write the three procedure messages.
        ByteBuffer requestMessage = vanillaMessages.get(filename);
        if (requestMessage == null) {
            abend("Cannot find request message for file name \"%s\"\n", filename);
        }
        voltsc.write(requestMessage);
        readMessage(scratch, voltsc);
        setResponseClientData(scratch, clientData);
        setClusterRoundTripTime(scratch, clusterRoundTripTime);
        String responseFileName = filename.replaceAll("_request_", "_response_");
        writeDataFile(clientDataDir, responseFileName, scratch);
    }
    if (generateGeoMessages) {
        for (String filename : geoFileNames) {
            // Write the three procedure messages.
            ByteBuffer requestMessage = geoMessages.get(filename);
            if (requestMessage == null) {
                abend("Cannot find request message for file name \"%s\"\n", filename);
            }
            voltsc.write(requestMessage);
            readMessage(scratch, voltsc);
            setResponseClientData(scratch, clientData);
            setClusterRoundTripTime(scratch, clusterRoundTripTime);
            String responseFileName = filename.replaceAll("_request_", "_response_");
            System.out.printf("Writing Response file \"%s\".\n", responseFileName);
            writeDataFile(clientDataDir, responseFileName, scratch);
        }
    }
    voltsc.close();
    clientThread.join();
    Thread.sleep(3000);
    ssc = ServerSocketChannel.open();
    ssc.socket().bind(new InetSocketAddress("localhost", FAKE_SERVER_PORT));
    clientThread = new Thread() {

        @Override
        public void run() {
            try {
                org.voltdb.client.Client newClient = ClientFactory.createClient();
                newClient.createConnection("localhost", FAKE_SERVER_PORT);
                String[] strings = new String[] { "oh", "noes" };
                byte[] bytes = new byte[] { 22, 33, 44 };
                short[] shorts = new short[] { 22, 33, 44 };
                int[] ints = new int[] { 22, 33, 44 };
                long[] longs = new long[] { 22, 33, 44 };
                double[] doubles = new double[] { 3, 3.1, 3.14, 3.1459 };
                TimestampType[] timestamps = new TimestampType[] { new TimestampType(33), new TimestampType(44) };
                BigDecimal[] bds = new BigDecimal[] { new BigDecimal("3"), new BigDecimal("3.14"), new BigDecimal("3.1459") };
                try {
                    newClient.callProcedure("foo", strings, bytes, shorts, ints, longs, doubles, timestamps, bds, null, "ohnoes!", (byte) 22, (short) 22, 22, (long) 22, 3.1459, new TimestampType(33), new BigDecimal("3.1459"));
                } catch (Exception e) {
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    clientThread.setDaemon(true);
    clientThread.start();
    voltsc = ssc.accept();
    // Read the authentication message.  We don't need it.
    readMessage(scratch, voltsc);
    writeServerAuthenticationResponse(voltsc, true);
    //
    // The client engages us in some dialog.  We don't need this
    // either, but we need to read past it.
    //
    subscription_request = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    readMessage(subscription_request, voltsc);
    writeServerCallResponse(voltsc, getRequestClientData(subscription_request));
    stats_request = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    readMessage(stats_request, voltsc);
    writeServerCallResponse(voltsc, getRequestClientData(stats_request));
    syscat_request = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    readMessage(syscat_request, voltsc);
    writeServerCallResponse(voltsc, getRequestClientData(stats_request));
    // Read the all-types call procedure message.
    readMessage(scratch, voltsc);
    writeServerCallResponse(voltsc, getRequestClientData(scratch));
    setRequestClientData(scratch, clientData);
    writeDataFile(clientDataDir, "invocation_request_all_params.msg", scratch);
    voltsc.close();
    clientThread.join();
    //
    // Serialize a message and write it.
    //
    ColumnInfo[] columns = new ColumnInfo[] { new ColumnInfo("column1", VoltType.TINYINT), new ColumnInfo("column2", VoltType.STRING), new ColumnInfo("column3", VoltType.SMALLINT), new ColumnInfo("column4", VoltType.INTEGER), new ColumnInfo("column5", VoltType.BIGINT), new ColumnInfo("column6", VoltType.TIMESTAMP), new ColumnInfo("column7", VoltType.DECIMAL), new ColumnInfo("column8", VoltType.GEOGRAPHY), new ColumnInfo("column9", VoltType.GEOGRAPHY_POINT) };
    VoltTable vt = new VoltTable(columns);
    GeographyValue poly = GeographyValue.fromWKT(smallPolyTxt);
    GeographyPointValue pt = GeographyPointValue.fromWKT(smallPointTxt);
    vt.addRow(null, null, null, null, null, null, null, poly, pt);
    vt.addRow(0, "", 2, 4, 5, new TimestampType(44), new BigDecimal("3.1459"), poly, pt);
    vt.addRow(0, null, 2, 4, 5, null, null, poly, pt);
    vt.addRow(null, "woobie", null, null, null, new TimestampType(44), new BigDecimal("3.1459"), poly, pt);
    ByteBuffer bb = ByteBuffer.allocate(vt.getSerializedSize());
    vt.flattenToBuffer(bb);
    FastSerializer fs = new FastSerializer(vt.getSerializedSize());
    fs.write(bb);
    bb.flip();
    writeDataFile(clientDataDir, "serialized_table.bin", bb);
    clientThread.join();
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) FastSerializer(org.voltdb.messaging.FastSerializer) ColumnInfo(org.voltdb.VoltTable.ColumnInfo) TimestampType(org.voltdb.types.TimestampType) NullCallback(org.voltdb.client.NullCallback) ClientConfig(org.voltdb.client.ClientConfig) ServerSocketChannel(java.nio.channels.ServerSocketChannel) GeographyValue(org.voltdb.types.GeographyValue) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) ClientStatusListenerExt(org.voltdb.client.ClientStatusListenerExt) File(java.io.File) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 12 with NullCallback

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

the class AsyncBenchmark method runBenchmark.

/**
     * Core benchmark code.
     * Connect. Initialize. Run the loop. Cleanup. Print Results.
     *
     * @throws Exception if anything unexpected happens.
     */
public void runBenchmark() throws Exception {
    System.out.print(HORIZONTAL_RULE);
    System.out.println(" Setup & Initialization");
    System.out.println(HORIZONTAL_RULE);
    // connect to one or more servers, loop until success
    connect(config.servers);
    // preload keys if requested
    System.out.println();
    if (config.preload) {
        System.out.println("Preloading data store...");
        for (int i = 0; i < config.poolsize; i++) {
            client.callProcedure(new NullCallback(), "STORE.upsert", String.format(processor.KeyFormat, i), processor.generateForStore().getStoreValue());
        }
        client.drain();
        System.out.println("Preloading complete.\n");
    }
    System.out.print(HORIZONTAL_RULE);
    System.out.println(" Starting Benchmark");
    System.out.println(HORIZONTAL_RULE);
    // Run the benchmark loop for the requested warmup time
    // The throughput may be throttled depending on client configuration
    System.out.println("Warming up...");
    final long warmupEndTime = System.currentTimeMillis() + (1000l * config.warmup);
    while (warmupEndTime > System.currentTimeMillis()) {
        // Decide whether to perform a GET or PUT operation
        if (rand.nextDouble() < config.getputratio) {
            // Get a key/value pair using inbuilt select procedure, asynchronously
            client.callProcedure(new NullCallback(), "STORE.select", processor.generateRandomKeyForRetrieval());
        } else {
            // Put a key/value pair using inbuilt upsert procedure, asynchronously
            final PayloadProcessor.Pair pair = processor.generateForStore();
            client.callProcedure(new NullCallback(), "STORE.upsert", pair.Key, pair.getStoreValue());
        }
    }
    // reset the stats after warmup
    fullStatsContext.fetchAndResetBaseline();
    periodicStatsContext.fetchAndResetBaseline();
    // print periodic statistics to the console
    benchmarkStartTS = System.currentTimeMillis();
    schedulePeriodicStats();
    // Run the benchmark loop for the requested duration
    // The throughput may be throttled depending on client configuration
    System.out.println("\nRunning benchmark...");
    final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration);
    while (benchmarkEndTime > System.currentTimeMillis()) {
        // Decide whether to perform a GET or PUT operation
        if (rand.nextDouble() < config.getputratio) {
            // Get a key/value pair using inbuilt select procedure, asynchronously
            client.callProcedure(new GetCallback(), "STORE.select", processor.generateRandomKeyForRetrieval());
        } else {
            // Put a key/value pair using inbuilt upsert procedure, asynchronously
            final PayloadProcessor.Pair pair = processor.generateForStore();
            client.callProcedure(new PutCallback(pair), "STORE.upsert", pair.Key, pair.getStoreValue());
        }
    }
    // cancel periodic stats printing
    timer.cancel();
    // block until all outstanding txns return
    client.drain();
    // print the summary results
    printResults();
    // close down the client connections
    client.close();
}
Also used : NullCallback(org.voltdb.client.NullCallback)

Example 13 with NullCallback

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

the class TestGroupByComplexSuite method turnOfftestAggregateOnJoinForMemoryIssue.

// This test case will trigger temp table "delete as we go" feature on join node
// Turn off this test cases because of valgrind timeout.
public void turnOfftestAggregateOnJoinForMemoryIssue() throws IOException, ProcCallException {
    Client client = this.getClient();
    ClientResponse cr;
    VoltTable vt;
    long[][] expected;
    // Empty data from table.
    for (String tb : tbs) {
        cr = client.callProcedure("@AdHoc", "delete from " + tb);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    }
    int scale = 10;
    int numOfRecords = scale * 1000;
    // Insert records into the table.
    // id, wage, dept, rate
    String timeStamp = "2013-06-18 02:00:00.123457";
    String[] myProcs = { "R1.insert", "P1.insert" };
    for (String insertProc : myProcs) {
        for (int ii = 1; ii <= numOfRecords; ii++) {
            client.callProcedure(new NullCallback(), insertProc, ii, ii % 1000, ii % 2, timeStamp);
        }
    }
    try {
        client.drain();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // Serial aggregation because of no group by
    cr = client.callProcedure("@AdHoc", "SELECT sum(R1.wage) " + " from R1, P1 WHERE R1.id = P1.id ;");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    expected = new long[][] { { 499500 * scale } };
    validateTableOfLongs(vt, expected);
    // hash aggregation because of no index on group by key
    cr = client.callProcedure("@AdHoc", "SELECT R1.dept, sum(R1.wage) " + " from R1, P1 WHERE R1.id = P1.id Group by R1.dept order by R1.dept;");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    expected = new long[][] { { 0, 249500 * scale }, { 1, 250000 * scale } };
    validateTableOfLongs(vt, expected);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) NullCallback(org.voltdb.client.NullCallback) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Example 14 with NullCallback

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

the class TestSystemProcedureSuite method testLoadMultipartitionTableAndIndexStatsAndValidatePartitioning.

public void testLoadMultipartitionTableAndIndexStatsAndValidatePartitioning() throws Exception {
    // using insert for @Load*Table
    byte upsertMode = (byte) 0;
    Client client = getClient();
    // Load a little partitioned data for the mispartitioned row check
    Random r = new Random(0);
    for (int ii = 0; ii < 50; ii++) {
        client.callProcedure(new NullCallback(), "@AdHoc", "INSERT INTO new_order values (" + (short) (r.nextDouble() * Short.MAX_VALUE) + ");");
    }
    // try the failure case first
    try {
        client.callProcedure("@LoadMultipartitionTable", "DOES_NOT_EXIST", upsertMode, null);
        fail("ORLY - @LoadMultipartitionTable DOES_NOT_EXIST succeeds");
    } catch (ProcCallException ex) {
        assertTrue(ex.getMessage().contains("Table not present in catalog"));
    }
    // make a TPCC warehouse table
    VoltTable partitioned_table = new VoltTable(new VoltTable.ColumnInfo("W_ID", org.voltdb.VoltType.SMALLINT), new VoltTable.ColumnInfo("W_NAME", org.voltdb.VoltType.get((byte) 9)), new VoltTable.ColumnInfo("W_STREET_1", org.voltdb.VoltType.get((byte) 9)), new VoltTable.ColumnInfo("W_STREET_2", org.voltdb.VoltType.get((byte) 9)), new VoltTable.ColumnInfo("W_CITY", org.voltdb.VoltType.get((byte) 9)), new VoltTable.ColumnInfo("W_STATE", org.voltdb.VoltType.get((byte) 9)), new VoltTable.ColumnInfo("W_ZIP", org.voltdb.VoltType.get((byte) 9)), new VoltTable.ColumnInfo("W_TAX", org.voltdb.VoltType.get((byte) 8)), new VoltTable.ColumnInfo("W_YTD", org.voltdb.VoltType.get((byte) 8)));
    for (int i = 1; i < 21; i++) {
        Object[] row = new Object[] { new Short((short) i), "name_" + i, "street1_" + i, "street2_" + i, "city_" + i, "ma", "zip_" + i, new Double(i), new Double(i) };
        partitioned_table.addRow(row);
    }
    // make a TPCC item table
    VoltTable replicated_table = new VoltTable(new VoltTable.ColumnInfo("I_ID", VoltType.INTEGER), new VoltTable.ColumnInfo("I_IM_ID", VoltType.INTEGER), new VoltTable.ColumnInfo("I_NAME", VoltType.STRING), new VoltTable.ColumnInfo("I_PRICE", VoltType.FLOAT), new VoltTable.ColumnInfo("I_DATA", VoltType.STRING));
    for (int i = 1; i < 21; i++) {
        Object[] row = new Object[] { i, i, "name_" + i, new Double(i), "data_" + i };
        replicated_table.addRow(row);
    }
    try {
        try {
            client.callProcedure("@LoadMultipartitionTable", "WAREHOUSE", upsertMode, partitioned_table);
            fail("ORLY - @LoadMultipartitionTable succeeds on partitioned WAREHOUSE table?");
        } catch (ProcCallException ex) {
            assertTrue(ex.getMessage().contains("LoadMultipartitionTable no longer supports loading partitioned tables"));
        }
        client.callProcedure("@LoadMultipartitionTable", "ITEM", upsertMode, replicated_table);
        // 20 rows per site for the replicated table.  Wait for it...
        int rowcount = 0;
        VoltTable[] results = client.callProcedure("@Statistics", "table", 0).getResults();
        while (rowcount != (20 * SITES * HOSTS)) {
            rowcount = 0;
            results = client.callProcedure("@Statistics", "table", 0).getResults();
            // Check that tables loaded correctly
            while (results[0].advanceRow()) {
                if (results[0].getString("TABLE_NAME").equals("ITEM")) {
                    rowcount += results[0].getLong("TUPLE_COUNT");
                }
            }
        }
        //*enable to debug*/ System.out.println(results[0]);
        // Check that tables loaded correctly
        int foundItem = 0;
        results = client.callProcedure("@Statistics", "table", 0).getResults();
        while (results[0].advanceRow()) {
            if (results[0].getString("TABLE_NAME").equals("ITEM")) {
                ++foundItem;
                //Different values depending on local cluster vs. single process hence ||
                assertEquals(20, results[0].getLong("TUPLE_COUNT"));
            }
        }
        assertEquals(MiscUtils.isPro() ? 6 : 3, foundItem);
        // Table finally loaded fully should mean that index is okay on first read.
        VoltTable indexStats = client.callProcedure("@Statistics", "INDEX", 0).getResults()[0];
        //*enable to debug*/ System.out.println(indexStats);
        long memorySum = 0;
        while (indexStats.advanceRow()) {
            memorySum += indexStats.getLong("MEMORY_ESTIMATE");
        }
        //
        // It takes about a minute to spin through this 1000 times.
        // Should definitely give a 1 second tick time to fire
        //
        long indexMemorySum = 0;
        for (int ii = 0; ii < 1000; ii++) {
            indexMemorySum = 0;
            indexStats = client.callProcedure("@Statistics", "MEMORY", 0).getResults()[0];
            //*enable to debug*/ System.out.println(indexStats);
            while (indexStats.advanceRow()) {
                indexMemorySum += indexStats.getLong("INDEXMEMORY");
            }
            //That is a row count, not memory usage
            boolean success = indexMemorySum != 120;
            if (success) {
                success = memorySum == indexMemorySum;
                if (success) {
                    break;
                }
            }
            Thread.sleep(1);
        }
        //That is a row count, not memory usage
        assertTrue(indexMemorySum != 120);
        assertEquals(memorySum, indexMemorySum);
        //
        // Test once using the current correct hash function,
        // expect no mispartitioned rows
        //
        ClientResponse cr = client.callProcedure("@ValidatePartitioning", 0, null);
        VoltTable hashinatorMatches = cr.getResults()[1];
        while (hashinatorMatches.advanceRow()) {
            assertEquals(1L, hashinatorMatches.getLong("HASHINATOR_MATCHES"));
        }
        VoltTable validateResult = cr.getResults()[0];
        //*enable to debug*/ System.out.println(validateResult);
        while (validateResult.advanceRow()) {
            assertEquals(0L, validateResult.getLong("MISPARTITIONED_ROWS"));
        }
        //
        // Test again with a bad hash function, expect mispartitioned rows
        //
        cr = client.callProcedure("@ValidatePartitioning", 0, new byte[] { 0, 0, 0, 9 });
        hashinatorMatches = cr.getResults()[1];
        while (hashinatorMatches.advanceRow()) {
            assertEquals(0L, hashinatorMatches.getLong("HASHINATOR_MATCHES"));
        }
        validateResult = cr.getResults()[0];
        //*enable to debug*/ System.out.println(validateResult);
        while (validateResult.advanceRow()) {
            if (validateResult.getString("TABLE").equals("NEW_ORDER")) {
                assertTrue(validateResult.getLong("MISPARTITIONED_ROWS") > 0);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltTable(org.voltdb.VoltTable) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) Random(java.util.Random) NullCallback(org.voltdb.client.NullCallback) Client(org.voltdb.client.Client) ProcCallException(org.voltdb.client.ProcCallException)

Example 15 with NullCallback

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

the class OneShotBenchmark method runBenchmark.

/**
     * Core benchmark code.
     * Connect. Initialize. Run the loop. Cleanup. Print Results.
     *
     * @throws Exception if anything unexpected happens.
     */
public void runBenchmark() throws Exception {
    System.out.print(HORIZONTAL_RULE);
    System.out.println(" Setup & Initialization");
    System.out.println(HORIZONTAL_RULE);
    // connect to one or more servers, loop until success
    connect(client, config.servers);
    connect(mpClient, config.servers);
    // preload keys if requested
    System.out.println();
    if (config.preload) {
        System.out.println("Preloading data store...");
        for (int i = 0; i < config.poolsize; i++) {
            client.callProcedure(new NullCallback(), "Put", String.format(processor.KeyFormat, i), processor.generateForStore().getStoreValue());
        }
        client.drain();
        System.out.println("Preloading complete.\n");
    }
    System.out.print(HORIZONTAL_RULE);
    System.out.println("Starting Benchmark");
    System.out.println(HORIZONTAL_RULE);
    // create/start the requested number of threads
    ArrayList<Thread> kvThreads = new ArrayList<Thread>();
    for (int i = 0; i < config.threads; ++i) {
        kvThreads.add(new Thread(new KVThread(client, true)));
    }
    for (int i = 0; i < config.mpthreads; ++i) {
        kvThreads.add(new Thread(new KVThread(mpClient, false)));
    }
    for (Thread thread : kvThreads) {
        thread.start();
    }
    // Run the benchmark loop for the requested warmup time
    System.out.println("Warming up...");
    Thread.sleep(1000l * config.warmup);
    // signal to threads to end the warmup phase
    warmupComplete.set(true);
    // reset the stats after warmup
    fullStatsContext.fetchAndResetBaseline();
    periodicStatsContext.fetchAndResetBaseline();
    mpFullStatsContext.fetchAndResetBaseline();
    // print periodic statistics to the console
    benchmarkStartTS = System.currentTimeMillis();
    schedulePeriodicStats();
    // Run the benchmark loop for the requested warmup time
    System.out.println("\nRunning benchmark...");
    Thread.sleep(1000l * config.duration);
    // stop the threads
    benchmarkComplete.set(true);
    // cancel periodic stats printing
    timer.cancel();
    // block until all outstanding txns return
    client.drain();
    mpClient.drain();
    // join on the threads
    for (Thread t : kvThreads) {
        t.join();
    }
    // print the summary results
    printResults();
    // close down the client connections
    client.close();
}
Also used : ArrayList(java.util.ArrayList) NullCallback(org.voltdb.client.NullCallback)

Aggregations

NullCallback (org.voltdb.client.NullCallback)19 IOException (java.io.IOException)6 ProcCallException (org.voltdb.client.ProcCallException)4 VoltTable (org.voltdb.VoltTable)3 ClientResponse (org.voltdb.client.ClientResponse)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Client (org.voltdb.client.Client)2 GeographyPointValue (org.voltdb.types.GeographyPointValue)2 GeographyValue (org.voltdb.types.GeographyValue)2 TimestampType (org.voltdb.types.TimestampType)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1