Search in sources :

Example 1 with PlatformProperties

use of org.voltdb.utils.PlatformProperties in project voltdb by VoltDB.

the class VoltDB method crashLocalVoltDB.

/**
     * Exit the process with an error message, optionally with a stack trace.
     */
public static void crashLocalVoltDB(String errMsg, boolean stackTrace, Throwable thrown) {
    if (exitAfterMessage) {
        System.err.println(errMsg);
        VoltDB.exit(-1);
    }
    try {
        OnDemandBinaryLogger.flush();
    } catch (Throwable e) {
    }
    /*
         * InvocationTargetException suppresses information about the cause, so unwrap until
         * we get to the root cause
         */
    while (thrown instanceof InvocationTargetException) {
        thrown = ((InvocationTargetException) thrown).getCause();
    }
    // for test code
    wasCrashCalled = true;
    crashMessage = errMsg;
    if (ignoreCrash) {
        throw new AssertionError("Faux crash of VoltDB successful.");
    }
    if (CoreUtils.isJunitTest()) {
        VoltLogger log = new VoltLogger("HOST");
        log.warn("Declining to drop a crash file during a junit test.");
    }
    // end test code
    // send a snmp trap crash notification
    sendCrashSNMPTrap(errMsg);
    // is called in
    try {
        // prints a message to stdout
        try {
            // we don't expect this to ever fail, but if it does, skip to dying immediately
            if (!turnOffClientInterface()) {
                // this will jump to the finally block and die faster
                return;
            }
            // Flush trace files
            try {
                VoltTrace.closeAllAndShutdown(new File(instance().getVoltDBRootPath(), "trace_logs").getAbsolutePath(), TimeUnit.SECONDS.toMillis(10));
            } catch (IOException e) {
            }
            // Even if the logger is null, don't stop.  We want to log the stack trace and
            // any other pertinent information to a .dmp file for crash diagnosis
            List<String> currentStacktrace = new ArrayList<>();
            currentStacktrace.add("Stack trace from crashLocalVoltDB() method:");
            // Create a special dump file to hold the stack trace
            try {
                TimestampType ts = new TimestampType(new java.util.Date());
                CatalogContext catalogContext = VoltDB.instance().getCatalogContext();
                String root = catalogContext != null ? VoltDB.instance().getVoltDBRootPath() + File.separator : "";
                PrintWriter writer = new PrintWriter(root + "voltdb_crash" + ts.toString().replace(' ', '-') + ".txt");
                writer.println("Time: " + ts);
                writer.println("Message: " + errMsg);
                writer.println();
                writer.println("Platform Properties:");
                PlatformProperties pp = PlatformProperties.getPlatformProperties();
                String[] lines = pp.toLogLines(instance().getVersionString()).split("\n");
                for (String line : lines) {
                    writer.println(line.trim());
                }
                if (thrown != null) {
                    writer.println();
                    writer.println("****** Exception Thread ****** ");
                    thrown.printStackTrace(writer);
                }
                printStackTraces(writer, currentStacktrace);
                writer.close();
            } catch (Throwable err) {
                // shouldn't fail, but..
                err.printStackTrace();
            }
            VoltLogger log = null;
            try {
                log = new VoltLogger("HOST");
            } catch (RuntimeException rt_ex) {
            /* ignore */
            }
            if (log != null) {
                log.fatal(errMsg);
                if (thrown != null) {
                    if (stackTrace) {
                        log.fatal("Fatal exception", thrown);
                    } else {
                        log.fatal(thrown.toString());
                    }
                } else {
                    if (stackTrace) {
                        for (String currentStackElem : currentStacktrace) {
                            log.fatal(currentStackElem);
                        }
                    }
                }
            } else {
                System.err.println(errMsg);
                if (thrown != null) {
                    if (stackTrace) {
                        thrown.printStackTrace();
                    } else {
                        System.err.println(thrown.toString());
                    }
                } else {
                    if (stackTrace) {
                        for (String currentStackElem : currentStacktrace) {
                            System.err.println(currentStackElem);
                        }
                    }
                }
            }
        } finally {
            System.err.println("VoltDB has encountered an unrecoverable error and is exiting.");
            System.err.println("The log may contain additional information.");
        }
    } finally {
        ShutdownHooks.useOnlyCrashHooks();
        System.exit(-1);
    }
}
Also used : Date(java.util.Date) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) VoltLogger(org.voltcore.logging.VoltLogger) TimestampType(org.voltdb.types.TimestampType) PlatformProperties(org.voltdb.utils.PlatformProperties) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 2 with PlatformProperties

use of org.voltdb.utils.PlatformProperties in project voltdb by VoltDB.

the class RealVoltDB method logDebuggingInfo.

void logDebuggingInfo(int adminPort, int httpPort, String httpPortExtraLogMessage, boolean jsonEnabled) {
    String startAction = m_config.m_startAction.toString();
    String startActionLog = "Database start action is " + (startAction.substring(0, 1).toUpperCase() + startAction.substring(1).toLowerCase()) + ".";
    if (!m_rejoining) {
        hostLog.info(startActionLog);
    }
    // print out awesome network stuff
    hostLog.info(String.format("Listening for native wire protocol clients on port %d.", m_config.m_port));
    hostLog.info(String.format("Listening for admin wire protocol clients on port %d.", adminPort));
    if (m_startMode == OperationMode.PAUSED) {
        hostLog.info(String.format("Started in admin mode. Clients on port %d will be rejected in admin mode.", m_config.m_port));
    }
    if (getReplicationRole() == ReplicationRole.REPLICA) {
        consoleLog.info("Started as " + getReplicationRole().toString().toLowerCase() + " cluster. " + "Clients can only call read-only procedures.");
    }
    if (httpPortExtraLogMessage != null) {
        hostLog.info(httpPortExtraLogMessage);
    }
    if (httpPort != -1) {
        hostLog.info(String.format("Local machine HTTP monitoring is listening on port %d.", httpPort));
    } else {
        hostLog.info(String.format("Local machine HTTP monitoring is disabled."));
    }
    if (jsonEnabled) {
        hostLog.info(String.format("Json API over HTTP enabled at path /api/1.0/, listening on port %d.", httpPort));
    } else {
        hostLog.info("Json API disabled.");
    }
    // java heap size
    long javamaxheapmem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();
    javamaxheapmem /= (1024 * 1024);
    hostLog.info(String.format("Maximum usable Java heap set to %d mb.", javamaxheapmem));
    // Computed minimum heap requirement
    long minRqt = computeMinimumHeapRqt(MiscUtils.isPro(), m_catalogContext.tables.size(), (m_iv2Initiators.size() - 1), m_configuredReplicationFactor);
    hostLog.info("Minimum required Java heap for catalog and server config is " + minRqt + " MB.");
    SortedMap<String, String> dbgMap = m_catalogContext.getDebuggingInfoFromCatalog(true);
    for (String line : dbgMap.values()) {
        hostLog.info(line);
    }
    // print out a bunch of useful system info
    PlatformProperties pp = PlatformProperties.getPlatformProperties();
    String[] lines = pp.toLogLines(getVersionString()).split("\n");
    for (String line : lines) {
        hostLog.info(line.trim());
    }
    if (m_catalogContext.cluster.getDrconsumerenabled() || m_catalogContext.cluster.getDrproducerenabled()) {
        hostLog.info("DR initializing with Cluster Id " + m_catalogContext.cluster.getDrclusterid() + ". The DR cluster was first started at " + new Date(m_clusterCreateTime).toString() + ".");
    }
    final ZooKeeper zk = m_messenger.getZK();
    ZKUtil.ByteArrayCallback operationModeFuture = new ZKUtil.ByteArrayCallback();
    /*
         * Publish our cluster metadata, and then retrieve the metadata
         * for the rest of the cluster
         */
    try {
        zk.create(VoltZK.cluster_metadata + "/" + m_messenger.getHostId(), getLocalMetadata().getBytes("UTF-8"), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, new ZKUtil.StringCallback(), null);
        zk.getData(VoltZK.operationMode, false, operationModeFuture, null);
    } catch (Exception e) {
        VoltDB.crashLocalVoltDB("Error creating \"/cluster_metadata\" node in ZK", true, e);
    }
    Map<Integer, String> clusterMetadata = new HashMap<>(0);
    /*
         * Spin and attempt to retrieve cluster metadata for all nodes in the cluster.
         */
    Set<Integer> metadataToRetrieve = new HashSet<>(m_messenger.getLiveHostIds());
    metadataToRetrieve.remove(m_messenger.getHostId());
    while (!metadataToRetrieve.isEmpty()) {
        Map<Integer, ZKUtil.ByteArrayCallback> callbacks = new HashMap<>();
        for (Integer hostId : metadataToRetrieve) {
            ZKUtil.ByteArrayCallback cb = new ZKUtil.ByteArrayCallback();
            zk.getData(VoltZK.cluster_metadata + "/" + hostId, false, cb, null);
            callbacks.put(hostId, cb);
        }
        for (Map.Entry<Integer, ZKUtil.ByteArrayCallback> entry : callbacks.entrySet()) {
            try {
                ZKUtil.ByteArrayCallback cb = entry.getValue();
                Integer hostId = entry.getKey();
                clusterMetadata.put(hostId, new String(cb.getData(), "UTF-8"));
                metadataToRetrieve.remove(hostId);
            } catch (KeeperException.NoNodeException e) {
            } catch (Exception e) {
                VoltDB.crashLocalVoltDB("Error retrieving cluster metadata", true, e);
            }
        }
    }
    // print out cluster membership
    hostLog.info("About to list cluster interfaces for all nodes with format [ip1 ip2 ... ipN] client-port,admin-port,http-port");
    for (int hostId : m_messenger.getLiveHostIds()) {
        if (hostId == m_messenger.getHostId()) {
            hostLog.info(String.format("  Host id: %d with interfaces: %s [SELF]", hostId, MiscUtils.formatHostMetadataFromJSON(getLocalMetadata())));
        } else {
            String hostMeta = clusterMetadata.get(hostId);
            hostLog.info(String.format("  Host id: %d with interfaces: %s [PEER]", hostId, MiscUtils.formatHostMetadataFromJSON(hostMeta)));
        }
    }
    try {
        if (operationModeFuture.getData() != null) {
            String operationModeStr = new String(operationModeFuture.getData(), "UTF-8");
            m_startMode = OperationMode.valueOf(operationModeStr);
        }
    } catch (KeeperException.NoNodeException e) {
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) ZKUtil(org.voltcore.zk.ZKUtil) 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) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) PlatformProperties(org.voltdb.utils.PlatformProperties) Map(java.util.Map) CatalogMap(org.voltdb.catalog.CatalogMap) TreeMap(java.util.TreeMap) ImmutableMap(com.google_voltpatches.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) HashSet(java.util.HashSet)

Example 3 with PlatformProperties

use of org.voltdb.utils.PlatformProperties in project voltdb by VoltDB.

the class ReportMaker method liveReport.

/**
     * Find the pre-compild catalog report in the jarfile, and modify it for use in the
     * the built-in web portal.
     */
public static String liveReport() {
    byte[] reportbytes = VoltDB.instance().getCatalogContext().getFileInJar("catalog-report.html");
    String report = new String(reportbytes, Charsets.UTF_8);
    // remove commented out code
    report = report.replace("<!--##RESOURCES", "");
    report = report.replace("##RESOURCES-->", "");
    // inject the cluster overview
    //String clusterStr = "<h4>System Overview</h4>\n<p>" + getLiveSystemOverview() + "</p><br/>\n";
    //report = report.replace("<!--##CLUSTER##-->", clusterStr);
    // inject the running system platform properties
    PlatformProperties pp = PlatformProperties.getPlatformProperties();
    String ppStr = "<h4>Cluster Platform</h4>\n<p>" + pp.toHTML() + "</p><br/>\n";
    report = report.replace("<!--##PLATFORM2##-->", ppStr);
    // change the live/static var to live
    if (VoltDB.instance().getConfig().m_isEnterprise) {
        report = report.replace("&b=r&", "&b=e&");
    } else {
        report = report.replace("&b=r&", "&b=c&");
    }
    return report;
}
Also used : PlatformProperties(org.voltdb.utils.PlatformProperties)

Aggregations

PlatformProperties (org.voltdb.utils.PlatformProperties)3 IOException (java.io.IOException)2 Date (java.util.Date)2 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)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 VoltLogger (org.voltcore.logging.VoltLogger)1