Search in sources :

Example 16 with VoltLogger

use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.

the class VoltDB method sendCrashSNMPTrap.

/**
     * send a SNMP trap crash notification
     * @param msg
     */
private static void sendCrashSNMPTrap(String msg) {
    if (msg == null || msg.trim().isEmpty()) {
        return;
    }
    VoltDBInterface vdbInstance = instance();
    if (vdbInstance == null) {
        return;
    }
    SnmpTrapSender snmp = vdbInstance.getSnmpTrapSender();
    if (snmp == null) {
        return;
    }
    try {
        snmp.crash(msg);
    } catch (Throwable t) {
        VoltLogger log = new VoltLogger("HOST");
        log.warn("failed to issue a crash SNMP trap", t);
    }
}
Also used : VoltLogger(org.voltcore.logging.VoltLogger) SnmpTrapSender(org.voltdb.snmp.SnmpTrapSender)

Example 17 with VoltLogger

use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.

the class VoltDB method dropStackTrace.

/*
     * Create a file that starts with the supplied message that contains
     * human readable stack traces for all java threads in the current process.
     */
public static void dropStackTrace(String message) {
    if (CoreUtils.isJunitTest()) {
        VoltLogger log = new VoltLogger("HOST");
        log.warn("Declining to drop a stack trace during a junit test.");
        return;
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss.SSSZ");
    String dateString = sdf.format(new Date());
    CatalogContext catalogContext = VoltDB.instance().getCatalogContext();
    HostMessenger hm = VoltDB.instance().getHostMessenger();
    int hostId = 0;
    if (hm != null) {
        hostId = hm.getHostId();
    }
    String root = catalogContext != null ? VoltDB.instance().getVoltDBRootPath() + File.separator : "";
    try {
        PrintWriter writer = new PrintWriter(root + "host" + hostId + "-" + dateString + ".txt");
        writer.println(message);
        printStackTraces(writer);
        writer.flush();
        writer.close();
    } catch (Exception e) {
        try {
            VoltLogger log = new VoltLogger("HOST");
            log.error("Error while dropping stack trace for \"" + message + "\"", e);
        } catch (RuntimeException rt_ex) {
            e.printStackTrace();
        }
    }
}
Also used : VoltLogger(org.voltcore.logging.VoltLogger) HostMessenger(org.voltcore.messaging.HostMessenger) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrintWriter(java.io.PrintWriter)

Example 18 with VoltLogger

use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.

the class ExecutionEngine method crashVoltDB.

/*
     * Interface backend invokes to communicate to Java frontend
     */
/**
     * Call VoltDB.crashVoltDB on behalf of the EE
     * @param reason Reason the EE crashed
     */
public static void crashVoltDB(String reason, String[] traces, String filename, int lineno) {
    VoltLogger hostLog = new VoltLogger("HOST");
    String fn = (filename == null) ? "unknown" : filename;
    String re = (reason == null) ? "Fatal EE error." : reason;
    hostLog.fatal(re + " In " + fn + ":" + lineno);
    if (traces != null) {
        for (String trace : traces) {
            hostLog.fatal(trace);
        }
    }
    VoltDB.crashLocalVoltDB(re + " In " + fn + ":" + lineno, true, null);
}
Also used : VoltLogger(org.voltcore.logging.VoltLogger)

Example 19 with VoltLogger

use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.

the class TestRateLimitedLogger method testRateLimit.

@Test
public void testRateLimit() {
    VoltLogger vlogger = Mockito.mock(VoltLogger.class);
    RateLimitedLogger logger = new RateLimitedLogger(20, vlogger, Level.DEBUG);
    long startTime = System.currentTimeMillis();
    while (true) {
        logger.log("foo", System.currentTimeMillis());
        if (System.currentTimeMillis() - startTime > 100) {
            break;
        }
    }
    // Rate limited to every 20 ms, we should get this logged
    // no more than 5 times.  Add an extra possible count just
    // to be safe; the real goal is that we not see an infinite
    // number of these.
    Mockito.verify(vlogger, Mockito.atMost(6)).debug("foo");
}
Also used : VoltLogger(org.voltcore.logging.VoltLogger) Test(org.junit.Test)

Example 20 with VoltLogger

use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.

the class SnapshotUtil method requestSnapshot.

/**
     * Request a new snapshot. It will retry for a couple of times. If it
     * doesn't succeed in the specified time, an error response will be sent to
     * the response handler, otherwise a success response will be passed to the
     * handler.
     *
     * The request process runs in a separate thread, this method call will
     * return immediately.
     *
     * @param clientHandle
     * @param path
     * @param nonce
     * @param blocking
     * @param format
     * @param stype type of snapshot path SNAP_AUTO, SNAP_CL or SNAP_PATH
     * @param data Any data that needs to be passed to the snapshot target
     * @param handler
     */
public static void requestSnapshot(final long clientHandle, final String path, final String nonce, final boolean blocking, final SnapshotFormat format, final SnapshotPathType stype, final String data, final SnapshotResponseHandler handler, final boolean notifyChanges) {
    final SnapshotInitiationInfo snapInfo = new SnapshotInitiationInfo(path, nonce, blocking, format, stype, data);
    final SimpleClientResponseAdapter adapter = new SimpleClientResponseAdapter(ClientInterface.SNAPSHOT_UTIL_CID, "SnapshotUtilAdapter", true);
    final LinkedBlockingQueue<ClientResponse> responses = new LinkedBlockingQueue<ClientResponse>();
    adapter.registerCallback(clientHandle, new SimpleClientResponseAdapter.Callback() {

        @Override
        public void handleResponse(ClientResponse response) {
            responses.offer(response);
        }
    });
    final SnapshotDaemon sd = VoltDB.instance().getClientInterface().getSnapshotDaemon();
    Runnable work = new Runnable() {

        @Override
        public void run() {
            ClientResponse response = null;
            // abort if unable to succeed in 2 hours
            final long startTime = System.currentTimeMillis();
            boolean hasRequested = false;
            while (System.currentTimeMillis() - startTime <= TimeUnit.HOURS.toMillis(2)) {
                try {
                    if (!hasRequested) {
                        sd.createAndWatchRequestNode(clientHandle, adapter, snapInfo, notifyChanges);
                        hasRequested = true;
                    }
                    try {
                        response = responses.poll(TimeUnit.HOURS.toMillis(2) - (System.currentTimeMillis() - startTime), TimeUnit.MILLISECONDS);
                        if (response == null)
                            break;
                    } catch (InterruptedException e) {
                        VoltDB.crashLocalVoltDB("Should never happen", true, e);
                    }
                    VoltTable[] results = response.getResults();
                    if (response.getStatus() != ClientResponse.SUCCESS) {
                        break;
                    } else if (isSnapshotInProgress(results)) {
                        // retry after a second
                        Thread.sleep(1000);
                        // Request again
                        hasRequested = false;
                        continue;
                    } else if (isSnapshotQueued(results) && notifyChanges) {
                        //Wait for an update on the queued state via ZK
                        continue;
                    } else {
                        // other errors are not recoverable
                        break;
                    }
                } catch (ForwardClientException e) {
                    //It should eventually terminate and then we can submit one.
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e1) {
                    }
                    new VoltLogger("SNAPSHOT").warn("Partition detection is unable to submit a snapshot request " + "because one already exists. Retrying.");
                    continue;
                } catch (InterruptedException ignore) {
                }
            }
            handler.handleResponse(response);
        }
    };
    // Use an executor service here to avoid explosion of threads???
    ThreadFactory factory = CoreUtils.getThreadFactory("Snapshot Request - " + nonce);
    Thread workThread = factory.newThread(work);
    workThread.start();
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ThreadFactory(java.util.concurrent.ThreadFactory) SnapshotDaemon(org.voltdb.SnapshotDaemon) SimpleClientResponseAdapter(org.voltdb.SimpleClientResponseAdapter) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) VoltTable(org.voltdb.VoltTable) ForwardClientException(org.voltdb.SnapshotDaemon.ForwardClientException) VoltLogger(org.voltcore.logging.VoltLogger) SnapshotInitiationInfo(org.voltdb.SnapshotInitiationInfo)

Aggregations

VoltLogger (org.voltcore.logging.VoltLogger)20 File (java.io.File)3 IOException (java.io.IOException)3 HostAndPort (com.google_voltpatches.common.net.HostAndPort)2 PrintWriter (java.io.PrintWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 Test (org.junit.Test)2 CLIConfig (org.voltdb.CLIConfig)2 VoltTable (org.voltdb.VoltTable)2 SnmpTrapSender (org.voltdb.snmp.SnmpTrapSender)2 VoltFile (org.voltdb.utils.VoltFile)2 EOFException (java.io.EOFException)1 OutputStream (java.io.OutputStream)1 Field (java.lang.reflect.Field)1 InetSocketAddress (java.net.InetSocketAddress)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 ClosedSelectorException (java.nio.channels.ClosedSelectorException)1