Search in sources :

Example 1 with DbSettings

use of org.voltdb.settings.DbSettings in project voltdb by VoltDB.

the class MockVoltDB method getCatalogContext.

@Override
public CatalogContext getCatalogContext() {
    long now = System.currentTimeMillis();
    DbSettings settings = new DbSettings(ClusterSettings.create().asSupplier(), NodeSettings.create());
    m_context = new CatalogContext(now, now, m_catalog, settings, new byte[] {}, null, new byte[] {}, 0, m_hostMessenger) {

        @Override
        public long getCatalogCRC() {
            return 13;
        }
    };
    return m_context;
}
Also used : DbSettings(org.voltdb.settings.DbSettings)

Example 2 with DbSettings

use of org.voltdb.settings.DbSettings in project voltdb by VoltDB.

the class RealVoltDB method readDeploymentAndCreateStarterCatalogContext.

boolean readDeploymentAndCreateStarterCatalogContext(VoltDB.Configuration config) {
    /*
         * Debate with the cluster what the deployment file should be
         */
    try {
        ZooKeeper zk = m_messenger.getZK();
        byte[] deploymentBytes = null;
        try {
            deploymentBytes = org.voltcore.utils.CoreUtils.urlToBytes(m_config.m_pathToDeployment);
        } catch (Exception ex) {
        //Let us get bytes from ZK
        }
        DeploymentType deployment = null;
        try {
            if (deploymentBytes != null) {
                CatalogUtil.writeCatalogToZK(zk, // Fill in innocuous values for non-deployment stuff
                0, 0L, 0L, // spin loop in Inits.LoadCatalog.run() needs
                new byte[] {}, // this to be of zero length until we have a real catalog.
                null, deploymentBytes);
                hostLog.info("URL of deployment: " + m_config.m_pathToDeployment);
            } else {
                CatalogAndIds catalogStuff = CatalogUtil.getCatalogFromZK(zk);
                deploymentBytes = catalogStuff.deploymentBytes;
            }
        } catch (KeeperException.NodeExistsException e) {
            CatalogAndIds catalogStuff = CatalogUtil.getCatalogFromZK(zk);
            byte[] deploymentBytesTemp = catalogStuff.deploymentBytes;
            if (deploymentBytesTemp != null) {
                //We will ignore the supplied or default deployment anyways.
                if (deploymentBytes != null && !m_config.m_deploymentDefault) {
                    byte[] deploymentHashHere = CatalogUtil.makeDeploymentHash(deploymentBytes);
                    if (!(Arrays.equals(deploymentHashHere, catalogStuff.getDeploymentHash()))) {
                        hostLog.warn("The locally provided deployment configuration did not " + " match the configuration information found in the cluster.");
                    } else {
                        hostLog.info("Deployment configuration pulled from other cluster node.");
                    }
                }
                //Use remote deployment obtained.
                deploymentBytes = deploymentBytesTemp;
            } else {
                hostLog.error("Deployment file could not be loaded locally or remotely, " + "local supplied path: " + m_config.m_pathToDeployment);
                deploymentBytes = null;
            }
        } catch (KeeperException.NoNodeException e) {
            // no deploymentBytes case is handled below. So just log this error.
            if (hostLog.isDebugEnabled()) {
                hostLog.debug("Error trying to get deployment bytes from cluster", e);
            }
        }
        if (deploymentBytes == null) {
            hostLog.error("Deployment information could not be obtained from cluster node or locally");
            VoltDB.crashLocalVoltDB("No such deployment file: " + m_config.m_pathToDeployment, false, null);
        }
        if (deployment == null) {
            deployment = CatalogUtil.getDeployment(new ByteArrayInputStream(deploymentBytes));
        }
        // wasn't a valid xml deployment file
        if (deployment == null) {
            hostLog.error("Not a valid XML deployment file at URL: " + m_config.m_pathToDeployment);
            VoltDB.crashLocalVoltDB("Not a valid XML deployment file at URL: " + m_config.m_pathToDeployment, false, null);
        }
        /*
             * Check for invalid deployment file settings (enterprise-only) in the community edition.
             * Trick here is to print out all applicable problems and then stop, rather than stopping
             * after the first one is found.
             */
        if (!m_config.m_isEnterprise) {
            boolean shutdownDeployment = false;
            boolean shutdownAction = false;
            // check license features for community version
            if ((deployment.getCluster() != null) && (deployment.getCluster().getKfactor() > 0)) {
                consoleLog.error("K-Safety is not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            if ((deployment.getSnapshot() != null) && (deployment.getSnapshot().isEnabled())) {
                consoleLog.error("Snapshots are not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            if ((deployment.getCommandlog() != null) && (deployment.getCommandlog().isEnabled())) {
                consoleLog.error("Command logging is not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            if ((deployment.getExport() != null) && deployment.getExport().getConfiguration() != null && !deployment.getExport().getConfiguration().isEmpty()) {
                consoleLog.error("Export is not supported " + "in the community edition of VoltDB.");
                shutdownDeployment = true;
            }
            // check the start action for the community edition
            if (m_config.m_startAction != StartAction.CREATE) {
                consoleLog.error("Start action \"" + m_config.m_startAction.getClass().getSimpleName() + "\" is not supported in the community edition of VoltDB.");
                shutdownAction = true;
            }
            // if the process needs to stop, try to be helpful
            if (shutdownAction || shutdownDeployment) {
                String msg = "This process will exit. Please run VoltDB with ";
                if (shutdownDeployment) {
                    msg += "a deployment file compatible with the community edition";
                }
                if (shutdownDeployment && shutdownAction) {
                    msg += " and ";
                }
                if (shutdownAction && !shutdownDeployment) {
                    msg += "the CREATE start action";
                }
                msg += ".";
                VoltDB.crashLocalVoltDB(msg, false, null);
            }
        }
        // note the heart beats are specified in seconds in xml, but ms internally
        HeartbeatType hbt = deployment.getHeartbeat();
        if (hbt != null) {
            m_config.m_deadHostTimeoutMS = hbt.getTimeout() * 1000;
            m_messenger.setDeadHostTimeout(m_config.m_deadHostTimeoutMS);
        } else {
            hostLog.info("Dead host timeout set to " + m_config.m_deadHostTimeoutMS + " milliseconds");
        }
        PartitionDetectionType pt = deployment.getPartitionDetection();
        if (pt != null) {
            m_config.m_partitionDetectionEnabled = pt.isEnabled();
            m_messenger.setPartitionDetectionEnabled(m_config.m_partitionDetectionEnabled);
        }
        // get any consistency settings into config
        ConsistencyType consistencyType = deployment.getConsistency();
        if (consistencyType != null) {
            m_config.m_consistencyReadLevel = Consistency.ReadLevel.fromReadLevelType(consistencyType.getReadlevel());
        }
        final String elasticSetting = deployment.getCluster().getElastic().trim().toUpperCase();
        if (elasticSetting.equals("ENABLED")) {
            TheHashinator.setConfiguredHashinatorType(HashinatorType.ELASTIC);
        } else if (!elasticSetting.equals("DISABLED")) {
            VoltDB.crashLocalVoltDB("Error in deployment file,  elastic attribute of " + "cluster element must be " + "'enabled' or 'disabled' but was '" + elasticSetting + "'", false, null);
        } else {
            TheHashinator.setConfiguredHashinatorType(HashinatorType.LEGACY);
        }
        // log system setting information
        SystemSettingsType sysType = deployment.getSystemsettings();
        if (sysType != null) {
            if (sysType.getElastic() != null) {
                hostLog.info("Elastic duration set to " + sysType.getElastic().getDuration() + " milliseconds");
                hostLog.info("Elastic throughput set to " + sysType.getElastic().getThroughput() + " mb/s");
            }
            if (sysType.getTemptables() != null) {
                hostLog.info("Max temptable size set to " + sysType.getTemptables().getMaxsize() + " mb");
            }
            if (sysType.getSnapshot() != null) {
                hostLog.info("Snapshot priority set to " + sysType.getSnapshot().getPriority() + " [0 - 10]");
            }
            if (sysType.getQuery() != null) {
                if (sysType.getQuery().getTimeout() > 0) {
                    hostLog.info("Query timeout set to " + sysType.getQuery().getTimeout() + " milliseconds");
                    m_config.m_queryTimeout = sysType.getQuery().getTimeout();
                } else if (sysType.getQuery().getTimeout() == 0) {
                    hostLog.info("Query timeout set to unlimited");
                    m_config.m_queryTimeout = 0;
                }
            }
        }
        // log a warning on console log if security setting is turned off, like durability warning.
        SecurityType securityType = deployment.getSecurity();
        if (securityType == null || !securityType.isEnabled()) {
            consoleLog.warn(SECURITY_OFF_WARNING);
        }
        // create a dummy catalog to load deployment info into
        Catalog catalog = new Catalog();
        // Need these in the dummy catalog
        Cluster cluster = catalog.getClusters().add("cluster");
        cluster.getDatabases().add("database");
        String result = CatalogUtil.compileDeployment(catalog, deployment, true);
        if (result != null) {
            // Any other non-enterprise deployment errors will be caught and handled here
            // (such as <= 0 host count)
            VoltDB.crashLocalVoltDB(result);
        }
        m_catalogContext = new CatalogContext(//txnid
        TxnEgo.makeZero(MpInitiator.MP_INIT_PID).getTxnId(), //timestamp
        0, catalog, new DbSettings(m_clusterSettings, m_nodeSettings), new byte[] {}, null, deploymentBytes, 0, m_messenger);
        return ((deployment.getCommandlog() != null) && (deployment.getCommandlog().isEnabled()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CatalogAndIds(org.voltdb.utils.CatalogUtil.CatalogAndIds) SecurityType(org.voltdb.compiler.deploymentfile.SecurityType) Cluster(org.voltdb.catalog.Cluster) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException) Catalog(org.voltdb.catalog.Catalog) DbSettings(org.voltdb.settings.DbSettings) HeartbeatType(org.voltdb.compiler.deploymentfile.HeartbeatType) ConsistencyType(org.voltdb.compiler.deploymentfile.ConsistencyType) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) SystemSettingsType(org.voltdb.compiler.deploymentfile.SystemSettingsType) ByteArrayInputStream(java.io.ByteArrayInputStream) PartitionDetectionType(org.voltdb.compiler.deploymentfile.PartitionDetectionType) KeeperException(org.apache.zookeeper_voltpatches.KeeperException)

Example 3 with DbSettings

use of org.voltdb.settings.DbSettings in project voltdb by VoltDB.

the class TestAdHocPlans method setUp.

@Before
public void setUp() throws Exception {
    // For planner-only testing, we shouldn't care about IV2
    VoltDB.Configuration config = setUpSPDB();
    byte[] bytes = MiscUtils.fileToBytes(new File(config.m_pathToCatalog));
    String serializedCatalog = CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(bytes, false).getFirst());
    Catalog catalog = new Catalog();
    catalog.execute(serializedCatalog);
    DbSettings dbSettings = new DbSettings(config.asClusterSettings().asSupplier(), NodeSettings.create(config.asPathSettingsMap()));
    CatalogContext context = new CatalogContext(0, 0, catalog, dbSettings, bytes, null, new byte[] {}, 0, mock(HostMessenger.class));
    m_pt = new PlannerTool(context.database, context.getCatalogHash());
}
Also used : VoltDB(org.voltdb.VoltDB) DbSettings(org.voltdb.settings.DbSettings) PlannerTool(org.voltdb.compiler.PlannerTool) HostMessenger(org.voltcore.messaging.HostMessenger) File(java.io.File) Catalog(org.voltdb.catalog.Catalog) CatalogContext(org.voltdb.CatalogContext) Before(org.junit.Before)

Example 4 with DbSettings

use of org.voltdb.settings.DbSettings 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 5 with DbSettings

use of org.voltdb.settings.DbSettings 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

DbSettings (org.voltdb.settings.DbSettings)6 Catalog (org.voltdb.catalog.Catalog)5 File (java.io.File)4 IOException (java.io.IOException)3 HostMessenger (org.voltcore.messaging.HostMessenger)3 CatalogContext (org.voltdb.CatalogContext)3 PlannerTool (org.voltdb.compiler.PlannerTool)3 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketException (java.net.SocketException)1 ExecutionException (java.util.concurrent.ExecutionException)1 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)1 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)1 JSONException (org.json_voltpatches.JSONException)1 Before (org.junit.Before)1 VoltDB (org.voltdb.VoltDB)1 TPCCProjectBuilder (org.voltdb.benchmark.tpcc.TPCCProjectBuilder)1 Cluster (org.voltdb.catalog.Cluster)1 AdHocPlannedStatement (org.voltdb.compiler.AdHocPlannedStatement)1