use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx in project ignite by apache.
the class GridCacheOffheapManager method destroyCacheDataStore0.
/**
* {@inheritDoc}
*/
@Override
protected void destroyCacheDataStore0(CacheDataStore store) throws IgniteCheckedException {
ctx.database().checkpointReadLock();
try {
int p = store.partId();
saveStoreMetadata(store, null, false, true);
PageMemoryEx pageMemory = (PageMemoryEx) grp.dataRegion().pageMemory();
int tag = pageMemory.invalidate(grp.groupId(), p);
if (grp.walEnabled())
ctx.wal().log(new PartitionDestroyRecord(grp.groupId(), p));
ctx.pageStore().onPartitionDestroyed(grp.groupId(), p, tag);
} finally {
ctx.database().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx in project ignite by apache.
the class GridCacheOffheapManager method recreateCacheDataStore.
/**
* Destroys given {@code store} and creates new with the same update counters as in given.
*
* @param store Store to destroy.
* @return New cache data store.
* @throws IgniteCheckedException If failed.
*/
public CacheDataStore recreateCacheDataStore(CacheDataStore store) throws IgniteCheckedException {
long updCounter = store.updateCounter();
long initUpdCounter = store.initialUpdateCounter();
int p = store.partId();
PageMemoryEx pageMemory = (PageMemoryEx) grp.dataRegion().pageMemory();
int tag = pageMemory.invalidate(grp.groupId(), p);
ctx.pageStore().onPartitionDestroyed(grp.groupId(), p, tag);
CacheDataStore store0;
partStoreLock.lock(p);
try {
store0 = createCacheDataStore0(p);
store0.updateCounter(updCounter);
store0.updateInitialCounter(initUpdCounter);
partDataStores.put(p, store0);
} finally {
partStoreLock.unlock(p);
}
return store0;
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx in project ignite by apache.
the class IgniteWalRecoveryTest method testApplyDeltaRecords.
/**
* @throws Exception if failed.
*/
public void testApplyDeltaRecords() throws Exception {
try {
IgniteEx ignite0 = (IgniteEx) startGrid("node0");
ignite0.active(true);
IgniteCache<Object, Object> cache0 = ignite0.cache(cacheName);
for (int i = 0; i < 1000; i++) cache0.put(i, new IndexedObject(i));
GridCacheSharedContext<Object, Object> sharedCtx = ignite0.context().cache().context();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
db.waitForCheckpoint("test");
db.enableCheckpoints(false).get();
// Log something to know where to start.
WALPointer ptr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));
info("Replay marker: " + ptr);
for (int i = 1000; i < 5000; i++) cache0.put(i, new IndexedObject(i));
info("Done puts...");
for (int i = 2_000; i < 3_000; i++) cache0.remove(i);
info("Done removes...");
for (int i = 5000; i < 6000; i++) cache0.put(i, new IndexedObject(i));
info("Done puts...");
Map<FullPageId, byte[]> rolledPages = new HashMap<>();
int pageSize = sharedCtx.database().pageSize();
ByteBuffer buf = ByteBuffer.allocateDirect(pageSize);
// Now check that deltas can be correctly applied.
try (WALIterator it = sharedCtx.wal().replay(ptr)) {
while (it.hasNext()) {
IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
WALRecord rec = tup.get2();
if (rec instanceof PageSnapshot) {
PageSnapshot page = (PageSnapshot) rec;
rolledPages.put(page.fullPageId(), page.pageData());
} else if (rec instanceof PageDeltaRecord) {
PageDeltaRecord delta = (PageDeltaRecord) rec;
FullPageId fullId = new FullPageId(delta.pageId(), delta.groupId());
byte[] pageData = rolledPages.get(fullId);
if (pageData == null) {
pageData = new byte[pageSize];
rolledPages.put(fullId, pageData);
}
assertNotNull("Missing page snapshot [page=" + fullId + ", delta=" + delta + ']', pageData);
buf.order(ByteOrder.nativeOrder());
buf.position(0);
buf.put(pageData);
buf.position(0);
delta.applyDelta(sharedCtx.database().dataRegion(null).pageMemory(), GridUnsafe.bufferAddress(buf));
buf.position(0);
buf.get(pageData);
}
}
}
info("Done apply...");
PageMemoryEx pageMem = (PageMemoryEx) db.dataRegion(null).pageMemory();
for (Map.Entry<FullPageId, byte[]> entry : rolledPages.entrySet()) {
FullPageId fullId = entry.getKey();
ignite0.context().cache().context().database().checkpointReadLock();
try {
long page = pageMem.acquirePage(fullId.groupId(), fullId.pageId(), true);
try {
long bufPtr = pageMem.writeLock(fullId.groupId(), fullId.pageId(), page, true);
try {
byte[] data = entry.getValue();
for (int i = 0; i < data.length; i++) {
if (fullId.pageId() == TrackingPageIO.VERSIONS.latest().trackingPageFor(fullId.pageId(), db.pageSize()))
// Skip tracking pages.
continue;
assertEquals("page=" + fullId + ", pos=" + i, PageUtils.getByte(bufPtr, i), data[i]);
}
} finally {
pageMem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, false, true);
}
} finally {
pageMem.releasePage(fullId.groupId(), fullId.pageId(), page);
}
} finally {
ignite0.context().cache().context().database().checkpointReadUnlock();
}
}
ignite0.close();
} finally {
stopAllGrids();
}
}
Aggregations