Search in sources :

Example 11 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OFileClassic method open.

/*
   * (non-Javadoc)
   * 
   * @see com.orientechnologies.orient.core.storage.fs.OFileAAA#open()
   */
public void open() {
    acquireWriteLock();
    try {
        if (!osFile.exists())
            throw new OIOException("File " + osFile.getPath() + " was not found");
        try {
            openChannel();
            init(-1);
            OLogManager.instance().debug(this, "Checking file integrity of " + osFile.getName() + "...");
            if (version < CURRENT_VERSION) {
                setVersion(CURRENT_VERSION);
                version = CURRENT_VERSION;
            }
        } catch (IOException e) {
            throw OException.wrapException(new OIOException("Error during file open"), e);
        }
    } finally {
        releaseWriteLock();
    }
}
Also used : OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OIOException(com.orientechnologies.common.io.OIOException)

Example 12 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OChannelBinary method readBytes.

public byte[] readBytes() throws IOException {
    if (debug)
        OLogManager.instance().info(this, "%s - Reading chunk of bytes. Reading chunk length as int (4 bytes)...", socket.getRemoteSocketAddress());
    final int len = in.readInt();
    if (len > maxChunkSize) {
        throw OException.wrapException(new OIOException("Impossible to read a chunk of length:" + len + " max allowed chunk length:" + maxChunkSize + " see NETWORK_BINARY_MAX_CONTENT_LENGTH settings "), null);
    }
    updateMetricReceivedBytes(OBinaryProtocol.SIZE_INT + len);
    if (debug)
        OLogManager.instance().info(this, "%s - Read chunk lenght: %d", socket.getRemoteSocketAddress(), len);
    if (len < 0)
        return null;
    if (debug)
        OLogManager.instance().info(this, "%s - Reading %d bytes...", socket.getRemoteSocketAddress(), len);
    // REUSE STATIC BUFFER?
    final byte[] tmp = new byte[len];
    in.readFully(tmp);
    if (debug)
        OLogManager.instance().info(this, "%s - Read %d bytes: %s", socket.getRemoteSocketAddress(), len, new String(tmp));
    return tmp;
}
Also used : OIOException(com.orientechnologies.common.io.OIOException)

Example 13 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class ODistributedAbstractPlugin method installDatabaseOnLocalNode.

protected ODatabaseDocumentTx installDatabaseOnLocalNode(final String databaseName, final String dbPath, final String iNode, final String iDatabaseCompressedFile, final boolean delta, final File uniqueClustersBackupDirectory, final OModifiableDistributedConfiguration cfg) {
    ODistributedServerLog.info(this, nodeName, iNode, DIRECTION.IN, "Installing database '%s' to: %s...", databaseName, dbPath);
    try {
        final File f = new File(iDatabaseCompressedFile);
        final File fCompleted = new File(iDatabaseCompressedFile + ".completed");
        new File(dbPath).mkdirs();
        final ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:" + dbPath);
        // USES A CUSTOM WRAPPER OF IS TO WAIT FOR FILE IS WRITTEN (ASYNCH)
        final FileInputStream in = new FileInputStream(f) {

            @Override
            public int read() throws IOException {
                while (true) {
                    final int read = super.read();
                    if (read > -1)
                        return read;
                    if (fCompleted.exists())
                        return 0;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    }
                }
            }

            @Override
            public int read(final byte[] b, final int off, final int len) throws IOException {
                while (true) {
                    final int read = super.read(b, off, len);
                    if (read > 0)
                        return read;
                    if (fCompleted.exists())
                        return 0;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    }
                }
            }

            @Override
            public int available() throws IOException {
                while (true) {
                    final int avail = super.available();
                    if (avail > 0)
                        return avail;
                    if (fCompleted.exists())
                        return 0;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    }
                }
            }
        };
        try {
            final ODistributedAbstractPlugin me = this;
            executeInDistributedDatabaseLock(databaseName, 0, cfg, new OCallable<Void, OModifiableDistributedConfiguration>() {

                @Override
                public Void call(final OModifiableDistributedConfiguration cfg) {
                    try {
                        if (delta) {
                            new OIncrementalServerSync().importDelta(serverInstance, db, in, iNode);
                        } else {
                            // IMPORT FULL DATABASE (LISTENER ONLY FOR DEBUG PURPOSE)
                            db.restore(in, null, new Callable<Object>() {

                                @Override
                                public Object call() throws Exception {
                                    if (uniqueClustersBackupDirectory != null && uniqueClustersBackupDirectory.exists()) {
                                        // NODE THAT WOULD BE LOST IF NOT REPLACED
                                        for (File f : uniqueClustersBackupDirectory.listFiles()) {
                                            final File oldFile = new File(dbPath + "/" + f.getName());
                                            if (oldFile.exists())
                                                oldFile.delete();
                                            // REPLACE IT
                                            if (!f.renameTo(oldFile))
                                                throw new ODistributedException("Cannot restore exclusive cluster file '" + f.getAbsolutePath() + "' into " + oldFile.getAbsolutePath());
                                        }
                                        uniqueClustersBackupDirectory.delete();
                                    }
                                    return null;
                                }
                            }, ODistributedServerLog.isDebugEnabled() ? me : null);
                        }
                        return null;
                    } catch (IOException e) {
                        throw OException.wrapException(new OIOException("Error on distributed sync of database"), e);
                    }
                }
            });
        } finally {
            in.close();
        }
        getServerInstance().openDatabase(db, "internal", "internal", null, true);
        db.reload();
        ODistributedServerLog.info(this, nodeName, null, DIRECTION.NONE, "Installed database '%s' (LSN=%s)", databaseName, ((OAbstractPaginatedStorage) db.getStorage().getUnderlying()).getLSN());
        return db;
    } catch (IOException e) {
        ODistributedServerLog.warn(this, nodeName, null, DIRECTION.IN, "Error on copying database '%s' on local server", e, databaseName);
    }
    return null;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIOException(com.orientechnologies.common.io.OIOException) OCallable(com.orientechnologies.common.util.OCallable) Callable(java.util.concurrent.Callable) OIOException(com.orientechnologies.common.io.OIOException)

Aggregations

OIOException (com.orientechnologies.common.io.OIOException)13 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)6 IOException (java.io.IOException)6 OException (com.orientechnologies.common.exception.OException)5 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)4 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)4 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)4 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)4 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)4 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)4 NamingException (javax.naming.NamingException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OCallable (com.orientechnologies.common.util.OCallable)1 OStorageRemoteNodeSession (com.orientechnologies.orient.client.remote.OStorageRemoteNodeSession)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)1