use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.
the class PageMemoryNoLoadSelfTest method testPageHandleDeallocation.
@Test
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.groupId(), fullId.pageId());
}
for (int i = 0; i < pages; i++) {
assertFalse(handles.add(allocatePage(mem)));
}
} finally {
mem.stop(true);
}
}
use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.
the class PageMemoryNoLoadSelfTest method testPageIdRotation.
@Test
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.groupId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
assertNotNull(pageAddr);
try {
PAGE_IO.initNewPage(pageAddr, id.pageId(), mem.realPageSize(id.groupId()));
long updId = PageIdUtils.rotatePageId(id.pageId());
PageIo.setPageId(pageAddr, updId);
updated.add(new FullPageId(updId, id.groupId()));
} finally {
mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, true);
}
} finally {
mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
}
}
// Check that updated pages are inaccessible using old IDs.
for (FullPageId id : old) {
long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
if (pageAddr != 0L) {
mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, false);
fail("Was able to acquire page write lock.");
}
mem.readLock(id.groupId(), id.pageId(), pageApsPtr);
if (pageAddr != 0) {
mem.readUnlock(id.groupId(), id.pageId(), pageApsPtr);
fail("Was able to acquire page read lock.");
}
} finally {
mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
}
}
// Check that updated pages are accessible using new IDs.
for (FullPageId id : updated) {
long pageApsPtr = mem.acquirePage(id.groupId(), id.pageId());
try {
long pageAddr = mem.writeLock(id.groupId(), id.pageId(), pageApsPtr);
assertNotSame(0L, pageAddr);
try {
assertEquals(id.pageId(), PageIo.getPageId(pageAddr));
} finally {
mem.writeUnlock(id.groupId(), id.pageId(), pageApsPtr, false);
}
pageAddr = mem.readLock(id.groupId(), id.pageId(), pageApsPtr);
assertNotSame(0L, pageAddr);
try {
assertEquals(id.pageId(), PageIo.getPageId(pageAddr));
} finally {
mem.readUnlock(id.groupId(), id.pageId(), pageApsPtr);
}
} finally {
mem.releasePage(id.groupId(), id.pageId(), pageApsPtr);
}
}
} finally {
mem.stop(true);
}
}
use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.
the class PageMemoryImplNoLoadTest method memory.
/**
* {@inheritDoc}
*/
@Override
protected PageMemory memory() throws Exception {
dataRegionCfg.change(cfg -> cfg.convert(PageMemoryDataRegionChange.class).changePageSize(PAGE_SIZE).changeInitSize(MAX_MEMORY_SIZE).changeMaxSize(MAX_MEMORY_SIZE)).get(1, SECONDS);
PageIoRegistry ioRegistry = new PageIoRegistry();
ioRegistry.loadFromServiceLoader();
return new PageMemoryImpl(new UnsafeMemoryProvider(null), (PageMemoryDataRegionConfiguration) fixConfiguration(dataRegionCfg), ioRegistry, LongStream.range(0, 10).map(i -> 5 * MiB).toArray(), new TestPageReadWriteManager(), (page, fullPageId, pageMemoryEx) -> {
});
}
use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.
the class ItBplusTreeSelfTest method createPageMemory.
/**
* Returns page memory.
*
* @throws Exception If failed.
*/
protected PageMemory createPageMemory() throws Exception {
dataRegionCfg.change(c -> c.convert(PageMemoryDataRegionChange.class).changePageSize(PAGE_SIZE).changeInitSize(MAX_MEMORY_SIZE).changeMaxSize(MAX_MEMORY_SIZE)).get(1, TimeUnit.SECONDS);
TestPageIoRegistry ioRegistry = new TestPageIoRegistry();
ioRegistry.loadFromServiceLoader();
return new PageMemoryNoStoreImpl(new UnsafeMemoryProvider(null), (PageMemoryDataRegionConfiguration) fixConfiguration(dataRegionCfg), ioRegistry);
}
use of org.apache.ignite.internal.pagememory.PageMemory in project ignite-3 by apache.
the class ItBplusTreePageMemoryImplTest method createPageMemory.
/**
* {@inheritDoc}
*/
@Override
protected PageMemory createPageMemory() throws Exception {
dataRegionCfg.change(c -> c.convert(PageMemoryDataRegionChange.class).changePageSize(PAGE_SIZE).changeInitSize(MAX_MEMORY_SIZE).changeMaxSize(MAX_MEMORY_SIZE)).get(1, TimeUnit.SECONDS);
long[] sizes = LongStream.range(0, CPUS + 1).map(i -> MAX_MEMORY_SIZE / CPUS).toArray();
sizes[CPUS] = 10 * MiB;
TestPageIoRegistry ioRegistry = new TestPageIoRegistry();
ioRegistry.loadFromServiceLoader();
return new PageMemoryImpl(new UnsafeMemoryProvider(null), (PageMemoryDataRegionConfiguration) fixConfiguration(dataRegionCfg), ioRegistry, sizes, new TestPageReadWriteManager(), (page, fullPageId, pageMemoryEx) -> {
});
}
Aggregations