use of org.apache.ignite.internal.pagememory.freelist.io.PagesListMetaIo in project ignite-3 by apache.
the class PagesList method init.
/**
* Initializes a {@link PagesList}.
*
* @param metaPageId Metadata page ID.
* @param initNew {@code True} if new list if created, {@code false} if should be initialized from metadata.
* @throws IgniteInternalCheckedException If failed.
*/
protected final void init(long metaPageId, boolean initNew) throws IgniteInternalCheckedException {
if (metaPageId != 0L) {
if (initNew) {
init(metaPageId, PagesListMetaIo.VERSIONS.latest());
} else {
Map<Integer, LongArrayList> bucketsData = new HashMap<>();
long nextId = metaPageId;
while (nextId != 0) {
final long pageId = nextId;
final long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
try {
// No concurrent recycling on init.
long pageAddr = readLock(pageId, page);
assert pageAddr != 0L;
try {
PagesListMetaIo io = PagesListMetaIo.VERSIONS.forPage(pageAddr);
io.getBucketsData(pageAddr, bucketsData);
nextId = io.getNextMetaPageId(pageAddr);
assert nextId != pageId : "Loop detected [next=" + hexLong(nextId) + ", cur=" + hexLong(pageId) + ']';
} finally {
readUnlock(pageId, page, pageAddr);
}
} finally {
releasePage(pageId, page);
}
}
for (Map.Entry<Integer, LongArrayList> e : bucketsData.entrySet()) {
int bucket = e.getKey();
long bucketSize = 0;
Stripe[] old = getBucket(bucket);
assert old == null;
long[] upd = e.getValue().toLongArray();
Stripe[] tails = new Stripe[upd.length];
for (int i = 0; i < upd.length; i++) {
long tailId = upd[i];
long prevId = tailId;
int cnt = 0;
while (prevId != 0L) {
final long pageId = prevId;
final long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
try {
long pageAddr = readLock(pageId, page);
assert pageAddr != 0L;
try {
PagesListNodeIo io = PagesListNodeIo.VERSIONS.forPage(pageAddr);
cnt += io.getCount(pageAddr);
prevId = io.getPreviousId(pageAddr);
// In reuse bucket the page itself can be used as a free page.
if (isReuseBucket(bucket) && prevId != 0L) {
cnt++;
}
} finally {
readUnlock(pageId, page, pageAddr);
}
} finally {
releasePage(pageId, page);
}
}
Stripe stripe = new Stripe(tailId, cnt == 0);
tails[i] = stripe;
bucketSize += cnt;
}
boolean ok = casBucket(bucket, null, tails);
assert ok;
bucketsSize.set(bucket, bucketSize);
}
}
}
}
use of org.apache.ignite.internal.pagememory.freelist.io.PagesListMetaIo in project ignite-3 by apache.
the class RandomLruPageReplacementPolicy method isStoreMetadataPage.
/**
* Return {@code true} if page is related to metadata.
*
* @param absPageAddr Absolute page address
*/
private boolean isStoreMetadataPage(long absPageAddr) {
try {
long dataAddr = absPageAddr + PAGE_OVERHEAD;
PageIo io = seg.ioRegistry().resolve(dataAddr);
return io instanceof PagesListMetaIo;
} catch (IgniteInternalCheckedException ignored) {
return false;
}
}
use of org.apache.ignite.internal.pagememory.freelist.io.PagesListMetaIo in project ignite-3 by apache.
the class PagesList method markUnusedPagesDirty.
/**
* Mark unused pages as dirty.
*
* @param nextPageId First unused page.
* @throws IgniteInternalCheckedException If failed.
*/
private void markUnusedPagesDirty(long nextPageId) throws IgniteInternalCheckedException {
while (nextPageId != 0L) {
long pageId = nextPageId;
long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
try {
long pageAddr = writeLock(pageId, page);
try {
PagesListMetaIo io = PagesListMetaIo.VERSIONS.forPage(pageAddr);
io.resetCount(pageAddr);
nextPageId = io.getNextMetaPageId(pageAddr);
} finally {
writeUnlock(pageId, page, pageAddr, true);
}
} finally {
releasePage(pageId, page);
}
}
}
use of org.apache.ignite.internal.pagememory.freelist.io.PagesListMetaIo in project ignite-3 by apache.
the class PagesList method writeFreeList.
/**
* Write free list data to page memory.
*
* @param nextPageId First free page id.
* @return Unused free list page id.
* @throws IgniteInternalCheckedException If failed.
*/
private long writeFreeList(long nextPageId) throws IgniteInternalCheckedException {
long curId = 0L;
long curPage = 0L;
long curAddr = 0L;
PagesListMetaIo curIo = null;
try {
for (int bucket = 0; bucket < buckets; bucket++) {
Stripe[] tails = getBucket(bucket);
if (tails != null) {
int tailIdx = 0;
while (tailIdx < tails.length) {
int written = curPage != 0L ? curIo.addTails(pageMem.realPageSize(grpId), curAddr, bucket, tails, tailIdx) : 0;
if (written == 0) {
if (nextPageId == 0L) {
nextPageId = allocatePageNoReuse();
if (curPage != 0L) {
curIo.setNextMetaPageId(curAddr, nextPageId);
releaseAndWriteUnlock(curId, curPage, curAddr);
}
curId = nextPageId;
curPage = acquirePage(curId, IoStatisticsHolderNoOp.INSTANCE);
curAddr = writeLock(curId, curPage);
curIo = PagesListMetaIo.VERSIONS.latest();
curIo.initNewPage(curAddr, curId, pageSize());
} else {
releaseAndWriteUnlock(curId, curPage, curAddr);
curId = nextPageId;
curPage = acquirePage(curId, IoStatisticsHolderNoOp.INSTANCE);
curAddr = writeLock(curId, curPage);
curIo = PagesListMetaIo.VERSIONS.forPage(curAddr);
curIo.resetCount(curAddr);
}
nextPageId = curIo.getNextMetaPageId(curAddr);
} else {
tailIdx += written;
}
}
}
}
} finally {
releaseAndWriteUnlock(curId, curPage, curAddr);
}
return nextPageId;
}
Aggregations