/** * @return Full page ID. */ public FullPageId fullPageId() { return new FullPageId(pageId, grpId); }
/** {@inheritDoc} */ @Override public void writeUnlock(int grpId, long pageId, long page, Boolean walPlc, boolean dirtyFlag, boolean restore) { writeUnlockPage(page, new FullPageId(pageId, grpId), walPlc, dirtyFlag, restore); }
/** {@inheritDoc} */ @Override public long writeLock(int grpId, long pageId, long page, boolean restore) { return writeLockPage(page, new FullPageId(pageId, grpId), !restore); }
/** {@inheritDoc} */ @Override public long tryWriteLock(int grpId, long pageId, long page) { return tryWriteLockPage(page, new FullPageId(pageId, grpId), true); }
/** {@inheritDoc} */ @Override public RootPage rootPageForIndex(int cacheId, String idxName, int segment) throws IgniteCheckedException { long pageId = allocateForTree(); return new RootPage(new FullPageId(pageId, grp.groupId()), true); }
/** * Returns Full page ID. For index 0 will return super-page of next partition * * @param pageIdx Page Index, monotonically growing number within each partition * @return FullPageId consists of cache ID (32 bits) and page ID (64 bits). */ @NotNull private FullPageId createFullPageId(final int pageIdx) { return new FullPageId(createPageId(pageIdx), getGroupId()); }
/** * @param base bucket base address. * @return Key. Full page ID from bucket. */ @NotNull private FullPageId getFullPageId(long base) { return new FullPageId(getPageId(base), getGrpId(base)); } }
/** {@inheritDoc} */ @Override public RootPage dropIndex(final String idxName) throws IgniteCheckedException { byte[] idxNameBytes = idxName.getBytes(StandardCharsets.UTF_8); final IndexItem row = metaTree.remove(new IndexItem(idxNameBytes, 0)); if (row != null) { if (reuseList == null) pageMem.freePage(grpId, row.pageId); } return row != null ? new RootPage(new FullPageId(row.pageId, grpId), false) : null; }
/** * Reads page ID and cache group ID from the page at the given absolute pointer. * * @param absPtr Absolute memory pointer to the page header. * @return Full page ID written to the page. */ private static FullPageId fullPageId(final long absPtr) { return new FullPageId(readPageId(absPtr), readPageGroupId(absPtr)); }
/** * @return Allocated meta page ID. * @throws IgniteCheckedException If failed. */ private FullPageId allocateMetaPage() throws IgniteCheckedException { return new FullPageId(pageMem.allocatePage(CACHE_ID, PageIdAllocator.INDEX_PARTITION, PageIdAllocator.FLAG_IDX), CACHE_ID); }
/** * @param mem Memory. * @return Page. * @throws IgniteCheckedException If failed. */ public static FullPageId allocatePage(PageIdAllocator mem) throws IgniteCheckedException { return new FullPageId(mem.allocatePage(-1, 1, PageIdAllocator.FLAG_DATA), -1); } }
/** {@inheritDoc} */ @Override public RootPage allocateIndex(String idxName) throws IgniteCheckedException { final MetaTree tree = metaTree; synchronized (this) { byte[] idxNameBytes = idxName.getBytes(StandardCharsets.UTF_8); if (idxNameBytes.length > MAX_IDX_NAME_LEN) throw new IllegalArgumentException("Too long encoded indexName [maxAllowed=" + MAX_IDX_NAME_LEN + ", currentLength=" + idxNameBytes.length + ", name=" + idxName + "]"); final IndexItem row = tree.findOne(new IndexItem(idxNameBytes, 0)); if (row == null) { long pageId = 0; if (reuseList != null) pageId = reuseList.takeRecycledPage(); pageId = pageId == 0 ? pageMem.allocatePage(grpId, allocPartId, allocSpace) : pageId; tree.put(new IndexItem(idxNameBytes, pageId)); return new RootPage(new FullPageId(pageId, grpId), true); } else { final FullPageId pageId = new FullPageId(row.pageId, grpId); return new RootPage(pageId, false); } } }
/** {@inheritDoc} */ @Override public void forEach(BiConsumer<FullPageId, Long> act) { for (int i = 0; i < capacity; i++) { if (isValuePresentAt(i)) { long base = entryBase(i); int cacheId = GridUnsafe.getInt(base); long pageId = GridUnsafe.getLong(base + PAGE_ID_OFFSET); long val = GridUnsafe.getLong(base + VALUE_OFFSET); act.accept(new FullPageId(pageId, cacheId), val); } } }
/** {@inheritDoc} */ @Override public int pages(int grpId, int partId) throws IgniteCheckedException { long root = PageIdUtils.pageId(partId, (byte)0, 0); FullPageId fullId = new FullPageId(root, grpId); AtomicInteger allocator = allocators.get(fullId); if (allocator == null) allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(2)); return allocator.get(); }
/** {@inheritDoc} */ @Override public int write(ByteBuffer srcBuf, long position) throws IOException { FullPageId fId = new FullPageId( PageIdUtils.pageId(partId, PageIdAllocator.FLAG_DATA, (int)(position / PAGE_SIZE) - 1), grpId); if (forbiddenPages.contains(fId)) throw new AssertionError("Attempted to write invalid page on recovery: " + fId); return super.write(srcBuf, position); }
/** {@inheritDoc} */ @Override public ReplaceCandidate getNearestAt(final int idxStart) { for (int i = idxStart; i < capacity + idxStart; i++) { final int idx2 = normalizeIndex(i); if (isValuePresentAt(idx2)) { long base = entryBase(idx2); int grpId = GridUnsafe.getInt(base); int tag = GridUnsafe.getInt(base + TAG_OFFSET); long pageId = GridUnsafe.getLong(base + PAGE_ID_OFFSET); long val = GridUnsafe.getLong(base + VALUE_OFFSET); return new ReplaceCandidate(tag, val, new FullPageId(pageId, grpId)); } } return null; }
/** {@inheritDoc} */ @Override public long allocatePage(int grpId, int partId, byte flags) throws IgniteCheckedException { long root = PageIdUtils.pageId(partId, flags, 0); FullPageId fullId = new FullPageId(root, grpId); AtomicInteger allocator = allocators.get(fullId); if (allocator == null) allocator = F.addIfAbsent(allocators, fullId, new AtomicInteger(1)); return PageIdUtils.pageId(partId, flags, allocator.getAndIncrement()); }
cpPages.remove(new FullPageId(pageId, grpId)); dirtyPages.remove(new FullPageId(pageId, grpId));
/** * */ @Test public void testCollisionOnRemove() { Map<FullPageId, Long> ctrl = new LinkedHashMap<>(); int cap = 10; FullPageId baseId = new FullPageId(0, 1); withMap(map -> { for (int i = 0; i < cap; i++) { int grpId = i + 1; int pageId = findPageIdForCollision(grpId, baseId, cap); ctrl.put(new FullPageId(pageId, grpId), (long)grpId); map.put(grpId, pageId, (long)grpId, 1); } for (FullPageId next : ctrl.keySet()) { assertTrue(map.remove(next.groupId(), next.pageId())); } }, cap); }
check.put(new FullPageId(pageId, grpId), val);