use of org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesListSetNextRecord method applyDelta.
/** {@inheritDoc} */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
io.setNextId(pageAddr, nextPageId);
}
use of org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesListAddPageRecord method applyDelta.
/** {@inheritDoc} */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
int cnt = io.addPage(pageAddr, dataPageId, pageMem.pageSize());
assert cnt >= 0 : cnt;
}
use of org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesListInitNewPageRecord method applyDelta.
/** {@inheritDoc} */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
PagesListNodeIO io = PageIO.getPageIO(PageIO.T_PAGE_LIST_NODE, ioVer);
io.initNewPage(pageAddr, pageId(), pageMem.pageSize());
io.setPreviousId(pageAddr, prevPageId);
if (addDataPageId != 0L) {
int cnt = io.addPage(pageAddr, addDataPageId, pageMem.pageSize());
assert cnt == 0 : cnt;
}
}
use of org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesList method removeDataPage.
/**
* @param dataId Data page ID.
* @param dataPage Data page pointer.
* @param dataAddr Data page address.
* @param dataIO Data page IO.
* @param bucket Bucket index.
* @throws IgniteCheckedException If failed.
* @return {@code True} if page was removed.
*/
protected final boolean removeDataPage(final long dataId, final long dataPage, final long dataAddr, DataPageIO dataIO, int bucket) throws IgniteCheckedException {
final long pageId = dataIO.getFreeListPageId(dataAddr);
assert pageId != 0;
final long page = acquirePage(pageId);
try {
long nextId;
long recycleId = 0L;
// Explicit check.
long pageAddr = writeLock(pageId, page);
if (pageAddr == 0L)
return false;
boolean rmvd = false;
try {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
rmvd = io.removePage(pageAddr, dataId);
if (!rmvd)
return false;
bucketsSize[bucket].decrementAndGet();
if (needWalDeltaRecord(pageId, page, null))
wal.log(new PagesListRemovePageRecord(cacheId, pageId, dataId));
// Reset free list page ID.
dataIO.setFreeListPageId(dataAddr, 0L);
if (needWalDeltaRecord(dataId, dataPage, null))
wal.log(new DataPageSetFreeListPageRecord(cacheId, dataId, 0L));
if (!io.isEmpty(pageAddr))
// In optimistic case we still have something in the page and can leave it as is.
return true;
// If the page is empty, we have to try to drop it and link next and previous with each other.
nextId = io.getNextId(pageAddr);
// because if we will need to lock previous page, the locking order will be already correct.
if (nextId == 0L) {
long prevId = io.getPreviousId(pageAddr);
recycleId = mergeNoNext(pageId, page, pageAddr, prevId, bucket);
}
} finally {
writeUnlock(pageId, page, pageAddr, rmvd);
}
// Perform a fair merge after lock release (to have a correct locking order).
if (nextId != 0L)
recycleId = merge(pageId, page, nextId, bucket);
if (recycleId != 0L)
reuseList.addForRecycle(new SingletonReuseBag(recycleId));
return true;
} finally {
releasePage(pageId, page);
}
}
use of org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesList method fairMerge.
/**
* Link previous and next to each other.
* @param prevId Previous Previous page ID.
* @param pageId Page ID.
* @param nextId Next page ID.
* @param nextPage Next page absolute pointer.
* @param nextAddr Next page address.
* @throws IgniteCheckedException If failed.
*/
private void fairMerge(final long prevId, long pageId, long nextId, long nextPage, long nextAddr) throws IgniteCheckedException {
long prevPage = acquirePage(prevId);
try {
// No check, we keep a reference.
final long prevAddr = writeLock(prevId, prevPage);
assert prevAddr != 0L;
try {
PagesListNodeIO prevIO = PagesListNodeIO.VERSIONS.forPage(prevAddr);
PagesListNodeIO nextIO = PagesListNodeIO.VERSIONS.forPage(nextAddr);
// These references must be updated at the same time in write locks.
assert prevIO.getNextId(prevAddr) == pageId;
assert nextIO.getPreviousId(nextAddr) == pageId;
prevIO.setNextId(prevAddr, nextId);
if (needWalDeltaRecord(prevId, prevPage, null))
wal.log(new PagesListSetNextRecord(cacheId, prevId, nextId));
nextIO.setPreviousId(nextAddr, prevId);
if (needWalDeltaRecord(nextId, nextPage, null))
wal.log(new PagesListSetPreviousRecord(cacheId, nextId, prevId));
} finally {
writeUnlock(prevId, prevPage, prevAddr, true);
}
} finally {
releasePage(prevId, prevPage);
}
}
Aggregations