Search in sources :

Example 1 with VoltDBInterface

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

the class VoltCompiler method generateCatalogReport.

private void generateCatalogReport(String ddlWithBatchSupport) throws IOException {
    VoltDBInterface voltdb = VoltDB.instance();
    // try to get a catalog context
    CatalogContext catalogContext = voltdb != null ? voltdb.getCatalogContext() : null;
    ClusterSettings clusterSettings = catalogContext != null ? catalogContext.getClusterSettings() : null;
    int tableCount = catalogContext != null ? catalogContext.tables.size() : 0;
    Deployment deployment = catalogContext != null ? catalogContext.cluster.getDeployment().get("deployment") : null;
    int hostcount = clusterSettings != null ? clusterSettings.hostcount() : 1;
    int kfactor = deployment != null ? deployment.getKfactor() : 0;
    int sitesPerHost = 8;
    if (voltdb != null && voltdb.getCatalogContext() != null) {
        sitesPerHost = voltdb.getCatalogContext().getNodeSettings().getLocalSitesCount();
    }
    boolean isPro = MiscUtils.isPro();
    long minHeapRqt = RealVoltDB.computeMinimumHeapRqt(isPro, tableCount, sitesPerHost, kfactor);
    m_report = ReportMaker.report(m_catalog, minHeapRqt, isPro, hostcount, sitesPerHost, kfactor, m_warnings, ddlWithBatchSupport);
    m_reportPath = null;
    File file = null;
    // write to working dir when using VoltCompiler directly
    if (standaloneCompiler) {
        file = new File("catalog-report.html");
    } else {
        // if we have a context, write report to voltroot
        if (catalogContext != null) {
            file = new File(VoltDB.instance().getVoltDBRootPath(), "catalog-report.html");
        }
    }
    // if there's a good place to write the report, do so
    if (file != null) {
        FileWriter fw = new FileWriter(file);
        fw.write(m_report);
        fw.close();
        m_reportPath = file.getAbsolutePath();
    }
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) ClusterSettings(org.voltdb.settings.ClusterSettings) FileWriter(java.io.FileWriter) Deployment(org.voltdb.catalog.Deployment) JarFile(java.util.jar.JarFile) File(java.io.File) CatalogContext(org.voltdb.CatalogContext)

Example 2 with VoltDBInterface

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

the class Pause method run.

/**
     * Enter admin mode
     * @param ctx       Internal parameter. Not user-accessible.
     * @return          Standard STATUS table.
     */
public VoltTable[] run(SystemProcedureExecutionContext ctx) {
    if (ctx.isLowestSiteId()) {
        VoltDBInterface voltdb = VoltDB.instance();
        OperationMode opMode = voltdb.getMode();
        if (LOG.isDebugEnabled()) {
            LOG.debug("voltdb opmode is " + opMode);
        }
        ZooKeeper zk = voltdb.getHostMessenger().getZK();
        try {
            Stat stat;
            OperationMode zkMode = null;
            Code code;
            do {
                stat = new Stat();
                code = Code.BADVERSION;
                try {
                    byte[] data = zk.getData(VoltZK.operationMode, false, stat);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("zkMode is " + (zkMode == null ? "(null)" : OperationMode.valueOf(data)));
                    }
                    zkMode = data == null ? opMode : OperationMode.valueOf(data);
                    if (zkMode == PAUSED) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("read node at version " + stat.getVersion() + ", txn " + ll(stat.getMzxid()));
                        }
                        break;
                    }
                    stat = zk.setData(VoltZK.operationMode, PAUSED.getBytes(), stat.getVersion());
                    code = Code.OK;
                    zkMode = PAUSED;
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("!WROTE! node at version " + stat.getVersion() + ", txn " + ll(stat.getMzxid()));
                    }
                    break;
                } catch (BadVersionException ex) {
                    code = ex.code();
                }
            } while (zkMode != PAUSED && code == Code.BADVERSION);
            m_stat = stat;
            voltdb.getHostMessenger().pause();
            voltdb.setMode(PAUSED);
            // for snmp
            SnmpTrapSender snmp = voltdb.getSnmpTrapSender();
            if (snmp != null) {
                snmp.pause("Cluster paused.");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    // Force a tick so that stats will be updated.
    // Primarily added to get latest table stats for DR pause and empty db check.
    ctx.getSiteProcedureConnection().tick();
    VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
    t.addRow(VoltSystemProcedure.STATUS_OK);
    return (new VoltTable[] { t });
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException) SnmpTrapSender(org.voltdb.snmp.SnmpTrapSender) OperationMode(org.voltdb.OperationMode) Code(org.apache.zookeeper_voltpatches.KeeperException.Code) VoltTable(org.voltdb.VoltTable) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)

Example 3 with VoltDBInterface

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

the class Resume method run.

/**
     * Exit admin mode
     * @param ctx       Internal parameter. Not user-accessible.
     * @return          Standard STATUS table.
     */
public VoltTable[] run(SystemProcedureExecutionContext ctx) {
    // Choose the lowest site ID on this host to actually flip the bit
    VoltDBInterface voltdb = VoltDB.instance();
    OperationMode opMode = voltdb.getMode();
    if (ctx.isLowestSiteId()) {
        ZooKeeper zk = voltdb.getHostMessenger().getZK();
        try {
            Stat stat;
            OperationMode zkMode = null;
            Code code;
            do {
                stat = new Stat();
                code = Code.BADVERSION;
                try {
                    byte[] data = zk.getData(VoltZK.operationMode, false, stat);
                    zkMode = data == null ? opMode : OperationMode.valueOf(data);
                    if (zkMode == RUNNING) {
                        break;
                    }
                    stat = zk.setData(VoltZK.operationMode, RUNNING.getBytes(), stat.getVersion());
                    code = Code.OK;
                    zkMode = RUNNING;
                    break;
                } catch (BadVersionException ex) {
                    code = ex.code();
                }
            } while (zkMode != RUNNING && code == Code.BADVERSION);
            voltdb.getHostMessenger().unpause();
            voltdb.setMode(RUNNING);
            // for snmp
            SnmpTrapSender snmp = voltdb.getSnmpTrapSender();
            if (snmp != null) {
                snmp.resume("Cluster resumed.");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
    t.addRow(VoltSystemProcedure.STATUS_OK);
    return new VoltTable[] { t };
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) Stat(org.apache.zookeeper_voltpatches.data.Stat) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException) SnmpTrapSender(org.voltdb.snmp.SnmpTrapSender) OperationMode(org.voltdb.OperationMode) Code(org.apache.zookeeper_voltpatches.KeeperException.Code) VoltTable(org.voltdb.VoltTable) BadVersionException(org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)

Example 4 with VoltDBInterface

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

the class TestLeaderAppointer method testFailureDuringSyncSnapshot.

@Test
public void testFailureDuringSyncSnapshot() throws Exception {
    final VoltDBInterface mVolt = mock(VoltDBInterface.class);
    doReturn(ReplicationRole.REPLICA).when(mVolt).getReplicationRole();
    VoltDB.replaceVoltDBInstanceForTest(mVolt);
    configure(2, 2, 1, false);
    Thread dutthread = new Thread() {

        @Override
        public void run() {
            try {
                m_dut.acceptPromotion();
            } catch (Exception e) {
            }
        }
    };
    dutthread.start();
    // Need to sleep so we don't write to ZK before the LeaderAppointer appears or we'll crash
    Thread.sleep(1000);
    addReplica(0, 0L);
    addReplica(0, 1L);
    addReplica(1, 2L);
    addReplica(1, 3L);
    waitForAppointee(1);
    registerLeader(0, m_cache.pointInTimeCache().get(0));
    registerLeader(1, m_cache.pointInTimeCache().get(1));
    dutthread.join();
    // kill the appointer and delete one of the leaders
    m_dut.shutdown();
    deleteReplica(0, m_cache.pointInTimeCache().get(0));
    // create a new appointer and start it up with expectSyncSnapshot=true
    m_dut = new LeaderAppointer(m_hm, m_topo.getPartitionCount(), m_kfactor, m_topo.topologyToJSON(), m_mpi, new KSafetyStats(), true);
    m_dut.onReplayCompletion();
    m_newAppointee.set(false);
    VoltDB.ignoreCrash = true;
    boolean threw = false;
    try {
        m_dut.acceptPromotion();
    } catch (ExecutionException e) {
        threw = true;
    }
    assertTrue(threw);
    assertTrue(VoltDB.wasCrashCalled);
    // Promote the replica to a master before sync snapshot, failure should not crash now.
    doReturn(ReplicationRole.NONE).when(mVolt).getReplicationRole();
    VoltDB.wasCrashCalled = false;
    m_dut.acceptPromotion();
    assertFalse(VoltDB.wasCrashCalled);
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) ExecutionException(java.util.concurrent.ExecutionException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) JSONException(org.json_voltpatches.JSONException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with VoltDBInterface

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

the class TestLeaderAppointer method setUp.

@Before
public void setUp() throws Exception {
    final VoltDBInterface mock = mock(VoltDBInterface.class);
    when(mock.getReplicationRole()).thenReturn(ReplicationRole.NONE);
    VoltDB.replaceVoltDBInstanceForTest(mock);
    VoltDB.ignoreCrash = false;
    VoltDB.wasCrashCalled = false;
    setUpZK(NUM_AGREEMENT_SITES);
}
Also used : VoltDBInterface(org.voltdb.VoltDBInterface) Before(org.junit.Before)

Aggregations

VoltDBInterface (org.voltdb.VoltDBInterface)5 BadVersionException (org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)2 Code (org.apache.zookeeper_voltpatches.KeeperException.Code)2 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)2 Stat (org.apache.zookeeper_voltpatches.data.Stat)2 OperationMode (org.voltdb.OperationMode)2 VoltTable (org.voltdb.VoltTable)2 SnmpTrapSender (org.voltdb.snmp.SnmpTrapSender)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 ExecutionException (java.util.concurrent.ExecutionException)1 JarFile (java.util.jar.JarFile)1 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)1 JSONException (org.json_voltpatches.JSONException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 CatalogContext (org.voltdb.CatalogContext)1 Deployment (org.voltdb.catalog.Deployment)1 ClusterSettings (org.voltdb.settings.ClusterSettings)1