Search in sources :

Example 6 with ClientResponse

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

the class LogAnalyzer method analyzeOperation.

public void analyzeOperation(String name) {
    int seconds = 10;
    long minuteBeforeNow = System.currentTimeMillis() - seconds * 1000;
    ClientResponse response = null;
    try {
        response = m_voltClient.callProcedure("FetchLogRowsProcedure", minuteBeforeNow, name);
    } catch (ProcCallException | IOException e) {
        System.out.println("Error executing analyzer stmt: " + e.getMessage());
        e.printStackTrace();
        return;
    }
    if (response.getStatus() != ClientResponse.SUCCESS) {
        System.out.println("Procedure execution failed with status " + response.getStatus());
        return;
    }
    VoltTable[] results = response.getResults();
    if (results.length == 0 || results[0].getRowCount() == 0) {
        System.out.println("No entries found for " + name + " in the last " + seconds + " seconds");
        return;
    }
    int count = 0;
    long totalTime = 0;
    int min = 0;
    int max = 0;
    System.out.println("rowCount=" + results[0].getRowCount());
    for (int i = 0; i < results[0].getRowCount(); i++) {
        VoltTableRow row = results[0].fetchRow(i);
        int time = getTimeFromLogMesg((String) row.get(0, VoltType.STRING));
        if (time >= 0) {
            min = Math.min(min, time);
            max = Math.max(max, time);
            totalTime += time;
            count++;
        }
    }
    if (count == 0) {
        System.out.println("No good log entries found for " + name + " in the last " + seconds + " seconds");
    } else {
        System.out.println(String.format("Operation time for %s in the last %d seconds: min=%d, max=%d, avg=%f", name, seconds, min, max, totalTime * 1.0 / count));
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException)

Example 7 with ClientResponse

use of org.voltdb.client.ClientResponse 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 {
    log.info(HORIZONTAL_RULE);
    log.info(" Setup & Initialization");
    log.info(HORIZONTAL_RULE);
    // connect to one or more servers, loop until success
    connect();
    VoltTable[] rowResults = null;
    VoltTable[] replicatedResults = null;
    boolean succeeded = false;
    // If server fails during initialization, try again
    while (!succeeded) {
        Client initClient = clients.get(0);
        try {
            // initialize using synchronous call
            initClient.callProcedure("Initialize");
            ClientResponse rowResp = initClient.callProcedure("getLastRow");
            rowResults = rowResp.getResults();
            assert (rowResp.getStatus() == ClientResponse.SUCCESS);
            ClientResponse replicatedRowResp = initClient.callProcedure("getLastReplicatedRow");
            replicatedResults = replicatedRowResp.getResults();
            assert (replicatedRowResp.getStatus() == ClientResponse.SUCCESS);
            succeeded = true;
        } catch (Exception e) {
            log.error("Exception on init. Will sleep.", e);
            sleepUntilConnected(initClient, System.currentTimeMillis() + config.duration * 1000);
        }
    }
    // total of 127 cids
    final int cidCount = 127;
    final long windowPerCid = config.windowsize / cidCount;
    // rids per cid
    final Map<Integer, Long> rids = new HashMap<Integer, Long>();
    // reset all cids to 0 and initialize inFlight queues
    for (int i = -1; i < cidCount; i++) {
        rids.put(i, 0l);
    }
    // populate the rids with values from previous run
    while (rowResults[0].advanceRow()) {
        long cid = rowResults[0].getLong("cid");
        long last_rid = rowResults[0].getLong("last_rid");
        rids.put((int) cid, last_rid + 1);
    }
    rids.put(-1, replicatedResults[0].asScalarLong() + 1);
    log.info(HORIZONTAL_RULE);
    log.info("Starting Benchmark");
    log.info(HORIZONTAL_RULE);
    java.util.Random r = new java.util.Random(2);
    // 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
    final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration);
    while (benchmarkEndTime > System.currentTimeMillis()) {
        int cid;
        if (r.nextDouble() < config.multisingleratio) {
            // MP uses cid -1
            cid = -1;
        } else {
            cid = (byte) r.nextInt(cidCount);
        }
        long rid = rids.get(cid);
        // txns for the same cid go to the same client
        Client client = null;
        try {
            if (cid == -1) {
                client = clients.get(0);
                // skip this work if the client is not connected
                if (client.getConnectedHostList().size() == 0) {
                    continue;
                }
                // update the replicated table
                try {
                    client.callProcedure(new updateReplicatedCallback(), "updateReplicated", rid);
                } catch (NoConnectionsException e) {
                    log.error("ClientThread got NoConnectionsException on updateReplicated proc call.");
                }
            } else {
                client = clients.get(cid % clients.size());
                // skip this work if the client is not connected
                if (client.getConnectedHostList().size() == 0) {
                    continue;
                }
                // asynchronously call the "doTxn" procedure
                try {
                    client.callProcedure(new doTxnCallback(), "doTxn", cid, rid, rid > windowPerCid ? rid - windowPerCid : 0, processor.generateForStore().getStoreValue());
                } catch (NoConnectionsException e) {
                    log.error("ClientThread got NoConnectionsException on doTxn proc call.");
                }
            }
        } catch (Exception e) {
            log.error("Benchark had a unexpected exception", e);
            System.exit(-1);
        }
        rids.put(cid, rid + 1);
    }
    // cancel periodic stats printing
    timer.cancel();
    shutdown.set(true);
    /* don't wait for a proper cleanup just go away the system may not be healthy -pr
        // block until all outstanding txns return
        for (Client client : clients) {
            client.drain();
            client.close();
        }*/
    log.info(HORIZONTAL_RULE);
    log.info("Benchmark Complete");
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) HashMap(java.util.HashMap) VoltTable(org.voltdb.VoltTable) NoConnectionsException(org.voltdb.client.NoConnectionsException) NoConnectionsException(org.voltdb.client.NoConnectionsException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Client(org.voltdb.client.Client)

Example 8 with ClientResponse

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

the class TestUpdateClasses method testRoleControl.

@Test
public void testRoleControl() throws Exception {
    System.out.println("\n\n-----\n testRoleControl \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    RoleInfo[] groups = new RoleInfo[] { new RoleInfo("adhoc", true, false, false, false, false, false) };
    UserInfo[] users = new UserInfo[] { new UserInfo("adhocuser", "adhocuser", new String[] { "adhoc" }), new UserInfo("sysuser", "sysuser", new String[] { "ADMINISTRATOR" }) };
    builder.addRoles(groups);
    builder.addUsers(users);
    // Test defines its own ADMIN user
    builder.setSecurityEnabled(true, false);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    Client auth_client = null;
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        // Default client auth is going to fail, catch and keep chugging
        try {
            startSystem(config);
        } catch (IOException ioe) {
            assertTrue(ioe.getMessage().contains("Authentication rejected"));
        }
        m_client.close();
        // reconnect m_client with auth that will connect but no sysproc powers
        ClientConfig bad_config = new ClientConfig("adhocuser", "adhocuser");
        m_client = ClientFactory.createClient(bad_config);
        m_client.createConnection("localhost");
        // Need a client with the right auth
        ClientConfig auth_config = new ClientConfig("sysuser", "sysuser");
        auth_client = ClientFactory.createClient(auth_config);
        auth_client.createConnection("localhost");
        ClientResponse resp;
        resp = auth_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = auth_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("does not have admin permission"));
            threw = true;
        }
        assertTrue(threw);
        resp = auth_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        // Are we still like summer vacation?
        resp = auth_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
    } finally {
        if (auth_client != null) {
            auth_client.close();
        }
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) VoltCompiler(org.voltdb.compiler.VoltCompiler) RoleInfo(org.voltdb.compiler.VoltProjectBuilder.RoleInfo) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 9 with ClientResponse

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

the class TestUpdateClasses method testBasic.

@Test
public void testBasic() throws Exception {
    System.out.println("\n\n-----\n testBasic \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    // Add a deployment file just to have something other than classes in the jar
    jarfile.put("deployment.xml", new File(pathToDeployment));
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        ClientResponse resp;
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        // First, some tests of incorrect parameters
        // only 1 param
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("UpdateClasses system procedure requires exactly two parameters"));
            threw = true;
        }
        assertTrue(threw);
        // wrong jarfile param type
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", 10L, null);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("UpdateClasses system procedure takes the jarfile bytes as a byte array"));
            threw = true;
        }
        assertTrue(threw);
        // wrong delete string param type
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), 10L);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("UpdateClasses system procedure takes the list of classes"));
            threw = true;
        }
        assertTrue(threw);
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        // Are we still like summer vacation?
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
        // Can we turn it into a procedure?
        resp = m_client.callProcedure("@AdHoc", "create procedure from class " + PROC_CLASSES[0].getCanonicalName() + ";");
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        results = resp.getResults()[0];
        assertEquals(10L, results.asScalarLong());
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) VoltCompiler(org.voltdb.compiler.VoltCompiler) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 10 with ClientResponse

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

the class TestUpdateClasses method testCollidingClasses.

@Test
public void testCollidingClasses() throws Exception {
    System.out.println("\n\n-----\n testCollidingProc \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        ClientResponse resp;
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        // Are we still like summer vacation?
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
        // Can we turn it into a procedure?
        resp = m_client.callProcedure("@AdHoc", "create procedure from class " + PROC_CLASSES[0].getCanonicalName() + ";");
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        results = resp.getResults()[0];
        assertEquals(10L, results.asScalarLong());
        // now, let's collide identically simpleName'd classes
        InMemoryJarfile boom = new InMemoryJarfile();
        for (Class<?> clazz : COLLIDING_CLASSES) {
            VoltCompiler comp = new VoltCompiler(false);
            comp.addClassToJar(boom, clazz);
        }
        resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        // should be okay to have classnames with same simplename
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(5, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", COLLIDING_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
    } finally {
        teardownSystem();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Aggregations

ClientResponse (org.voltdb.client.ClientResponse)385 VoltTable (org.voltdb.VoltTable)195 Client (org.voltdb.client.Client)184 ProcCallException (org.voltdb.client.ProcCallException)107 IOException (java.io.IOException)54 NoConnectionsException (org.voltdb.client.NoConnectionsException)35 Test (org.junit.Test)32 ProcedureCallback (org.voltdb.client.ProcedureCallback)32 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)29 Configuration (org.voltdb.VoltDB.Configuration)28 File (java.io.File)19 Timestamp (java.sql.Timestamp)16 VoltDB (org.voltdb.VoltDB)16 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)16 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 JSONException (org.json_voltpatches.JSONException)11 BigDecimal (java.math.BigDecimal)10 ExecutionException (java.util.concurrent.ExecutionException)10 ClientResponseImpl (org.voltdb.ClientResponseImpl)10 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)9