use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method close.
public void close(long fileId, boolean flush) throws IOException {
final int intId = extractFileId(fileId);
fileId = composeFileId(id, intId);
filesLock.acquireWriteLock();
try {
if (flush)
flush(intId);
else
removeCachedPages(intId);
if (!files.close(fileId))
throw new OStorageException("Can not close file with id " + internalFileId(fileId) + " because it is still in use");
} finally {
filesLock.releaseWriteLock();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method initNameIdMapping.
private void initNameIdMapping() throws IOException, InterruptedException {
if (nameIdMapHolder == null) {
final File storagePath = new File(storageLocal.getStoragePath());
if (!storagePath.exists())
if (!storagePath.mkdirs())
throw new OStorageException("Cannot create directories for the path '" + storagePath + "'");
nameIdMapHolderFile = new File(storagePath, NAME_ID_MAP);
nameIdMapHolder = new RandomAccessFile(nameIdMapHolderFile, "rw");
readNameIdMap();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method load.
public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages, OModifiableBoolean cacheHit) throws IOException {
final int intId = extractFileId(fileId);
if (pageCount < 1)
throw new IllegalArgumentException("Amount of pages to load should be not less than 1 but provided value is " + pageCount);
filesLock.acquireReadLock();
try {
final PageKey[] pageKeys = new PageKey[pageCount];
for (int i = 0; i < pageCount; i++) {
pageKeys[i] = new PageKey(intId, startPageIndex + i);
}
Lock[] pageLocks = lockManager.acquireSharedLocksInBatch(pageKeys);
try {
PageGroup pageGroup = writeCachePages.get(pageKeys[0]);
if (pageGroup == null) {
final OCachePointer[] pagePointers = cacheFileContent(intId, startPageIndex, pageCount, addNewPages, cacheHit);
if (pagePointers.length == 0)
return pagePointers;
for (int n = 0; n < pagePointers.length; n++) {
pagePointers[n].incrementReadersReferrer();
if (n > 0) {
pageGroup = writeCachePages.get(pageKeys[n]);
assert pageKeys[n].pageIndex == pagePointers[n].getPageIndex();
if (pageGroup != null) {
pagePointers[n].decrementReadersReferrer();
pagePointers[n] = pageGroup.page;
pagePointers[n].incrementReadersReferrer();
}
}
}
return pagePointers;
}
final OCachePointer pagePointer = pageGroup.page;
pagePointer.incrementReadersReferrer();
cacheHit.setValue(true);
return new OCachePointer[] { pagePointer };
} catch (InterruptedException e) {
throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
} finally {
for (Lock lock : pageLocks) {
lock.unlock();
}
}
} finally {
filesLock.releaseReadLock();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method addFile.
public long addFile(String fileName) throws IOException {
filesLock.acquireWriteLock();
try {
Integer fileId = nameIdMap.get(fileName);
OFileClassic fileClassic;
if (fileId != null && fileId >= 0)
throw new OStorageException("File with name " + fileName + " already exists in storage " + storageLocal.getName());
if (fileId == null) {
++fileCounter;
fileId = fileCounter;
} else
fileId = -fileId;
fileClassic = createFileInstance(fileName);
createFile(fileClassic);
final long externalId = composeFileId(id, fileId);
files.add(externalId, fileClassic);
nameIdMap.put(fileName, fileId);
writeNameIdEntry(new NameFileIdEntry(fileName, fileId), true);
return externalId;
} catch (InterruptedException e) {
throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
} finally {
filesLock.releaseWriteLock();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class O2QCache method clearPinnedPages.
private void clearPinnedPages() {
for (OCacheEntry pinnedEntry : pinnedPages.values()) {
if (pinnedEntry.getUsagesCount() == 0) {
final OCachePointer cachePointer = pinnedEntry.getCachePointer();
cachePointer.decrementReadersReferrer();
pinnedEntry.clearCachePointer();
MemoryData memoryData = memoryDataContainer.get();
MemoryData newMemoryData = new MemoryData(memoryData.maxSize, memoryData.pinnedPages - 1);
while (!memoryDataContainer.compareAndSet(memoryData, newMemoryData)) {
memoryData = memoryDataContainer.get();
newMemoryData = new MemoryData(memoryData.maxSize, memoryData.pinnedPages - 1);
}
} else
throw new OStorageException("Page with index " + pinnedEntry.getPageIndex() + " for file with id " + pinnedEntry.getFileId() + "cannot be freed because it is used.");
}
pinnedPages.clear();
}
Aggregations