use of org.apache.ignite.internal.pagemem.FullPageId in project ignite by apache.
the class MetadataStorageSelfTest method metaAllocation.
/**
* @throws Exception If failed.
*/
private void metaAllocation() throws Exception {
PageMemory mem = memory(true);
int[] cacheIds = new int[] { 1, "partitioned".hashCode(), "replicated".hashCode() };
Map<Integer, Map<String, RootPage>> allocatedIdxs = new HashMap<>();
mem.start();
try {
final Map<Integer, MetadataStorage> storeMap = new HashMap<>();
for (int i = 0; i < 1_000; i++) {
int cacheId = cacheIds[i % cacheIds.length];
Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
if (idxMap == null) {
idxMap = new HashMap<>();
allocatedIdxs.put(cacheId, idxMap);
}
String idxName;
do {
idxName = randomName();
} while (idxMap.containsKey(idxName));
MetadataStorage metaStore = storeMap.get(cacheId);
if (metaStore == null) {
metaStore = new MetadataStorage(mem, null, new AtomicLong(), cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX, null, mem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX), true);
storeMap.put(cacheId, metaStore);
}
final RootPage rootPage = metaStore.getOrAllocateForTree(idxName);
assertTrue(rootPage.isAllocated());
idxMap.put(idxName, rootPage);
}
for (int cacheId : cacheIds) {
Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
for (Map.Entry<String, RootPage> entry : idxMap.entrySet()) {
String idxName = entry.getKey();
FullPageId rootPageId = entry.getValue().pageId();
final RootPage rootPage = storeMap.get(cacheId).getOrAllocateForTree(idxName);
assertEquals("Invalid root page ID restored [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPageId, rootPage.pageId());
assertFalse("Root page already allocated [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPage.isAllocated());
}
}
} finally {
mem.stop();
}
}
use of org.apache.ignite.internal.pagemem.FullPageId in project ignite by apache.
the class PageMemoryNoLoadSelfTest method testPageHandleDeallocation.
/**
* @throws Exception If failed.
*/
public void testPageHandleDeallocation() throws Exception {
PageMemory mem = memory();
mem.start();
try {
int pages = 3 * 1024 * 1024 / (8 * 1024);
Collection<FullPageId> handles = new HashSet<>();
for (int i = 0; i < pages; i++) handles.add(allocatePage(mem));
for (FullPageId fullId : handles) mem.freePage(fullId.cacheId(), fullId.pageId());
for (int i = 0; i < pages; i++) assertFalse(handles.add(allocatePage(mem)));
} finally {
mem.stop();
}
}
use of org.apache.ignite.internal.pagemem.FullPageId in project ignite by apache.
the class PageMemoryNoLoadSelfTest method testPageTearingSequential.
/**
* @throws Exception If failed.
*/
public void testPageTearingSequential() throws Exception {
PageMemory mem = memory();
mem.start();
try {
int pagesCnt = 1024;
List<FullPageId> pages = new ArrayList<>(pagesCnt);
for (int i = 0; i < pagesCnt; i++) {
FullPageId fullId = allocatePage(mem);
pages.add(fullId);
long page = mem.acquirePage(fullId.cacheId(), fullId.pageId());
try {
if (i % 64 == 0)
info("Writing page [idx=" + i + ", pageId=" + fullId.pageId() + ", page=" + page + ']');
writePage(mem, fullId.pageId(), page, i + 1);
} finally {
mem.releasePage(fullId.cacheId(), fullId.pageId(), page);
}
}
for (int i = 0; i < pagesCnt; i++) {
FullPageId fullId = pages.get(i);
long page = mem.acquirePage(fullId.cacheId(), fullId.pageId());
try {
if (i % 64 == 0)
info("Reading page [idx=" + i + ", pageId=" + fullId.pageId() + ", page=" + page + ']');
readPage(mem, fullId.pageId(), page, i + 1);
} finally {
mem.releasePage(fullId.cacheId(), fullId.pageId(), page);
}
}
} finally {
mem.stop();
}
}
use of org.apache.ignite.internal.pagemem.FullPageId in project ignite by apache.
the class MetadataStorage method getOrAllocateForTree.
/** {@inheritDoc} */
@Override
public RootPage getOrAllocateForTree(final 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(cacheId, allocPartId, allocSpace) : pageId;
tree.put(new IndexItem(idxNameBytes, pageId));
return new RootPage(new FullPageId(pageId, cacheId), true);
} else {
final FullPageId pageId = new FullPageId(row.pageId, cacheId);
return new RootPage(pageId, false);
}
}
}
use of org.apache.ignite.internal.pagemem.FullPageId in project ignite by apache.
the class PageMemoryNoLoadSelfTest method testPageIdRotation.
/**
* @throws Exception If failed.
*/
public void testPageIdRotation() throws Exception {
PageMemory mem = memory();
mem.start();
try {
int pages = 5;
Collection<FullPageId> old = new ArrayList<>();
Collection<FullPageId> updated = new ArrayList<>();
for (int i = 0; i < pages; i++) old.add(allocatePage(mem));
// Check that initial pages are accessible.
for (FullPageId id : old) {
long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
assertNotNull(pageAddr);
try {
long updId = PageIdUtils.rotatePageId(id.pageId());
PageIO.setPageId(pageAddr, updId);
updated.add(new FullPageId(updId, id.cacheId()));
} finally {
mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, true);
}
} finally {
mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
}
}
// Check that updated pages are inaccessible using old IDs.
for (FullPageId id : old) {
long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
if (pageAddr != 0L) {
mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, false);
fail("Was able to acquire page write lock.");
}
mem.readLock(id.cacheId(), id.pageId(), pageApsPtr);
if (pageAddr != 0) {
mem.readUnlock(id.cacheId(), id.pageId(), pageApsPtr);
fail("Was able to acquire page read lock.");
}
} finally {
mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
}
}
// Check that updated pages are accessible using new IDs.
for (FullPageId id : updated) {
long pageApsPtr = mem.acquirePage(id.cacheId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.cacheId(), id.pageId(), pageApsPtr);
assertNotSame(0L, pageAddr);
try {
assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
} finally {
mem.writeUnlock(id.cacheId(), id.pageId(), pageApsPtr, null, false);
}
pageAddr = mem.readLock(id.cacheId(), id.pageId(), pageApsPtr);
assertNotSame(0L, pageAddr);
try {
assertEquals(id.pageId(), PageIO.getPageId(pageAddr));
} finally {
mem.readUnlock(id.cacheId(), id.pageId(), pageApsPtr);
}
} finally {
mem.releasePage(id.cacheId(), id.pageId(), pageApsPtr);
}
}
} finally {
mem.stop();
}
}
Aggregations