Search in sources :

Example 11 with CatalogContext

use of org.voltdb.CatalogContext in project voltdb by VoltDB.

the class Site method updateCatalog.

/**
     * Update the catalog.  If we're the MPI, don't bother with the EE.
     */
public boolean updateCatalog(String diffCmds, CatalogContext context, CatalogSpecificPlanner csp, boolean requiresSnapshotIsolationboolean, boolean isMPI, long uniqueId, long spHandle, boolean requireCatalogDiffCmdsApplyToEE, boolean requiresNewExportGeneration) {
    CatalogContext oldContext = m_context;
    m_context = context;
    m_ee.setBatchTimeout(m_context.cluster.getDeployment().get("deployment").getSystemsettings().get("systemsettings").getQuerytimeout());
    m_loadedProcedures.loadProcedures(m_context, csp, false);
    if (isMPI) {
        // the rest of the work applies to sites with real EEs
        return true;
    }
    if (requireCatalogDiffCmdsApplyToEE == false) {
        // empty diff cmds for the EE to apply, so skip the JNI call
        hostLog.info("Skipped applying diff commands on EE.");
        return true;
    }
    CatalogMap<Table> tables = m_context.catalog.getClusters().get("cluster").getDatabases().get("database").getTables();
    boolean DRCatalogChange = false;
    for (Table t : tables) {
        if (t.getIsdred()) {
            DRCatalogChange |= diffCmds.contains("tables#" + t.getTypeName());
            if (DRCatalogChange) {
                break;
            }
        }
    }
    if (!DRCatalogChange) {
        // Check against old catalog for deletions
        CatalogMap<Table> oldTables = oldContext.catalog.getClusters().get("cluster").getDatabases().get("database").getTables();
        for (Table t : oldTables) {
            if (t.getIsdred()) {
                DRCatalogChange |= diffCmds.contains(CatalogDiffEngine.getDeleteDiffStatement(t, "tables"));
                if (DRCatalogChange) {
                    break;
                }
            }
        }
    }
    //
    if (requiresSnapshotIsolationboolean && m_snapshotter.isEESnapshotting()) {
        hostLog.info(String.format("Site %d performing schema change operation must block until snapshot is locally complete.", CoreUtils.getSiteIdFromHSId(m_siteId)));
        try {
            m_snapshotter.completeSnapshotWork(m_sysprocContext);
            hostLog.info(String.format("Site %d locally finished snapshot. Will update catalog now.", CoreUtils.getSiteIdFromHSId(m_siteId)));
        } catch (InterruptedException e) {
            VoltDB.crashLocalVoltDB("Unexpected Interrupted Exception while finishing a snapshot for a catalog update.", true, e);
        }
    }
    //Necessary to quiesce before updating the catalog
    //so export data for the old generation is pushed to Java.
    m_ee.quiesce(m_lastCommittedSpHandle);
    m_ee.updateCatalog(m_context.m_uniqueId, requiresNewExportGeneration, diffCmds);
    if (DRCatalogChange) {
        final DRCatalogCommands catalogCommands = DRCatalogDiffEngine.serializeCatalogCommandsForDr(m_context.catalog, -1);
        generateDREvent(EventType.CATALOG_UPDATE, uniqueId, m_lastCommittedSpHandle, spHandle, catalogCommands.commands.getBytes(Charsets.UTF_8));
    }
    return true;
}
Also used : VoltTable(org.voltdb.VoltTable) Table(org.voltdb.catalog.Table) DRCatalogCommands(org.voltdb.catalog.DRCatalogCommands) CatalogContext(org.voltdb.CatalogContext)

Example 12 with CatalogContext

use of org.voltdb.CatalogContext in project voltdb by VoltDB.

the class TestPlannerTool method testBadDDL.

public void testBadDDL() throws IOException {
    // semicolons in in-lined comments are bad
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("CREATE TABLE A (C1 BIGINT NOT NULL, PRIMARY KEY(C1)); -- this; is bad");
    builder.addPartitionInfo("A", "C1");
    // semicolons in string literals are bad
    builder.addLiteralSchema("create table t(id bigint not null, name varchar(5) default 'a;bc', primary key(id));");
    builder.addPartitionInfo("t", "id");
    // Add a newline string literal case just for fun
    builder.addLiteralSchema("create table s(id bigint not null, name varchar(5) default 'a\nb', primary key(id));");
    builder.addStmtProcedure("MakeCompileHappy", "SELECT * FROM A WHERE C1 = ?;", "A.C1: 0");
    final File jar = new File("testbadddl-oop.jar");
    jar.deleteOnExit();
    builder.compile("testbadddl-oop.jar");
    byte[] bytes = MiscUtils.fileToBytes(new File("testbadddl-oop.jar"));
    String serializedCatalog = CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(bytes, false).getFirst());
    assertNotNull(serializedCatalog);
    Catalog c = new Catalog();
    c.execute(serializedCatalog);
    DbSettings settings = new DbSettings(ClusterSettings.create().asSupplier(), NodeSettings.create());
    CatalogContext context = new CatalogContext(0, 0, c, settings, bytes, null, new byte[] {}, 0, mock(HostMessenger.class));
    m_pt = new PlannerTool(context.database, context.getCatalogHash());
    // Bad DDL would kill the planner before it starts and this query
    // would return a Stream Closed error
    m_pt.planSqlForTest("select * from A;");
}
Also used : DbSettings(org.voltdb.settings.DbSettings) PlannerTool(org.voltdb.compiler.PlannerTool) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) HostMessenger(org.voltcore.messaging.HostMessenger) File(java.io.File) Catalog(org.voltdb.catalog.Catalog) CatalogContext(org.voltdb.CatalogContext)

Example 13 with CatalogContext

use of org.voltdb.CatalogContext in project voltdb by VoltDB.

the class TestPlannerTool method testSimple.

public void testSimple() throws IOException {
    TPCCProjectBuilder builder = new TPCCProjectBuilder();
    builder.addAllDefaults();
    final File jar = new File("tpcc-oop.jar");
    jar.deleteOnExit();
    //long start = System.nanoTime();
    //for (int i = 0; i < 10000; i++) {
    builder.compile("tpcc-oop.jar");
    /*    long end = System.nanoTime();
            System.err.printf("Took %.3f seconds to compile.\n",
                    (end - start) / 1000000000.0);
            start = end;
        }*/
    byte[] bytes = MiscUtils.fileToBytes(new File("tpcc-oop.jar"));
    String serializedCatalog = CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(bytes, false).getFirst());
    Catalog catalog = new Catalog();
    catalog.execute(serializedCatalog);
    DbSettings settings = new DbSettings(ClusterSettings.create().asSupplier(), NodeSettings.create());
    CatalogContext context = new CatalogContext(0, 0, catalog, settings, bytes, null, new byte[] {}, 0, mock(HostMessenger.class));
    m_pt = new PlannerTool(context.database, context.getCatalogHash());
    AdHocPlannedStatement result = null;
    result = m_pt.planSqlForTest("select * from warehouse;");
    System.out.println(result);
    // try many tables joins
    try {
        result = m_pt.planSqlForTest("select * from WAREHOUSE, DISTRICT, CUSTOMER, CUSTOMER_NAME, HISTORY, STOCK, ORDERS, NEW_ORDER, ORDER_LINE where " + "WAREHOUSE.W_ID = DISTRICT.D_W_ID and " + "WAREHOUSE.W_ID = CUSTOMER.C_W_ID and " + "WAREHOUSE.W_ID = CUSTOMER_NAME.C_W_ID and " + "WAREHOUSE.W_ID = HISTORY.H_W_ID and " + "WAREHOUSE.W_ID = STOCK.S_W_ID and " + "WAREHOUSE.W_ID = ORDERS.O_W_ID and " + "WAREHOUSE.W_ID = NEW_ORDER.NO_W_ID and " + "WAREHOUSE.W_ID = ORDER_LINE.OL_W_ID and " + "WAREHOUSE.W_ID = 0");
    } catch (Exception e) {
        // V4.5 supports multiple table joins
        fail();
    }
    // try just the right amount of tables
    try {
        result = m_pt.planSqlForTest("select * from CUSTOMER, STOCK, ORDERS, ORDER_LINE, NEW_ORDER where " + "CUSTOMER.C_W_ID = CUSTOMER.C_W_ID and " + "CUSTOMER.C_W_ID = STOCK.S_W_ID and " + "CUSTOMER.C_W_ID = ORDERS.O_W_ID and " + "CUSTOMER.C_W_ID = ORDER_LINE.OL_W_ID and " + "CUSTOMER.C_W_ID = NEW_ORDER.NO_W_ID and " + "CUSTOMER.C_W_ID = 0");
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // try garbage
    try {
        result = m_pt.planSqlForTest("ryan likes the yankees");
        fail();
    } catch (Exception e) {
    }
    try {
        Thread.sleep(500);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        result = m_pt.planSqlForTest("ryan likes the yankees");
        fail();
    } catch (Exception e) {
    }
    result = m_pt.planSqlForTest("select * from warehouse;");
    System.out.println(result);
}
Also used : DbSettings(org.voltdb.settings.DbSettings) PlannerTool(org.voltdb.compiler.PlannerTool) AdHocPlannedStatement(org.voltdb.compiler.AdHocPlannedStatement) HostMessenger(org.voltcore.messaging.HostMessenger) TPCCProjectBuilder(org.voltdb.benchmark.tpcc.TPCCProjectBuilder) File(java.io.File) Catalog(org.voltdb.catalog.Catalog) CatalogContext(org.voltdb.CatalogContext) IOException(java.io.IOException)

Aggregations

CatalogContext (org.voltdb.CatalogContext)13 File (java.io.File)5 VoltTable (org.voltdb.VoltTable)5 Catalog (org.voltdb.catalog.Catalog)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HostMessenger (org.voltcore.messaging.HostMessenger)3 PlannerTool (org.voltdb.compiler.PlannerTool)3 DbSettings (org.voltdb.settings.DbSettings)3 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 JarFile (java.util.jar.JarFile)2 CatalogSpecificPlanner (org.voltdb.CatalogSpecificPlanner)2 ClientResponseImpl (org.voltdb.ClientResponseImpl)2 DependencyPair (org.voltdb.DependencyPair)2 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)2 Table (org.voltdb.catalog.Table)2 ClientResponse (org.voltdb.client.ClientResponse)2 ClusterSettings (org.voltdb.settings.ClusterSettings)2 FileWriter (java.io.FileWriter)1