use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class LRUListTest method testSingleAdd.
@Test
public void testSingleAdd() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
final ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, 10, cachePointer, false));
Iterator<OCacheEntry> entryIterator = lruList.iterator();
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 10, cachePointer, false));
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OAtomicOperation method addPage.
public OCacheEntry addPage(long fileId) throws IOException {
fileId = checkFileIdCompatibilty(fileId, storageId);
if (deletedFiles.contains(fileId))
throw new OStorageException("File with id " + fileId + " is deleted.");
final FileChanges changesContainer = fileChanges.get(fileId);
assert changesContainer != null;
final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(filledUpTo);
assert pageChangesContainer == null;
pageChangesContainer = new FilePageChanges();
pageChangesContainer.isNew = true;
changesContainer.pageChangesMap.put(filledUpTo, pageChangesContainer);
changesContainer.maxNewPageIndex = filledUpTo;
return new OCacheEntry(fileId, filledUpTo, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, filledUpTo), false);
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OAtomicOperation method commitChanges.
public void commitChanges(OWriteAheadLog writeAheadLog) throws IOException {
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.startCommitTimer();
sessionStoragePerformanceStatistic.startComponentOperation("atomic operation", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
}
try {
if (writeAheadLog != null) {
for (long deletedFileId : deletedFiles) {
writeAheadLog.log(new OFileDeletedWALRecord(operationUnitId, deletedFileId));
}
for (Map.Entry<Long, FileChanges> fileChangesEntry : fileChanges.entrySet()) {
final FileChanges fileChanges = fileChangesEntry.getValue();
final long fileId = fileChangesEntry.getKey();
if (fileChanges.isNew)
writeAheadLog.log(new OFileCreatedWALRecord(operationUnitId, fileChanges.fileName, fileId));
else if (fileChanges.truncate)
writeAheadLog.log(new OFileTruncatedWALRecord(operationUnitId, fileId));
Iterator<Map.Entry<Long, FilePageChanges>> filePageChangesIterator = fileChanges.pageChangesMap.entrySet().iterator();
while (filePageChangesIterator.hasNext()) {
Map.Entry<Long, FilePageChanges> filePageChangesEntry = filePageChangesIterator.next();
//I assume new pages have everytime changes
if (filePageChangesEntry.getValue().changes.hasChanges()) {
final long pageIndex = filePageChangesEntry.getKey();
final FilePageChanges filePageChanges = filePageChangesEntry.getValue();
filePageChanges.lsn = writeAheadLog.log(new OUpdatePageRecord(pageIndex, fileId, operationUnitId, filePageChanges.changes));
} else
filePageChangesIterator.remove();
}
}
}
for (long deletedFileId : deletedFiles) {
readCache.deleteFile(deletedFileId, writeCache);
}
for (Map.Entry<Long, FileChanges> fileChangesEntry : fileChanges.entrySet()) {
final FileChanges fileChanges = fileChangesEntry.getValue();
final long fileId = fileChangesEntry.getKey();
if (fileChanges.isNew)
readCache.addFile(fileChanges.fileName, newFileNamesId.get(fileChanges.fileName), writeCache);
else if (fileChanges.truncate)
readCache.truncateFile(fileId, writeCache);
for (Map.Entry<Long, FilePageChanges> filePageChangesEntry : fileChanges.pageChangesMap.entrySet()) {
final FilePageChanges filePageChanges = filePageChangesEntry.getValue();
if (!filePageChanges.changes.hasChanges())
continue;
final long pageIndex = filePageChangesEntry.getKey();
OCacheEntry cacheEntry = filePageChanges.isNew ? null : pageCache.purgePage(fileId, pageIndex, writeCache);
if (cacheEntry == null) {
cacheEntry = readCache.load(fileId, pageIndex, true, writeCache, 1);
if (cacheEntry == null) {
assert filePageChanges.isNew;
do {
if (cacheEntry != null)
readCache.release(cacheEntry, writeCache);
cacheEntry = readCache.allocateNewPage(fileId, writeCache);
} while (cacheEntry.getPageIndex() != pageIndex);
}
}
cacheEntry.acquireExclusiveLock();
try {
ODurablePage durablePage = new ODurablePage(cacheEntry, null);
durablePage.restoreChanges(filePageChanges.changes);
if (writeAheadLog != null)
durablePage.setLsn(filePageChanges.lsn);
if (filePageChanges.pinPage)
readCache.pinPage(cacheEntry);
} finally {
cacheEntry.releaseExclusiveLock();
readCache.release(cacheEntry, writeCache);
}
}
}
} finally {
pageCache.reset(writeCache);
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.stopCommitTimer();
sessionStoragePerformanceStatistic.completeComponentOperation();
}
}
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry 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.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OPaginatedCluster method getPhysicalPosition.
@Override
public OPhysicalPosition getPhysicalPosition(OPhysicalPosition position) throws IOException {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
long clusterPosition = position.clusterPosition;
OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition, 1);
if (positionEntry == null)
return null;
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
long pageIndex = positionEntry.getPageIndex();
int recordPosition = positionEntry.getRecordPosition();
long pagesCount = getFilledUpTo(atomicOperation, fileId);
if (pageIndex >= pagesCount)
return null;
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
try {
final OClusterPage localPage = new OClusterPage(cacheEntry, false, getChanges(atomicOperation, cacheEntry));
if (localPage.isDeleted(recordPosition))
return null;
if (localPage.getRecordByteValue(recordPosition, -OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE) == 0)
return null;
final OPhysicalPosition physicalPosition = new OPhysicalPosition();
physicalPosition.recordSize = -1;
physicalPosition.recordType = localPage.getRecordByteValue(recordPosition, 0);
physicalPosition.recordVersion = localPage.getRecordVersion(recordPosition);
physicalPosition.clusterPosition = position.clusterPosition;
return physicalPosition;
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
Aggregations