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);
}
}
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();
}
}
}
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);
}
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");
}
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();
}
Aggregations