Search in sources :

Example 36 with ClientResponse

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

the class TestAdhocDropTable method testDropTableBasic.

@Test
public void testDropTableBasic() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table BLAH (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create table DROPME (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID))\n;" + "create table DROPME_R (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));");
    builder.addPartitionInfo("BLAH", "ID");
    builder.addPartitionInfo("DROPME", "ID");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        // Check basic drop of partitioned table that should work.
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("DROPME"));
        // eng7297, start with 6 rows in @Statistics table (one per table per site)
        VoltTable stats = getStatWaitOnRowCount("TABLE", 6);
        assertEquals(6, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 6);
        assertEquals(6, stats.getRowCount());
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("DROPME"));
        // eng7297, now only 4 rows in @Statistics table (one per table per site)
        stats = getStatWaitOnRowCount("TABLE", 4);
        assertEquals(4, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 4);
        assertEquals(4, stats.getRowCount());
        // Check basic drop of replicated table that should work.
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("DROPME_R"));
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME_R;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("DROPME_R"));
        // eng7297, now only 2 rows in @Statistics table (one per table per site)
        stats = getStatWaitOnRowCount("TABLE", 2);
        assertEquals(2, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 2);
        assertEquals(2, stats.getRowCount());
        // Verify dropping a table that doesn't exist fails
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME;");
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("object not found: DROPME"));
            threw = true;
        }
        assertTrue("Dropping bad table should have failed", threw);
        // Verify dropping a table that doesn't exist is fine with IF EXISTS
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME IF EXISTS;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertFalse("Dropping bad table with IF EXISTS should not have failed", threw);
        // ENG-7297, Drop the last table and make sure that the statistics are correct
        try {
            m_client.callProcedure("@AdHoc", "drop table BLAH;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("BLAH"));
        // eng7297, now should be zero rows in the stats
        stats = getStatWaitOnRowCount("TABLE", 0);
        assertEquals(0, stats.getRowCount());
        stats = getStatWaitOnRowCount("INDEX", 0);
        assertEquals(0, stats.getRowCount());
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 37 with ClientResponse

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

the class TestAdhocDropTable method testDropTableWithIndexesAndProcedures.

@Test
public void testDropTableWithIndexesAndProcedures() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table BLAH (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create table VIEWBASE (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create table DROPME (" + "ID int default 0 not null, " + "VAL varchar(32) default null," + "PRIMARY KEY(ID));\n" + "create assumeunique index pkey_idx on DROPME(VAL);\n" + "create view BLAT (VAL, TOTAL) as select VAL, COUNT(*) from VIEWBASE group by VAL;\n");
    builder.addPartitionInfo("BLAH", "ID");
    builder.addPartitionInfo("DROPME", "ID");
    builder.addStmtProcedure("BLERG", "select * from BLAH where ID = ?");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        // Check basic drop of table with an index on it
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("DROPME"));
        resp = m_client.callProcedure("@SystemCatalog", "INDEXINFO");
        System.out.println(resp.getResults()[0]);
        assertTrue(findIndexInSystemCatalogResults("PKEY_IDX"));
        try {
            m_client.callProcedure("@AdHoc", "drop table DROPME;");
        } catch (ProcCallException pce) {
            fail("drop table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("DROPME"));
        resp = m_client.callProcedure("@SystemCatalog", "INDEXINFO");
        System.out.println(resp.getResults()[0]);
        assertFalse(findIndexInSystemCatalogResults("PKEY_IDX"));
        // Verify that we can't drop a table that a procedure depends on
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("BLAH"));
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table BLAH;");
        } catch (ProcCallException pce) {
            // The error message is really confusing for this case, not sure
            // how to make it better though
            pce.printStackTrace();
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a table used in a procedure", threw);
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("BLAH"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table VIEWBASE;");
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertTrue("Shouldn't be able to drop a table used in a view", threw);
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("VIEWBASE"));
        assertTrue(findTableInSystemCatalogResults("BLAT"));
        try {
            m_client.callProcedure("@AdHoc", "drop table VIEWBASE cascade;");
        } catch (ProcCallException pce) {
            fail("Should be able to drop table and view with cascade");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertFalse(findTableInSystemCatalogResults("VIEWBASE"));
        assertFalse(findTableInSystemCatalogResults("BLAT"));
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 38 with ClientResponse

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

the class TestAdhocCreateTable method testMultiLineCreateTable.

// Test creating a table when we feed a statement containing newlines.
// I honestly didn't expect this to work yet --izzy
@Test
public void testMultiLineCreateTable() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("--dont care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        // Check basic drop of partitioned table that should work.
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertFalse(findTableInSystemCatalogResults("FOO"));
        System.out.println(resp.getResults()[0]);
        try {
            m_client.callProcedure("@AdHoc", "create table FOO (\n" + "ID int default 0 not null,\n" + "VAL varchar(32 bytes)\n" + ");");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("create table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("FOO"));
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 39 with ClientResponse

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

the class TestAdhocCreateTable method testCreatePartitionedTable.

@Test
public void testCreatePartitionedTable() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("--dont care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        // Check basic create of partitioned table that should work.
        ClientResponse resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertFalse(findTableInSystemCatalogResults("FOO"));
        System.out.println(resp.getResults()[0]);
        try {
            m_client.callProcedure("@AdHoc", "create table FOO (\n" + "ID int default 0 not null,\n" + "VAL varchar(32 bytes),\n" + "VAL2 bigint not null assumeunique\n" + ");\n" + "partition table FOO on column ID;\n");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("create table should have succeeded");
        }
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        System.out.println(resp.getResults()[0]);
        assertTrue(findTableInSystemCatalogResults("FOO"));
        assertTrue(isColumnPartitionColumn("FOO", "ID"));
        // This, however, not being batched, won't work until the empty table
        // check goes in.
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertFalse(findTableInSystemCatalogResults("BAR"));
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "create table BAR (\n" + "ID int default 0 not null,\n" + "VAL varchar(32 bytes),\n" + // (starts replicated) and partition it in a separate @AdHoc call
            "VAL2 bigint not null assumeunique,\n" + "constraint blerg assumeunique(VAL)\n" + ");\n");
            m_client.callProcedure("@AdHoc", "partition table BAR on column ID;\n");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            threw = true;
        }
        assertFalse("Failed to partition an already created table.", threw);
        resp = m_client.callProcedure("@SystemCatalog", "TABLES");
        assertTrue(findTableInSystemCatalogResults("BAR"));
        assertTrue(isColumnPartitionColumn("BAR", "ID"));
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 40 with ClientResponse

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

the class TestLiveDDLSchemaSwitch method testReplicaWithAdhocDDL.

@Test
public void testReplicaWithAdhocDDL() throws Exception {
    generateCatalogsAndDeployments(true);
    // Fire up a cluster with no catalog
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = m_pathToOtherCatalog;
    config.m_pathToDeployment = m_pathToReplicaDeployment;
    try {
        startSystem(config);
        // UAC with schema should fail
        assertFalse(findTableInSystemCatalogResults("FOO"));
        boolean threw = false;
        try {
            m_client.updateApplicationCatalog(new File(m_pathToCatalog), null);
        } catch (ProcCallException pce) {
            threw = true;
            assertTrue(pce.getMessage().contains("Cluster is configured to use AdHoc DDL"));
        }
        assertTrue("@UAC should have failed", threw);
        assertFalse(findTableInSystemCatalogResults("FOO"));
        // deployment-only UAC should fail
        threw = false;
        try {
            m_client.updateApplicationCatalog(null, new File(m_pathToOtherReplicaDeployment));
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertFalse("@UAC should should succeed with just a deployment file", threw);
        assertEquals(getHeartbeatTimeout(), 6);
        // Adhoc DDL should be rejected
        assertFalse(findTableInSystemCatalogResults("BAR"));
        try {
            m_client.callProcedure("@AdHoc", "create table BAR (ID integer, VAL varchar(50));");
        } catch (ProcCallException pce) {
            fail("@AdHoc should succeed on replica cluster");
        }
        assertTrue(findTableInSystemCatalogResults("BAR"));
        // Adhoc DML updates should be rejected in the replica
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "insert into BAR values (100, 'ABC');");
        } catch (ProcCallException pce) {
            threw = true;
            System.out.println(pce.getMessage());
            assertTrue(pce.getMessage().contains("Write procedure @AdHoc_RW_MP is not allowed in replica cluster"));
        }
        assertTrue("Adhoc DDL should have failed", threw);
        // @UpdateClasses should be rejected
        assertFalse(findClassInSystemCatalog("org.voltdb_testprocs.fullddlfeatures.testImportProc"));
        threw = false;
        try {
            InMemoryJarfile jarfile = new InMemoryJarfile();
            VoltCompiler comp = new VoltCompiler(false);
            comp.addClassToJar(jarfile, org.voltdb_testprocs.fullddlfeatures.testImportProc.class);
            m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        } catch (ProcCallException pce) {
            threw = true;
            assertTrue(pce.getMessage().contains("Write procedure @UpdateClasses is not allowed"));
        }
        assertFalse("@UpdateClasses should have worked", threw);
        assertTrue(findClassInSystemCatalog("org.voltdb_testprocs.fullddlfeatures.testImportProc"));
        // adhoc queries still work
        ClientResponse result = m_client.callProcedure("@AdHoc", "select * from baz;");
        assertEquals(ClientResponse.SUCCESS, result.getStatus());
        // Promote, should behave like the original master test
        m_client.callProcedure("@Promote");
        verifyMasterWithAdhocDDL();
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) 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