use of org.hsqldb_voltpatches.lib.StopWatch in project voltdb by VoltDB.
the class ScriptRunner method runScript.
/**
* This is used to read the *.log file and manage any necessary
* transaction rollback.
*/
public static void runScript(Database database, String logFilename, int logType) {
IntKeyHashMap sessionMap = new IntKeyHashMap();
Session current = null;
int currentId = 0;
database.setReferentialIntegrity(false);
ScriptReaderBase scr = null;
String statement;
int statementType;
try {
StopWatch sw = new StopWatch();
scr = ScriptReaderBase.newScriptReader(database, logFilename, logType);
while (scr.readLoggedStatement(current)) {
int sessionId = scr.getSessionNumber();
if (current == null || currentId != sessionId) {
currentId = sessionId;
current = (Session) sessionMap.get(currentId);
if (current == null) {
current = database.getSessionManager().newSession(database, database.getUserManager().getSysUser(), false, true, 0);
sessionMap.put(currentId, current);
}
}
if (current.isClosed()) {
sessionMap.remove(currentId);
continue;
}
Result result = null;
statementType = scr.getStatementType();
switch(statementType) {
case ScriptReaderBase.ANY_STATEMENT:
statement = scr.getLoggedStatement();
result = current.executeDirectStatement(statement);
if (result != null && result.isError()) {
if (result.getException() != null) {
throw result.getException();
}
throw Error.error(result);
}
break;
case ScriptReaderBase.SEQUENCE_STATEMENT:
scr.getCurrentSequence().reset(scr.getSequenceValue());
break;
case ScriptReaderBase.COMMIT_STATEMENT:
current.commit(false);
break;
case ScriptReaderBase.INSERT_STATEMENT:
{
current.beginAction(null);
Object[] data = scr.getData();
scr.getCurrentTable().insertNoCheckFromLog(current, data);
current.endAction(Result.updateOneResult);
break;
}
case ScriptReaderBase.DELETE_STATEMENT:
{
current.beginAction(null);
Object[] data = scr.getData();
scr.getCurrentTable().deleteNoCheckFromLog(current, data);
current.endAction(Result.updateOneResult);
break;
}
case ScriptReaderBase.SET_SCHEMA_STATEMENT:
{
current.setSchema(scr.getCurrentSchema());
}
}
if (current.isClosed()) {
sessionMap.remove(currentId);
}
}
} catch (Throwable e) {
String message;
// catch out-of-memory errors and terminate
if (e instanceof EOFException) {
// end of file - normal end
} else if (e instanceof OutOfMemoryError) {
message = "out of memory processing " + logFilename + " line: " + scr.getLineNumber();
database.logger.appLog.logContext(SimpleLog.LOG_ERROR, message);
throw Error.error(ErrorCode.OUT_OF_MEMORY);
} else {
// stop processing on bad log line
message = logFilename + " line: " + scr.getLineNumber() + " " + e.toString();
database.logger.appLog.logContext(SimpleLog.LOG_ERROR, message);
}
} finally {
if (scr != null) {
scr.close();
}
database.getSessionManager().closeAllSessions();
database.setReferentialIntegrity(true);
}
}
use of org.hsqldb_voltpatches.lib.StopWatch in project voltdb by VoltDB.
the class DataFileCache method close.
/**
* Parameter write indicates either an orderly close, or a fast close
* without backup.
*
* When false, just closes the file.
*
* When true, writes out all cached rows that have been modified and the
* free position pointer for the *.data file and then closes the file.
*/
public void close(boolean write) {
SimpleLog appLog = database.logger.appLog;
try {
if (cacheReadonly) {
if (dataFile != null) {
dataFile.close();
dataFile = null;
}
return;
}
StopWatch sw = new StopWatch();
appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close(" + write + ") : start");
if (write) {
cache.saveAll();
Error.printSystemOut("saveAll: " + sw.elapsedTime());
appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : save data");
if (fileModified || freeBlocks.isModified()) {
// set empty
dataFile.seek(LONG_EMPTY_SIZE);
dataFile.writeLong(freeBlocks.getLostBlocksSize());
// set end
dataFile.seek(LONG_FREE_POS_POS);
dataFile.writeLong(fileFreePosition);
// set saved flag;
dataFile.seek(FLAGS_POS);
int flag = BitMap.set(0, FLAG_ISSAVED);
if (hasRowInfo) {
flag = BitMap.set(flag, FLAG_ROWINFO);
}
dataFile.writeInt(flag);
appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : flags");
//
if (dataFile.length() != fileFreePosition) {
dataFile.seek(fileFreePosition);
}
appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : seek end");
Error.printSystemOut("pos and flags: " + sw.elapsedTime());
}
}
if (dataFile != null) {
dataFile.close();
appLog.sendLine(SimpleLog.LOG_NORMAL, "DataFileCache.close() : close");
dataFile = null;
Error.printSystemOut("close: " + sw.elapsedTime());
}
boolean empty = fileFreePosition == INITIAL_FREE_POS;
if (empty) {
fa.removeElement(fileName);
fa.removeElement(backupFileName);
}
} catch (Throwable e) {
appLog.logContext(e, null);
throw Error.error(ErrorCode.FILE_IO_ERROR, ErrorCode.M_DataFileCache_close, new Object[] { e, fileName });
}
}
Aggregations