use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method loadFile.
public long loadFile(final String fileName) throws IOException {
filesLock.acquireWriteLock();
try {
Integer fileId = nameIdMap.get(fileName);
OFileClassic fileClassic;
//check that file is already registered
if (!(fileId == null || fileId < 0)) {
final long externalId = composeFileId(id, fileId);
fileClassic = files.get(externalId);
if (fileClassic != null)
return externalId;
else
throw new OStorageException("File with given name " + fileName + " only partially registered in storage");
}
fileClassic = createFileInstance(fileName);
if (!fileClassic.exists())
throw new OStorageException("File with name " + fileName + " does not exist in storage " + storageLocal.getName());
else {
// REGISTER THE FILE
OLogManager.instance().debug(this, "File '" + fileName + "' is not registered in 'file name - id' map, but exists in file system. Registering it");
if (fileId == null) {
++fileCounter;
fileId = fileCounter;
} else
fileId = -fileId;
long externalId = composeFileId(id, fileId);
while (files.get(externalId) != null) {
++fileCounter;
fileId = fileCounter;
externalId = composeFileId(id, fileId);
}
openFile(fileClassic);
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 clearFile.
private void clearFile(long fileId) {
final Set<Long> pageEntries = filePages.get(fileId);
if (pageEntries == null || pageEntries.isEmpty()) {
assert get(fileId, 0, true) == null;
return;
}
for (Long pageIndex : pageEntries) {
OCacheEntry cacheEntry = get(fileId, pageIndex, true);
if (cacheEntry == null)
cacheEntry = pinnedPages.get(new PinnedPage(fileId, pageIndex));
if (cacheEntry != null) {
if (cacheEntry.getUsagesCount() == 0) {
cacheEntry = remove(fileId, pageIndex);
if (cacheEntry == null) {
MemoryData memoryData = memoryDataContainer.get();
cacheEntry = pinnedPages.remove(new PinnedPage(fileId, pageIndex));
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);
}
}
final OCachePointer cachePointer = cacheEntry.getCachePointer();
if (cachePointer != null) {
cachePointer.decrementReadersReferrer();
cacheEntry.clearCachePointer();
}
} else
throw new OStorageException("Page with index " + pageIndex + " for file with id " + fileId + " cannot be freed because it is used.");
} else
throw new OStorageException("Page with index " + pageIndex + " was not found in cache for file with id " + fileId);
}
assert get(fileId, 0, true) == null;
pageEntries.clear();
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OClusterPositionMapBucket method set.
public void set(final int index, final PositionEntry entry) throws IOException {
final int size = getIntValue(SIZE_OFFSET);
if (index >= size)
throw new OStorageException("Provided index " + index + " is out of range");
final int position = entryPosition(index);
final byte flag = getByteValue(position);
if (flag == ALLOCATED)
setByteValue(position, FILLED);
else if (flag != FILLED)
throw new OStorageException("Provided index " + index + " points to removed entry");
updateEntry(position, entry);
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OClusterPositionMapBucket method resurrect.
public void resurrect(final int index, final PositionEntry entry) throws IOException {
final int size = getIntValue(SIZE_OFFSET);
if (index >= size)
throw new OStorageException("Cannot resurrect a record: provided index " + index + " is out of range");
final int position = entryPosition(index);
final byte flag = getByteValue(position);
if (flag == REMOVED)
setByteValue(position, FILLED);
else
throw new OStorageException("Cannot resurrect a record: provided index " + index + " points to a non removed entry");
updateEntry(position, entry);
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method checkStoredPages.
public OPageDataVerificationError[] checkStoredPages(OCommandOutputListener commandOutputListener) {
final int notificationTimeOut = 5000;
final List<OPageDataVerificationError> errors = new ArrayList<OPageDataVerificationError>();
filesLock.acquireWriteLock();
try {
for (Integer intId : nameIdMap.values()) {
if (intId < 0)
continue;
boolean fileIsCorrect;
final long externalId = composeFileId(id, intId);
final OClosableEntry<Long, OFileClassic> entry = files.acquire(externalId);
final OFileClassic fileClassic = entry.get();
try {
if (commandOutputListener != null)
commandOutputListener.onMessage("Flashing file " + fileClassic.getName() + "... ");
flush(intId);
if (commandOutputListener != null)
commandOutputListener.onMessage("Start verification of content of " + fileClassic.getName() + "file ...");
long time = System.currentTimeMillis();
long filledUpTo = fileClassic.getFileSize();
fileIsCorrect = true;
for (long pos = 0; pos < filledUpTo; pos += pageSize) {
boolean checkSumIncorrect = false;
boolean magicNumberIncorrect = false;
byte[] data = new byte[pageSize];
fileClassic.read(pos, data, data.length);
long magicNumber = OLongSerializer.INSTANCE.deserializeNative(data, 0);
if (magicNumber != MAGIC_NUMBER) {
magicNumberIncorrect = true;
if (commandOutputListener != null)
commandOutputListener.onMessage("Error: Magic number for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " does not much !!!");
fileIsCorrect = false;
}
final int storedCRC32 = OIntegerSerializer.INSTANCE.deserializeNative(data, OLongSerializer.LONG_SIZE);
final int calculatedCRC32 = calculatePageCrc(data);
if (storedCRC32 != calculatedCRC32) {
checkSumIncorrect = true;
if (commandOutputListener != null)
commandOutputListener.onMessage("Error: Checksum for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " is incorrect !!!");
fileIsCorrect = false;
}
if (magicNumberIncorrect || checkSumIncorrect)
errors.add(new OPageDataVerificationError(magicNumberIncorrect, checkSumIncorrect, pos / pageSize, fileClassic.getName()));
if (commandOutputListener != null && System.currentTimeMillis() - time > notificationTimeOut) {
time = notificationTimeOut;
commandOutputListener.onMessage((pos / pageSize) + " pages were processed ...");
}
}
} catch (IOException ioe) {
if (commandOutputListener != null)
commandOutputListener.onMessage("Error: Error during processing of file " + fileClassic.getName() + ". " + ioe.getMessage());
fileIsCorrect = false;
} finally {
files.release(entry);
}
if (!fileIsCorrect) {
if (commandOutputListener != null)
commandOutputListener.onMessage("Verification of file " + fileClassic.getName() + " is finished with errors.");
} else {
if (commandOutputListener != null)
commandOutputListener.onMessage("Verification of file " + fileClassic.getName() + " is successfully finished.");
}
}
return errors.toArray(new OPageDataVerificationError[errors.size()]);
} catch (InterruptedException e) {
throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
} finally {
filesLock.releaseWriteLock();
}
}
Aggregations