Search in sources :

Example 16 with PageMemoryEx

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();
    }
}
Also used : PartitionDestroyRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PartitionDestroyRecord) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)

Example 17 with PageMemoryEx

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;
}
Also used : PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)

Example 18 with PageMemoryEx

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();
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) HashMap(java.util.HashMap) PageDeltaRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) ByteBuffer(java.nio.ByteBuffer) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteEx(org.apache.ignite.internal.IgniteEx) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) Map(java.util.Map) HashMap(java.util.HashMap) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)

Aggregations

PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)18 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)8 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ByteBuffer (java.nio.ByteBuffer)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 HashMap (java.util.HashMap)4 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)4 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)4 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)4 PageDeltaRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord)4 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)4 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)4 File (java.io.File)3 RandomAccessFile (java.io.RandomAccessFile)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)3