use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class CoreUtils method getThreadFactory.
/**
* Creates a thread factory that creates threads within a thread group if
* the group name is given. The threads created will catch any unhandled
* exceptions and log them to the HOST logger.
*
* @param groupName
* @param name
* @param stackSize
* @return
*/
public static ThreadFactory getThreadFactory(final String groupName, final String name, final int stackSize, final boolean incrementThreadNames, final Queue<String> coreList) {
ThreadGroup group = null;
if (groupName != null) {
group = new ThreadGroup(Thread.currentThread().getThreadGroup(), groupName);
}
final ThreadGroup finalGroup = group;
return new ThreadFactory() {
private final AtomicLong m_createdThreadCount = new AtomicLong(0);
private final ThreadGroup m_group = finalGroup;
@Override
public synchronized Thread newThread(final Runnable r) {
final String threadName = name + (incrementThreadNames ? " - " + m_createdThreadCount.getAndIncrement() : "");
String coreTemp = null;
if (coreList != null && !coreList.isEmpty()) {
coreTemp = coreList.poll();
}
final String core = coreTemp;
Runnable runnable = new Runnable() {
@Override
public void run() {
if (core != null) {
// Remove Affinity for now to make this dependency dissapear from the client.
// Goal is to remove client dependency on this class in the medium term.
//PosixJNAAffinity.INSTANCE.setAffinity(core);
}
try {
r.run();
} catch (Throwable t) {
new VoltLogger("HOST").error("Exception thrown in thread " + threadName, t);
} finally {
m_threadLocalDeallocator.run();
}
}
};
Thread t = new Thread(m_group, runnable, threadName, stackSize);
t.setDaemon(true);
return t;
}
};
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class EELibraryLoader method loadExecutionEngineLibrary.
/**
* Load the shared native library if not yet loaded. Returns true if the library was loaded
**/
public static synchronized boolean loadExecutionEngineLibrary(boolean mustSuccede) {
if (!voltSharedLibraryLoaded) {
if (VoltDB.getLoadLibVOLTDB()) {
test64bit();
try {
final VoltLogger hostLog = new VoltLogger("HOST");
String versionString = VoltDB.instance().getEELibraryVersionString();
// this fallback is for test code only
if (versionString == null) {
versionString = VoltDB.instance().getVersionString();
}
assert (versionString != null);
final String libname = "voltdb-" + versionString;
hostLog.info("Loading native VoltDB code (" + libname + "). A confirmation message will follow if the loading is successful.");
if (Boolean.getBoolean(USE_JAVA_LIBRARY_PATH)) {
System.loadLibrary(libname);
} else {
File libFile = getNativeLibraryFile(libname);
System.load(libFile.getAbsolutePath());
}
voltSharedLibraryLoaded = true;
hostLog.info("Successfully loaded native VoltDB library " + libname + ".");
} catch (Throwable e) {
if (hostLog.isDebugEnabled()) {
hostLog.debug("Error loading VoltDB JNI shared library", e);
}
if (mustSuccede) {
String msg = "Library VOLTDB JNI shared library loading failed with error: " + e.getMessage() + "\n";
msg += "Library path " + System.getProperty("java.library.path") + ", " + USE_JAVA_LIBRARY_PATH + "=" + System.getProperty(USE_JAVA_LIBRARY_PATH) + "\n";
msg += "The library may have failed to load because it can't be found in your " + "load library path, or because it is not compatible with the current " + "platform.\n";
msg += "VoltDB provides builds on our website for 64-bit OSX systems >= 10.6, " + "and 64-bit Linux systems with kernels >= 2.6.18.";
if (e instanceof UnsatisfiedLinkError) {
msg += "\nOr the library may have failed to load because java.io.tmpdir should be set to a different directory. " + "Use VOLTDB_OPTS='-Djava.io.tmpdir=<dirpath>' to set it.";
}
VoltDB.crashLocalVoltDB(msg, false, null);
} else {
hostLog.info("Library VOLTDB JNI shared library loading failed. Library path " + System.getProperty("java.library.path"));
}
return false;
}
} else {
return false;
}
}
return voltSharedLibraryLoaded;
}
use of org.voltcore.logging.VoltLogger 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);
}
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class Shutdown method executePlanFragment.
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
if (fragmentId == SysProcFragmentId.PF_shutdownSync) {
VoltDB.instance().getHostMessenger().prepareForShutdown();
if (!m_failsafeArmed.getAndSet(true)) {
m_failsafe.start();
VoltLogger voltLogger = new VoltLogger("HOST");
String msg = "VoltDB shutdown operation requested and in progress. Cluster will terminate shortly.";
CoreUtils.PrintGoodLookingLog(voltLogger, msg, Level.WARN);
}
VoltTable rslt = new VoltTable(new ColumnInfo[] { new ColumnInfo("HA", VoltType.STRING) });
return new DependencyPair.TableDependencyPair(DEP_shutdownSync, rslt);
} else if (fragmentId == SysProcFragmentId.PF_shutdownSyncDone) {
VoltTable rslt = new VoltTable(new ColumnInfo[] { new ColumnInfo("HA", VoltType.STRING) });
return new DependencyPair.TableDependencyPair(DEP_shutdownSyncDone, rslt);
} else if (fragmentId == SysProcFragmentId.PF_shutdownCommand) {
Thread shutdownThread = new Thread() {
@Override
public void run() {
boolean die = false;
try {
die = VoltDB.instance().shutdown(this);
} catch (InterruptedException e) {
new VoltLogger("HOST").error("Exception while attempting to shutdown VoltDB from shutdown sysproc", e);
}
if (die) {
VoltLogger voltLogger = new VoltLogger("HOST");
String msg = "VoltDB shutting down as requested by @Shutdown command.";
CoreUtils.PrintGoodLookingLog(voltLogger, msg, Level.WARN);
System.exit(0);
} else {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
}
}
};
shutdownThread.start();
}
return null;
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class TestFragmentProgressUpdate method verifyLongRunningQueries.
/**
* This method inserts a bunch of rows into table Items,
* and executes a set of fragments in the EE.
* @param numRowsToInsert how many rows to insert into Items
* @param timeout number of ms to wait before canceling RO fragments
* @param stmtName SQL stmt name for last fragment to execute
* @param numFragsToExecute Total number of frags to execute
* (if greater than 1, will prepend quick-running fragments)
* @param readOnly Identify the set of fragments as read-only (may timeout)
* @param sqlTextExpectation Behavior to expect when verify SQL text in log message
*/
@SuppressWarnings("deprecation")
private void verifyLongRunningQueries(int numRowsToInsert, int timeout, String stmtName, int numFragsToExecute, boolean readOnly, SqlTextExpectation sqlTextExpectation) {
m_ee.loadCatalog(0, m_catalog.serialize());
m_itemData.clearRowData();
for (int i = 0; i < numRowsToInsert; ++i) {
m_itemData.addRow(i, i + 50, "item" + i, (double) i / 2, "data" + i);
}
m_ee.loadTable(ITEM_TABLEID, m_itemData, 0, 0, 0, 0, false, false, WRITE_TOKEN);
assertEquals(numRowsToInsert, m_ee.serializeTable(ITEM_TABLEID).getRowCount());
System.out.println("Rows loaded to table " + m_ee.serializeTable(ITEM_TABLEID).getRowCount());
long[] fragIds = new long[numFragsToExecute];
ParameterSet[] paramSets = new ParameterSet[numFragsToExecute];
String[] sqlTexts = new String[numFragsToExecute];
boolean[] writeFrags = new boolean[numFragsToExecute];
for (boolean writeFrag : writeFrags) {
writeFrag = false;
}
createExecutionEngineInputs(stmtName, fragIds, paramSets, sqlTexts);
// Replace the normal logger with a mocked one, so we can verify the message
VoltLogger mockedLogger = Mockito.mock(VoltLogger.class);
ExecutionEngine.setVoltLoggerForTest(mockedLogger);
try (AutoEngineSettings aes = new AutoEngineSettings()) {
// Set the log duration to be short to ensure that a message will be logged
// for long-running queries
aes.setInitialLogDuration(1);
aes.setTimeoutLatency(timeout);
// been fixed, so (we hope) nothing like this will happen in the wild.
switch(sqlTextExpectation) {
case SQL_STATEMENT:
// leave sqlTexts AS-IS
break;
case NO_STATEMENT:
sqlTexts = null;
break;
case STATEMENT_LIST:
// Leave off the last item, which is the one that needs to be
// reported.
sqlTexts = Arrays.copyOfRange(sqlTexts, 0, numFragsToExecute - 1);
break;
default:
fail("Invalid value for sqlTextExpectation");
}
m_ee.executePlanFragments(numFragsToExecute, fragIds, null, paramSets, null, sqlTexts, writeFrags, null, 3, 3, 2, 42, readOnly ? READ_ONLY_TOKEN : WRITE_TOKEN, false);
if (readOnly && timeout > 0) {
// only time out read queries
fail();
}
} catch (Exception ex) {
String msg = String.format("A SQL query was terminated after %.03f seconds " + "because it exceeded", timeout / 1000.0);
assertTrue(ex.getMessage().contains(msg));
}
String expectedSqlTextMsg = null;
switch(sqlTextExpectation) {
case SQL_STATEMENT:
String sqlText = sqlTexts[numFragsToExecute - 1];
expectedSqlTextMsg = String.format("Executing SQL statement is \"%s\".", sqlText);
break;
case NO_STATEMENT:
expectedSqlTextMsg = "SQL statement text is not available.";
break;
case STATEMENT_LIST:
expectedSqlTextMsg = "Unable to report specific SQL statement text " + "for fragment task message index " + (numFragsToExecute - 1) + ". " + "It MAY be one of these " + (numFragsToExecute - 1) + " items: " + "\"SELECT W_ID FROM WAREHOUSE LIMIT 1;\", ";
break;
default:
fail("Invalid value for sqlTextExpectation");
}
verify(mockedLogger, atLeastOnce()).info(contains(expectedSqlTextMsg));
}
Aggregations