use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OAtomicOperation method loadPage.
public OCacheEntry loadPage(long fileId, long pageIndex, boolean checkPinnedPages, final int pageCount) throws IOException {
assert pageCount > 0;
fileId = checkFileIdCompatibilty(fileId, storageId);
if (deletedFiles.contains(fileId))
throw new OStorageException("File with id " + fileId + " is deleted.");
FileChanges changesContainer = fileChanges.get(fileId);
if (changesContainer == null) {
changesContainer = new FileChanges();
fileChanges.put(fileId, changesContainer);
}
if (changesContainer.isNew) {
if (pageIndex <= changesContainer.maxNewPageIndex)
return new OCacheEntry(fileId, pageIndex, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, pageIndex), false);
else
return null;
} else {
FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(pageIndex);
final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
if (pageIndex < filledUpTo) {
if (pageChangesContainer == null) {
pageChangesContainer = new FilePageChanges();
changesContainer.pageChangesMap.put(pageIndex, pageChangesContainer);
}
if (pageChangesContainer.isNew)
return new OCacheEntry(fileId, pageIndex, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, pageIndex), false);
else
return pageCache.loadPage(fileId, pageIndex, checkPinnedPages, writeCache, pageCount);
}
}
return null;
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OTransactionOptimistic method rollback.
@Override
public void rollback(boolean force, int commitLevelDiff) {
if (txStartCounter < 0)
throw new OStorageException("Invalid value of TX counter");
checkTransaction();
txStartCounter += commitLevelDiff;
status = TXSTATUS.ROLLBACKING;
if (!force && txStartCounter > 0) {
OLogManager.instance().debug(this, "Nested transaction was closed but transaction itself was scheduled for rollback.");
return;
}
if (txStartCounter < 0)
throw new OTransactionException("Transaction was rolled back more times than it was started.");
database.getStorage().callInLock(new Callable<Void>() {
public Void call() throws Exception {
database.getStorage().rollback(OTransactionOptimistic.this);
return null;
}
}, true);
// CLEAR THE CACHE
database.getLocalCache().clear();
// REMOVE ALL THE DIRTY ENTRIES AND UNDO ANY DIRTY DOCUMENT IF POSSIBLE.
for (ORecordOperation v : allEntries.values()) {
final ORecord rec = v.getRecord();
if (rec.isDirty())
if (rec instanceof ODocument && ((ODocument) rec).isTrackingChanges())
((ODocument) rec).undo();
else
rec.unload();
}
close();
status = TXSTATUS.ROLLED_BACK;
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class ODirectMemoryOnlyDiskCache method addFile.
@Override
public long addFile(String fileName, long fileId, OWriteCache writeCache) {
int intId = extractFileId(fileId);
metadataLock.lock();
try {
if (files.containsKey(intId))
throw new OStorageException("File with id " + intId + " already exists.");
if (fileNameIdMap.containsKey(fileName))
throw new OStorageException(fileName + " already exists.");
files.put(intId, new MemoryFile(id, intId));
fileNameIdMap.put(fileName, intId);
fileIdNameMap.put(intId, fileName);
return composeFileId(id, intId);
} finally {
metadataLock.unlock();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class ODiskWriteAheadLog method close.
public void close(boolean flush) throws IOException {
syncObject.lock();
try {
if (closed)
return;
closed = true;
for (OLogSegment logSegment : logSegments) logSegment.close(flush);
if (!commitExecutor.isShutdown()) {
commitExecutor.shutdown();
try {
if (!commitExecutor.awaitTermination(OGlobalConfiguration.WAL_SHUTDOWN_TIMEOUT.getValueAsInteger(), TimeUnit.MILLISECONDS))
throw new OStorageException("WAL flush task for '" + getStorage().getName() + "' storage cannot be stopped");
} catch (InterruptedException e) {
OLogManager.instance().error(this, "Cannot shutdown background WAL commit thread");
}
}
if (!autoFileCloser.isShutdown()) {
autoFileCloser.shutdown();
try {
if (!autoFileCloser.awaitTermination(OGlobalConfiguration.WAL_SHUTDOWN_TIMEOUT.getValueAsInteger(), TimeUnit.MILLISECONDS))
throw new OStorageException("WAL file auto close tasks '" + getStorage().getName() + "' storage cannot be stopped");
} catch (InterruptedException e) {
OLogManager.instance().error(this, "Shutdown of file auto close tasks was interrupted");
}
}
masterRecordLSNHolder.close();
} finally {
syncObject.unlock();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class ODiskWriteAheadLog method moveLsnAfter.
@Override
public void moveLsnAfter(OLogSequenceNumber lsn) throws IOException {
syncObject.lock();
try {
if (!activeOperations.isEmpty())
throw new OStorageException("Can not change end of WAL because there are active atomic operations in the log.");
if (end() == null)
throw new OStorageException("Can not change end of WAL because WAL is empty");
if (end().compareTo(lsn) > 0)
return;
OLogSegment last = logSegments.get(logSegments.size() - 1);
last.stopFlush(true);
if (last.filledUpTo() == 0) {
last.delete(false);
logSegments.remove(logSegments.size() - 1);
}
last = new OLogSegment(this, new File(walLocation, getSegmentName(lsn.getSegment() + 1)), fileTTL, maxPagesCacheSize, performanceStatisticManager, new SubScheduledExecutorService(autoFileCloser), new SubScheduledExecutorService(commitExecutor));
last.init(fileDataBuffer);
last.startFlush();
logSegments.add(last);
} finally {
syncObject.unlock();
}
}
Aggregations