use of java.io.EOFException in project voltdb by VoltDB.
the class PullSocketImporter method susceptibleRun.
private void susceptibleRun() {
if (m_eos.get())
return;
info(null, "Starting socket puller for " + m_config.getResourceID());
m_thread = Optional.of(Thread.currentThread());
Optional<BufferedReader> reader = null;
Formatter formatter = m_config.getFormatterBuilder().create();
while (!m_eos.get()) {
try {
reader = attemptBufferedReader();
if (!reader.isPresent()) {
sleep(2_000);
continue;
}
BufferedReader br = reader.get();
String csv = null;
while ((csv = br.readLine()) != null) {
try {
Object[] params = formatter.transform(ByteBuffer.wrap(csv.getBytes()));
Invocation invocation = new Invocation(m_config.getProcedure(), params);
if (!callProcedure(invocation)) {
if (isDebugEnabled()) {
debug(null, "Failed to process Invocation possibly bad data: " + csv);
}
}
} catch (FormatException e) {
rateLimitedLog(Level.ERROR, e, "Failed to tranform data: %s", csv);
;
}
}
if (csv == null) {
warn(null, m_config.getResourceID() + " peer terminated stream");
}
} catch (EOFException e) {
rateLimitedLog(Level.WARN, e, m_config.getResourceID() + " peer terminated stream");
} catch (InterruptedException e) {
if (m_eos.get())
return;
rateLimitedLog(Level.ERROR, e, "Socket puller %s was interrupted", m_config.getResourceID());
} catch (InterruptedIOException e) {
if (m_eos.get())
return;
rateLimitedLog(Level.ERROR, e, "Socket puller for %s was interrupted", m_config.getResourceID());
} catch (IOException e) {
rateLimitedLog(Level.ERROR, e, "Read fault for %s", m_config.getResourceID());
}
}
info(null, "Stopping socket puller for " + m_config.getResourceID());
}
use of java.io.EOFException in project voltdb by VoltDB.
the class ExecutionEngineIPC method getThreadLocalPoolAllocations.
@Override
public long getThreadLocalPoolAllocations() {
m_data.clear();
m_data.putInt(Commands.GetPoolAllocations.m_id);
try {
m_data.flip();
m_connection.write();
m_connection.readStatusByte();
ByteBuffer allocations = ByteBuffer.allocate(8);
while (allocations.hasRemaining()) {
int read = m_connection.m_socketChannel.read(allocations);
if (read <= 0) {
throw new EOFException();
}
}
allocations.flip();
return allocations.getLong();
} catch (final Exception e) {
System.out.println("Exception: " + e.getMessage());
throw new RuntimeException(e);
}
}
use of java.io.EOFException in project voltdb by VoltDB.
the class ExecutionEngineIPC method hashinate.
@Override
public int hashinate(Object value, HashinatorConfig config) {
ParameterSet parameterSet = ParameterSet.fromArrayNoCopy(value);
// in case this memoizes stuff
parameterSet.getSerializedSize();
m_data.clear();
m_data.putInt(Commands.Hashinate.m_id);
m_data.putInt(config.type.typeId());
m_data.putInt(config.configBytes.length);
m_data.put(config.configBytes);
try {
parameterSet.flattenToBuffer(m_data);
m_data.flip();
m_connection.write();
m_connection.readStatusByte();
ByteBuffer part = ByteBuffer.allocate(4);
while (part.hasRemaining()) {
int read = m_connection.m_socketChannel.read(part);
if (read <= 0) {
throw new EOFException();
}
}
part.flip();
return part.getInt();
} catch (final Exception e) {
System.out.println("Exception: " + e.getMessage());
throw new RuntimeException(e);
}
}
use of java.io.EOFException 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 java.io.EOFException in project android_frameworks_base by ResurrectionRemix.
the class AccountSyncSettingsBackupHelper method readOldMd5Checksum.
/**
* Read the MD5 checksum from the old state.
*
* @return the old MD5 checksum
*/
private byte[] readOldMd5Checksum(ParcelFileDescriptor oldState) throws IOException {
DataInputStream dataInput = new DataInputStream(new FileInputStream(oldState.getFileDescriptor()));
byte[] oldMd5Checksum = new byte[MD5_BYTE_SIZE];
try {
int stateVersion = dataInput.readInt();
if (stateVersion <= STATE_VERSION) {
// backup.
for (int i = 0; i < MD5_BYTE_SIZE; i++) {
oldMd5Checksum[i] = dataInput.readByte();
}
} else {
Log.i(TAG, "Backup state version is: " + stateVersion + " (support only up to version " + STATE_VERSION + ")");
}
} catch (EOFException eof) {
// Initial state may be empty.
}
// We explicitly don't close 'dataInput' because we must not close the backing fd.
return oldMd5Checksum;
}
Aggregations