Search in sources :

Example 51 with EOFException

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());
}
Also used : InterruptedIOException(java.io.InterruptedIOException) Invocation(org.voltdb.importer.Invocation) Formatter(org.voltdb.importer.formatter.Formatter) BufferedReader(java.io.BufferedReader) EOFException(java.io.EOFException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) FormatException(org.voltdb.importer.formatter.FormatException)

Example 52 with EOFException

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);
    }
}
Also used : EOFException(java.io.EOFException) ByteBuffer(java.nio.ByteBuffer) SerializableException(org.voltdb.exceptions.SerializableException) IOException(java.io.IOException) EOFException(java.io.EOFException) EEException(org.voltdb.exceptions.EEException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 53 with EOFException

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);
    }
}
Also used : ParameterSet(org.voltdb.ParameterSet) EOFException(java.io.EOFException) ByteBuffer(java.nio.ByteBuffer) SerializableException(org.voltdb.exceptions.SerializableException) IOException(java.io.IOException) EOFException(java.io.EOFException) EEException(org.voltdb.exceptions.EEException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 54 with EOFException

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);
    }
}
Also used : EOFException(java.io.EOFException) ScriptReaderBase(org.hsqldb_voltpatches.scriptio.ScriptReaderBase) IntKeyHashMap(org.hsqldb_voltpatches.lib.IntKeyHashMap) Session(org.hsqldb_voltpatches.Session) StopWatch(org.hsqldb_voltpatches.lib.StopWatch) Result(org.hsqldb_voltpatches.result.Result)

Example 55 with EOFException

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;
}
Also used : EOFException(java.io.EOFException) DataInputStream(java.io.DataInputStream) BackupDataInputStream(android.app.backup.BackupDataInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

EOFException (java.io.EOFException)1149 IOException (java.io.IOException)508 DataInputStream (java.io.DataInputStream)139 FileInputStream (java.io.FileInputStream)124 InputStream (java.io.InputStream)100 ByteArrayInputStream (java.io.ByteArrayInputStream)95 ArrayList (java.util.ArrayList)84 Test (org.junit.Test)84 ByteBuffer (java.nio.ByteBuffer)75 File (java.io.File)74 FileNotFoundException (java.io.FileNotFoundException)61 BufferedInputStream (java.io.BufferedInputStream)56 RandomAccessFile (java.io.RandomAccessFile)46 SocketTimeoutException (java.net.SocketTimeoutException)43 HashMap (java.util.HashMap)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 SocketException (java.net.SocketException)31 Map (java.util.Map)30 InterruptedIOException (java.io.InterruptedIOException)29 Path (org.apache.hadoop.fs.Path)29