use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class ShutdownHooks method runHooks.
private synchronized void runHooks() {
if (m_iAmAServer && !m_crashing && ShutdownHooks.m_crashMessage) {
VoltLogger voltLogger = new VoltLogger("CONSOLE");
String msg = "The VoltDB server will shut down due to a control-C or other JVM exit.";
CoreUtils.PrintGoodLookingLog(voltLogger, msg, Level.WARN);
}
for (Entry<Integer, List<ShutdownTask>> tasks : m_shutdownTasks.entrySet()) {
for (ShutdownTask task : tasks.getValue()) {
if (!m_crashing || (m_crashing && task.m_runOnCrash)) {
try {
task.m_action.run();
} catch (Exception e) {
new VoltLogger("CONSOLE").warn("Exception while running shutdown hooks.", e);
}
}
}
}
// Async volt logger needs to purge after other shutdown tasks but
// before log4j shuts down in the (typical) final action.
VoltLogger.shutdownAsynchronousLogging();
if (m_finalAction != null) {
try {
m_finalAction.run();
}// Don't even try to log that the logger failed to shutdown.
catch (Exception e) {
}
}
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class SystemStatsCollector method initialize.
/**
* Get the process id, the total memory size and determine the
* best way to get the RSS on an ongoing basis.
*/
private static synchronized void initialize() {
PlatformProperties pp = PlatformProperties.getPlatformProperties();
String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
String pidString = processName.substring(0, processName.indexOf('@'));
pid = Integer.valueOf(pidString);
initialized = true;
// get the RSS and other stats from scraping "ps" from the command line
PSScraper.PSData psdata = PSScraper.getPSData(pid);
assert (psdata.rss > 0);
// figure out how much memory this thing has
memorysize = pp.ramInMegabytes;
assert (memorysize > 0);
// now try to figure out the best way to get the rss size
long rss = -1;
// try the mac method
try {
rss = ExecutionEngine.nativeGetRSS();
}// as the useless stats thread got needlessly killed.
catch (Throwable e) {
}
if (rss > 0)
mode = GetRSSMode.MACOSX_NATIVE;
// try procfs
rss = getRSSFromProcFS();
if (rss > 0)
mode = GetRSSMode.PROCFS;
// notify users if stats collection might be slow
if (mode == GetRSSMode.PS) {
VoltLogger logger = new VoltLogger("HOST");
logger.warn("System statistics will be collected in a sub-optimal " + "manner because either procfs couldn't be read from or " + "the native library couldn't be loaded.");
}
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class TestDefaultDeployment method testDefaultDeploymentInitialization.
@Test
public void testDefaultDeploymentInitialization() throws Exception {
String ddl = "CREATE TABLE WAREHOUSE (" + "W_ID INTEGER DEFAULT '0' NOT NULL, " + "W_NAME VARCHAR(16) DEFAULT NULL, " + "PRIMARY KEY (W_ID)" + ");";
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema(ddl);
builder.addStmtProcedure("hello", "select * from warehouse");
// compileWithDefaultDeployment() generates no deployment.xml so that the default is used.
String jarPath = Configuration.getPathToCatalogForTest("test.jar");
assertTrue(builder.compileWithDefaultDeployment(jarPath));
final File jar = new File(jarPath);
jar.deleteOnExit();
String pathToDeployment = builder.getPathToDeployment();
assertEquals(pathToDeployment, null);
// the default deployment file includes an http server on port 8080.
// do some verification without starting VoltDB, since that port
// number conflicts with jenkins on some test servers.
String absolutePath = RealVoltDB.setupDefaultDeployment(new VoltLogger("HOST"));
DeploymentType dflt = CatalogUtil.parseDeployment(absolutePath);
assertTrue(dflt != null);
assertTrue(dflt.getCluster().getHostcount() == 1);
assertTrue(dflt.getCluster().getSitesperhost() == 8);
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class TestVoltCompiler method testInvalidCreateFunctionDDL.
public void testInvalidCreateFunctionDDL() throws Exception {
ArrayList<Feedback> fbs;
// Test CREATE FUNCTION syntax
String[] ddls = new String[] { "CREATE FUNCTION .func FROM METHOD class.method", "CREATE FUNCTION func FROM METHOD class", "CREATE FUNCTION func FROM METHOD .method", "CREATE FUNCTION func FROM METHOD package..class.method", "CREATE FUNCTION func FROM METHOD package.class.method." };
String expectedError = "Invalid CREATE FUNCTION statement: \"%s\", " + "expected syntax: \"CREATE FUNCTION <name> FROM METHOD <class-name>.<method-name>\"";
for (String ddl : ddls) {
fbs = checkInvalidDDL(ddl + ";");
assertTrue(isFeedbackPresent(String.format(expectedError, ddl), fbs));
}
// Test identifiers
String[][] ddlsAndInvalidIdentifiers = new String[][] { { "CREATE FUNCTION 1nvalid FROM METHOD package.class.method", "1nvalid" }, { "CREATE FUNCTION func FROM METHOD 1nvalid.class.method", "1nvalid.class" }, { "CREATE FUNCTION func FROM METHOD package.1nvalid.method", "package.1nvalid" }, { "CREATE FUNCTION func FROM METHOD package.class.1nvalid", "1nvalid" } };
expectedError = "Unknown indentifier in DDL: \"%s\" contains invalid identifier \"%s\"";
for (String[] ddlAndInvalidIdentifier : ddlsAndInvalidIdentifiers) {
fbs = checkInvalidDDL(ddlAndInvalidIdentifier[0] + ";");
assertTrue(isFeedbackPresent(String.format(expectedError, ddlAndInvalidIdentifier[0], ddlAndInvalidIdentifier[1]), fbs));
}
// Test method validation
VoltLogger mockedLogger = Mockito.mock(VoltLogger.class);
VoltCompiler.setVoltLogger(mockedLogger);
String temporaryWarningMessage = "User-defined functions are not implemented yet.";
// Class not found
fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.NonExistentClass.run;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Cannot load class for user-defined function: org.voltdb.compiler.functions.NonExistentClass", fbs));
// Abstract class
fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.AbstractUDFClass.run;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Cannot define a function using an abstract class org.voltdb.compiler.functions.AbstractUDFClass", fbs));
// Method not found
fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.nonexistent;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Cannot find the implementation method nonexistent for user-defined function afunc in class InvalidUDFLibrary", fbs));
// Invalid return type
fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.runWithUnsupportedReturnType;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Method InvalidUDFLibrary.runWithUnsupportedReturnType has an unsupported return type org.voltdb.compiler.functions.InvalidUDFLibrary$UnsupportedType", fbs));
// Invalid parameter type
fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.runWithUnsupportedParamType;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Method InvalidUDFLibrary.runWithUnsupportedParamType has an unsupported parameter type org.voltdb.compiler.functions.InvalidUDFLibrary$UnsupportedType at position 2", fbs));
// Multiple functions with the same name
fbs = checkInvalidDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.dup;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Class InvalidUDFLibrary has multiple methods named dup. Only a single function method is supported.", fbs));
// Function name exists
// One from FunctionSQL
fbs = checkInvalidDDL("CREATE FUNCTION abs FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Function \"abs\" is already defined.", fbs));
// One from FunctionCustom
fbs = checkInvalidDDL("CREATE FUNCTION log FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Function \"log\" is already defined.", fbs));
// One from FunctionForVoltDB
fbs = checkInvalidDDL("CREATE FUNCTION longitude FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;");
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
assertTrue(isFeedbackPresent("Function \"longitude\" is already defined.", fbs));
// The class contains some other invalid functions with the same name
VoltCompiler compiler = new VoltCompiler(false);
final boolean success = compileDDL("CREATE FUNCTION afunc FROM METHOD org.voltdb.compiler.functions.InvalidUDFLibrary.run;", compiler);
assertTrue("A CREATE FUNCTION statement should be able to succeed, but it did not.", success);
verify(mockedLogger, atLeastOnce()).warn(contains(temporaryWarningMessage));
verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a non-public run() method."));
verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a void run() method."));
verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a static run() method."));
verify(mockedLogger, atLeastOnce()).warn(contains("Class InvalidUDFLibrary has a non-public static void run() method."));
VoltCompiler.setVoltLogger(new VoltLogger("COMPILER"));
}
use of org.voltcore.logging.VoltLogger in project voltdb by VoltDB.
the class TransactionIdManager method getNextUniqueTransactionId.
/**
* Generate a unique id that contains a timestamp, a counter
* and a siteid packed into a 64-bit long value. Subsequent calls
* to this method will return strictly larger long values.
* @return The newly generated transaction id.
*/
public long getNextUniqueTransactionId() {
// get the current time, usually the salt value is zero
// in testing it is used to simulate clock skew
long currentTime = m_clock.get() + m_timestampTestingSalt;
if (currentTime == lastUsedTime) {
// increment the counter for this millisecond
counterValue++;
// for this particular millisecond (feels unlikely)
if (counterValue > COUNTER_MAX_VALUE) {
// spin until the next millisecond
while (currentTime == lastUsedTime) {
currentTime = m_clock.get();
}
// reset the counter and lastUsedTime for the new millisecond
lastUsedTime = currentTime;
counterValue = 0;
}
} else {
// reset the counter and lastUsedTime for the new millisecond
if (currentTime < lastUsedTime) {
VoltLogger log = new VoltLogger("HOST");
double diffSeconds = (lastUsedTime - currentTime) / 1000.0;
String msg = String.format("Initiator time moved backwards from: %d to %d, a difference of %.2f seconds.", lastUsedTime, currentTime, diffSeconds);
log.error(msg);
System.err.println(msg);
// if the diff is less than some specified amount of time, wait a bit
if ((lastUsedTime - currentTime) < BACKWARD_TIME_FORGIVENESS_WINDOW_MS) {
log.info("This node will delay any stored procedures sent to it.");
log.info(String.format("This node will resume full operation in %.2f seconds.", diffSeconds));
long count = BACKWARD_TIME_FORGIVENESS_WINDOW_MS;
// note, the loop should stop once lastUsedTime is PASSED, not current
while ((currentTime <= lastUsedTime) && (count-- > 0)) {
try {
m_clock.sleep(1);
} catch (InterruptedException e) {
}
currentTime = m_clock.get();
}
// if the loop above ended because it ran too much
if (count < 0) {
org.voltdb.VoltDB.crashLocalVoltDB("VoltDB was unable to recover after the system time was externally negatively adusted. " + "It is possible that there is a serious system time or NTP error. ", false, null);
}
} else // crash immediately if time has gone backwards by too much
{
org.voltdb.VoltDB.crashLocalVoltDB(String.format("%.2f is larger than the max allowable number of seconds that " + "the clock can be negatively adjusted (%d)", diffSeconds, BACKWARD_TIME_FORGIVENESS_WINDOW_MS / 1000), false, null);
}
}
lastUsedTime = currentTime;
counterValue = 0;
}
lastTxnId = makeIdFromComponents(currentTime, counterValue, initiatorId);
return lastTxnId;
}
Aggregations