use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesListRemovePageRecord method applyDelta.
/**
* {@inheritDoc}
*/
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
boolean rmvd = io.removePage(pageAddr, rmvdPageId);
assert rmvd;
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesListSetPreviousRecord method applyDelta.
/**
* {@inheritDoc}
*/
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
io.setPreviousId(pageAddr, prevPageId);
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesList method merge.
/**
* @param pageId Page ID.
* @param page Page pointer.
* @param nextId Next page ID.
* @param bucket Bucket index.
* @param statHolder Statistics holder to track IO operations.
* @return Page ID to recycle.
* @throws IgniteCheckedException If failed.
*/
private long merge(final long pageId, final long page, long nextId, int bucket, IoStatisticsHolder statHolder) throws IgniteCheckedException {
// We should do mergeNoNext then.
assert nextId != 0;
// Lock all the pages in correct order (from next to previous) and do the merge in retry loop.
for (; ; ) {
final long curId = nextId;
final long curPage = curId == 0L ? 0L : acquirePage(curId, statHolder);
try {
boolean write = false;
// Explicit check.
final long curAddr = curPage == 0L ? 0L : writeLock(curId, curPage);
// Explicit check.
final long pageAddr = writeLock(pageId, page);
if (pageAddr == 0L) {
if (// Unlock next page if needed.
curAddr != 0L)
writeUnlock(curId, curPage, curAddr, false);
// Someone has merged or taken our empty page concurrently. Nothing to do here.
return 0L;
}
try {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
if (!io.isEmpty(pageAddr))
// No need to merge anymore.
return 0L;
// Check if we see a consistent state of the world.
if (io.getNextId(pageAddr) == curId && (curId == 0L) == (curAddr == 0L)) {
long recycleId = doMerge(pageId, page, pageAddr, io, curId, curPage, curAddr, bucket, statHolder);
write = true;
// Done.
return recycleId;
}
// Reread next page ID and go for retry.
nextId = io.getNextId(pageAddr);
} finally {
if (curAddr != 0L)
writeUnlock(curId, curPage, curAddr, write);
writeUnlock(pageId, page, pageAddr, write);
}
} finally {
if (curPage != 0L)
releasePage(curId, curPage);
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.
the class PagesList method storedPagesCount.
/**
* !!! For tests only, does not provide any correctness guarantees for concurrent access.
*
* @param bucket Bucket index.
* @return Number of pages stored in this list.
* @throws IgniteCheckedException If failed.
*/
protected final long storedPagesCount(int bucket) throws IgniteCheckedException {
long res = 0;
Stripe[] tails = getBucket(bucket);
if (tails != null) {
for (Stripe tail : tails) {
long tailId = tail.tailId;
while (tailId != 0L) {
final long pageId = tailId;
final long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
try {
long pageAddr = readLock(pageId, page);
assert pageAddr != 0L;
try {
PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
int cnt = io.getCount(pageAddr);
assert cnt >= 0;
res += cnt;
tailId = io.getPreviousId(pageAddr);
// In reuse bucket the page itself can be used as a free page.
if (isReuseBucket(bucket) && tailId != 0L)
res++;
} finally {
readUnlock(pageId, page, pageAddr);
}
} finally {
releasePage(pageId, page);
}
}
}
}
assert res == bucketsSize.get(bucket) : "Wrong bucket size counter [exp=" + res + ", cntr=" + bucketsSize.get(bucket) + ']';
return res;
}
use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.
the class IgniteIndexReader method getPageList.
/**
* Get single page list.
*
* @param pageListStartId Id of the start page of the page list.
* @param pageStat Page types statistics.
* @return List of page ids.
*/
private List<Long> getPageList(long pageListStartId, Map<Class, Long> pageStat) {
List<Long> res = new LinkedList<>();
long nextNodeId = pageListStartId;
ByteBuffer nodeBuf = allocateBuffer(pageSize);
ByteBuffer pageBuf = allocateBuffer(pageSize);
long nodeAddr = bufferAddress(nodeBuf);
long pageAddr = bufferAddress(pageBuf);
try {
while (nextNodeId != 0) {
try {
nodeBuf.rewind();
readPage(idxStore, nextNodeId, nodeBuf);
PagesListNodeIO io = PageIO.getPageIO(nodeAddr);
for (int i = 0; i < io.getCount(nodeAddr); i++) {
pageBuf.rewind();
long pageId = normalizePageId(io.getAt(nodeAddr, i));
res.add(pageId);
readPage(idxStore, pageId, pageBuf);
PageIO pageIO = PageIO.getPageIO(pageAddr);
pageStat.compute(pageIO.getClass(), (k, v) -> v == null ? 1 : v + 1);
}
nextNodeId = io.getNextId(nodeAddr);
} catch (IgniteCheckedException e) {
throw new IgniteException(e.getMessage(), e);
}
}
} finally {
freeBuffer(nodeBuf);
freeBuffer(pageBuf);
}
return res;
}
Aggregations