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();
}
}
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;
}
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;
}
Aggregations