Search in sources :

Example 51 with ProcCallException

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

the class SQLCommand method loadStoredProcedures.

private static void loadStoredProcedures(Map<String, Map<Integer, List<String>>> procedures, Map<String, List<Boolean>> classlist) {
    VoltTable procs = null;
    VoltTable params = null;
    VoltTable classes = null;
    try {
        procs = m_client.callProcedure("@SystemCatalog", "PROCEDURES").getResults()[0];
        params = m_client.callProcedure("@SystemCatalog", "PROCEDURECOLUMNS").getResults()[0];
        classes = m_client.callProcedure("@SystemCatalog", "CLASSES").getResults()[0];
    } catch (NoConnectionsException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    } catch (ProcCallException e) {
        e.printStackTrace();
        return;
    }
    Map<String, Integer> proc_param_counts = Collections.synchronizedMap(new HashMap<String, Integer>());
    while (params.advanceRow()) {
        String this_proc = params.getString("PROCEDURE_NAME");
        Integer curr_val = proc_param_counts.get(this_proc);
        if (curr_val == null) {
            curr_val = 1;
        } else {
            ++curr_val;
        }
        proc_param_counts.put(this_proc, curr_val);
    }
    params.resetRowPosition();
    Set<String> userProcs = new HashSet<>();
    while (procs.advanceRow()) {
        String proc_name = procs.getString("PROCEDURE_NAME");
        userProcs.add(proc_name);
        Integer param_count = proc_param_counts.get(proc_name);
        ArrayList<String> this_params = new ArrayList<>();
        // prepopulate it to make sure the size is right
        if (param_count != null) {
            for (int i = 0; i < param_count; i++) {
                this_params.add(null);
            }
        } else {
            param_count = 0;
        }
        HashMap<Integer, List<String>> argLists = new HashMap<>();
        argLists.put(param_count, this_params);
        procedures.put(proc_name, argLists);
    }
    for (String proc_name : new ArrayList<>(procedures.keySet())) {
        if (!proc_name.startsWith("@") && !userProcs.contains(proc_name)) {
            procedures.remove(proc_name);
        }
    }
    classlist.clear();
    while (classes.advanceRow()) {
        String classname = classes.getString("CLASS_NAME");
        boolean isProc = (classes.getLong("VOLT_PROCEDURE") == 1L);
        boolean isActive = (classes.getLong("ACTIVE_PROC") == 1L);
        if (!classlist.containsKey(classname)) {
            List<Boolean> stuff = Collections.synchronizedList(new ArrayList<Boolean>());
            stuff.add(isProc);
            stuff.add(isActive);
            classlist.put(classname, stuff);
        }
    }
    // Retrieve the parameter types.  Note we have to do some special checking
    // for array types.  ENG-3101
    params.resetRowPosition();
    while (params.advanceRow()) {
        Map<Integer, List<String>> argLists = procedures.get(params.getString("PROCEDURE_NAME"));
        assert (argLists.size() == 1);
        List<String> this_params = argLists.values().iterator().next();
        int idx = (int) params.getLong("ORDINAL_POSITION") - 1;
        String param_type = params.getString("TYPE_NAME").toLowerCase();
        // Detect if this parameter is supposed to be an array.  It's kind of clunky, we have to
        // look in the remarks column...
        String param_remarks = params.getString("REMARKS");
        if (null != param_remarks) {
            param_type += (param_remarks.equalsIgnoreCase("ARRAY_PARAMETER") ? "_array" : "");
        }
        this_params.set(idx, param_type);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) NoConnectionsException(org.voltdb.client.NoConnectionsException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ProcCallException(org.voltdb.client.ProcCallException) HashSet(java.util.HashSet)

Example 52 with ProcCallException

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

the class TestDDLFeatures method testAlterTableAddConstraint.

@Test
public void testAlterTableAddConstraint() throws Exception {
    ClientResponse resp;
    boolean threw;
    // Test for T40
    assertTrue(findTableInSystemCatalogResults("T40"));
    resp = m_client.callProcedure("T40.insert", 1, 2);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T40.insert", 1, 2);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertTrue("Shouldn't violate UNIQUE constraint", threw);
    //      ENG-7321 - bug with PRIMARY KEY and verification of generated DDL
    //        // Test for T41
    //        assertTrue(findTableInSystemCatalogResults("T41"));
    //        resp = m_client.callProcedure("T41.insert", 1);
    //        assertEquals(resp.getResults()[0].getRowCount(), 1);
    //
    //        threw = false;
    //        try {
    //            resp = m_client.callProcedure("T41.insert", 1);
    //        } catch (ProcCallException pce) {
    //            pce.printStackTrace();
    //            threw = true;
    //        }
    //        assertEquals(resp.getResults()[0].getRowCount(), 1);
    //        assertTrue("Shouldn't violate PRIMARY KEY constraint", threw);
    ////        assertEquals(indexedColumnCount("T41"), 1);
    // Test for T42
    assertTrue(findTableInSystemCatalogResults("T42"));
    resp = m_client.callProcedure("T42.insert", 1, 2);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T42.insert", 1, 2);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertTrue("Shouldn't violate ASSUMEUNIQUE constraint", threw);
    // Test for T42A
    assertTrue(findTableInSystemCatalogResults("T42A"));
    resp = m_client.callProcedure("T42A.insert", 1, 2, 3);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T42A.insert", 1, 2, 3);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertTrue("Shouldn't violate ASSUMEUNIQUE constraint", threw);
    // Test for T43
    assertTrue(findTableInSystemCatalogResults("T43"));
    resp = m_client.callProcedure("T43.insert", 1);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T43.insert", 2);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertTrue("Shouldn't violate LIMIT PARTITION ROW constraint", threw);
    assertEquals(indexedColumnCount("T43"), 0);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 53 with ProcCallException

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

the class TestDDLFeatures method testAlterTableDropConstraint.

@Test
public void testAlterTableDropConstraint() throws Exception {
    ClientResponse resp;
    boolean threw;
    // Test for T35
    assertTrue(findTableInSystemCatalogResults("T35"));
    resp = m_client.callProcedure("T35.insert", 1, 2);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T35.insert", 1, 3);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertFalse("Shouldn't violate PRIMARY KEY constraint", threw);
    threw = false;
    try {
        m_client.callProcedure("T35.insert", 2, 2);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertTrue("Shouldn't violate UNIQUE constraint", threw);
    assertEquals(indexedColumnCount("T35"), 1);
    // Test for T35A
    assertTrue(findTableInSystemCatalogResults("T35A"));
    resp = m_client.callProcedure("T35A.insert", 1);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T35A.insert", 1);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertFalse("Shouldn't violate LIMIT PARTITION ROWS constraint", threw);
    assertEquals(indexedColumnCount("T35A"), 0);
    // Test for T36
    assertTrue(findTableInSystemCatalogResults("T36"));
    resp = m_client.callProcedure("T36.insert", 1);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T36.insert", 1);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertFalse("Shouldn't violate PRIMARY KEY constraint", threw);
    assertEquals(indexedColumnCount("T36"), 0);
    // Test for T37
    assertTrue(findTableInSystemCatalogResults("T37"));
    resp = m_client.callProcedure("T37.insert", 1);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T37.insert", 1);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertFalse("Shouldn't violate UNIQUE constraint", threw);
    assertEquals(indexedColumnCount("T37"), 0);
    // Test for T38
    assertTrue(findTableInSystemCatalogResults("T38"));
    resp = m_client.callProcedure("T38.insert", 1);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T38.insert", 1);
    } catch (ProcCallException pce) {
        threw = true;
    }
    assertFalse("Shouldn't violate UNIQUE constraint", threw);
    assertEquals(indexedColumnCount("T38"), 0);
    // Test for T39
    assertTrue(findTableInSystemCatalogResults("T39"));
    resp = m_client.callProcedure("T39.insert", 1);
    assertEquals(resp.getResults()[0].getRowCount(), 1);
    threw = false;
    try {
        m_client.callProcedure("T39.insert", 2);
    } catch (ProcCallException pce) {
        pce.printStackTrace();
        threw = true;
    }
    assertFalse("Shouldn't violate LIMIT PARTITION ROW constraint", threw);
    assertEquals(indexedColumnCount("T39"), 0);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 54 with ProcCallException

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

the class TestCatalogUpdateSuite method testUpdateHonkingBigCatalog.

public void testUpdateHonkingBigCatalog() throws IOException, ProcCallException, InterruptedException {
    System.out.println("\n\n-----\n testUpdateHonkingBigCatalog\n");
    System.out.printf("jar: %s (%.2f MB)\n", hugeCatalogJarPath, new File(hugeCatalogJarPath).length() / 1048576.0);
    System.out.printf("compile: %.2f seconds (%.2f/second)\n", hugeCompileElapsed, HUGE_TABLES / hugeCompileElapsed);
    long t = System.currentTimeMillis();
    Client client = getClient();
    loadSomeData(client, 0, 10);
    assertCallbackSuccess(client);
    try {
        VoltTable[] results = client.updateApplicationCatalog(new File(hugeCatalogJarPath), new File(hugeCatalogXMLPath)).getResults();
        assertTrue(results.length == 1);
    } catch (ProcCallException e) {
        fail(String.format("@UpdateApplicationCatalog: ProcCallException: %s", e.getLocalizedMessage()));
    }
    hugeTestElapsed = (System.currentTimeMillis() - t) / 1000.0;
    System.out.printf("test: %.2f seconds (%.2f/second)\n", hugeTestElapsed, HUGE_TABLES / hugeTestElapsed);
    System.out.println("-----\n\n");
}
Also used : Client(org.voltdb.client.Client) File(java.io.File) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 55 with ProcCallException

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

the class TestCatalogUpdateSuite method testUpdate.

public void testUpdate() throws Exception {
    Client client = getClient();
    String newCatalogURL;
    String deploymentURL;
    VoltTable[] results;
    CatTestCallback callback;
    loadSomeData(client, 0, 25);
    assertCallbackSuccess(client);
    negativeTests(client);
    assertCallbackSuccess(client);
    // asynchronously call some random inserts
    loadSomeData(client, 25, 25);
    assertCallbackSuccess(client);
    // add a procedure "InsertOrderLineBatched"
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.xml");
    callback = new CatTestCallback(ClientResponse.SUCCESS);
    client.updateApplicationCatalog(callback, new File(newCatalogURL), new File(deploymentURL));
    // don't care if this succeeds or fails.
    // calling the new proc before the cat change returns is not guaranteed to work
    // we just hope it doesn't crash anything
    int x = 3;
    SyncCallback cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    // make sure the previous catalog change has completed
    assertCallbackSuccess(client);
    // now calling the new proc better work
    x = 2;
    client.callProcedure(org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    loadSomeData(client, 50, 5);
    assertCallbackSuccess(client);
    // this is a do nothing change... shouldn't affect anything
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.xml");
    results = client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL)).getResults();
    assertTrue(results.length == 1);
    assertCallbackSuccess(client);
    // now calling the new proc better work
    x = 4;
    client.callProcedure(org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    loadSomeData(client, 55, 5);
    // remove the procedure we just added async
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.xml");
    callback = new CatTestCallback(ClientResponse.SUCCESS);
    client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
    // don't care if this works now
    x = 4;
    cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    // make sure the previous catalog change has completed
    assertCallbackSuccess(client);
    // now calling the new proc better fail
    x = 5;
    cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    assertNotSame(cb.getResponse().getStatus(), ClientResponse.SUCCESS);
    loadSomeData(client, 60, 5);
    // change the insert new order procedure
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-conflict.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-conflict.xml");
    results = client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL)).getResults();
    assertTrue(results.length == 1);
    // call the new proc and make sure the one we want gets run
    results = client.callProcedure(InsertNewOrder.class.getSimpleName(), 100, 100, 100, 100, (short) 100, 100, 1.0, "a").getResults();
    assertEquals(1, results.length);
    assertEquals(1776, results[0].asScalarLong());
    // load a big catalog change just to make sure nothing fails horribly
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-many.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-many.xml");
    results = client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL)).getResults();
    assertTrue(results.length == 1);
    loadSomeData(client, 65, 5);
    //Check that if a catalog update blocker exists the catalog update fails
    ZooKeeper zk = ZKUtil.getClient(((LocalCluster) m_config).zkinterface(0), 10000, new HashSet<Long>());
    final String catalogUpdateBlockerPath = zk.create(VoltZK.elasticJoinActiveBlocker, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
    try {
        /*
             * Update the catalog and expect failure
             */
        newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.jar");
        deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.xml");
        boolean threw = false;
        try {
            client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
        } catch (ProcCallException e) {
            e.printStackTrace();
            threw = true;
        }
        assertTrue(threw);
    } finally {
        zk.delete(catalogUpdateBlockerPath, -1);
    }
    //Expect success
    client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
    assertCallbackSuccess(client);
    assertTrue(true);
}
Also used : VoltTable(org.voltdb.VoltTable) SyncCallback(org.voltdb.client.SyncCallback) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) TimestampType(org.voltdb.types.TimestampType) Client(org.voltdb.client.Client) File(java.io.File) InsertNewOrder(org.voltdb.benchmark.tpcc.procedures.InsertNewOrder) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

ProcCallException (org.voltdb.client.ProcCallException)240 Client (org.voltdb.client.Client)151 VoltTable (org.voltdb.VoltTable)120 ClientResponse (org.voltdb.client.ClientResponse)92 IOException (java.io.IOException)82 NoConnectionsException (org.voltdb.client.NoConnectionsException)55 Test (org.junit.Test)44 Configuration (org.voltdb.VoltDB.Configuration)41 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)36 File (java.io.File)21 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)19 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 VoltDB (org.voltdb.VoltDB)10 VoltTableRow (org.voltdb.VoltTableRow)10 Timestamp (java.sql.Timestamp)5 TimestampType (org.voltdb.types.TimestampType)5 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 HashSet (java.util.HashSet)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3