Search in sources :

Example 16 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class CachePageWriteLockUnlockTest method preloadPartition.

/**
 * Preload partition fast by iterating on all pages in disk order.
 *
 * @param grid Grid.
 * @param cacheName Cache name.
 * @param p P.
 */
private void preloadPartition(Ignite grid, String cacheName, int p) throws IgniteCheckedException {
    GridDhtCacheAdapter<Object, Object> dht = ((IgniteKernal) grid).internalCache(cacheName).context().dht();
    GridDhtLocalPartition part = dht.topology().localPartition(p);
    assertNotNull(part);
    assertTrue(part.state() == OWNING);
    CacheGroupContext grpCtx = dht.context().group();
    if (part.state() != OWNING)
        return;
    IgnitePageStoreManager pageStoreMgr = grpCtx.shared().pageStore();
    if (pageStoreMgr instanceof FilePageStoreManager) {
        FilePageStoreManager filePageStoreMgr = (FilePageStoreManager) pageStoreMgr;
        PageStore pageStore = filePageStoreMgr.getStore(grpCtx.groupId(), part.id());
        PageMemoryEx pageMemory = (PageMemoryEx) grpCtx.dataRegion().pageMemory();
        long pageId = pageMemory.partitionMetaPageId(grpCtx.groupId(), part.id());
        for (int pageNo = 0; pageNo < pageStore.pages(); pageId++, pageNo++) {
            long pagePointer = -1;
            try {
                pagePointer = pageMemory.acquirePage(grpCtx.groupId(), pageId);
            } finally {
                if (pagePointer != -1)
                    pageMemory.releasePage(grpCtx.groupId(), pageId, pagePointer);
            }
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 17 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class WalRecoveryTxLogicalRecordsTest method allocatedPages.

/**
 * @param ignite Node.
 * @param cacheName Cache name.
 * @return Allocated pages per-store.
 * @throws Exception If failed.
 */
private List<Integer> allocatedPages(Ignite ignite, String cacheName) throws Exception {
    GridCacheProcessor cacheProc = ((IgniteEx) ignite).context().cache();
    FilePageStoreManager storeMgr = (FilePageStoreManager) cacheProc.context().pageStore();
    int parts = ignite.affinity(cacheName).partitions();
    List<Integer> res = new ArrayList<>(parts);
    for (int p = 0; p < parts; p++) {
        PageStore store = storeMgr.getStore(CU.cacheId(cacheName), p);
        cacheProc.context().database().checkpointReadLock();
        try {
            GridDhtLocalPartition part = cacheProc.cache(cacheName).context().topology().localPartition(p);
            if (part.dataStore().rowStore() != null) {
                AbstractFreeList freeList = (AbstractFreeList) part.dataStore().rowStore().freeList();
                // Flush free-list onheap cache to page memory.
                freeList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE);
            }
        } finally {
            cacheProc.context().database().checkpointReadUnlock();
        }
        store.sync();
        res.add(store.pages());
    }
    PageStore store = storeMgr.getStore(CU.cacheId(cacheName), PageIdAllocator.INDEX_PARTITION);
    store.sync();
    res.add(store.pages());
    return res;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList) ArrayList(java.util.ArrayList) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheProcessor(org.apache.ignite.internal.processors.cache.GridCacheProcessor)

Example 18 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class FilePageStoreManager method writeInternal.

/**
 * @param cacheId Cache ID to write.
 * @param pageId Page ID.
 * @param pageBuf Page buffer.
 * @param tag Partition tag (growing 1-based partition file version). Used to validate page is not outdated
 * @param calculateCrc if {@code False} crc calculation will be forcibly skipped.
 * @return PageStore to which the page has been written.
 * @throws IgniteCheckedException If IO error occurred.
 */
public PageStore writeInternal(int cacheId, long pageId, ByteBuffer pageBuf, int tag, boolean calculateCrc) throws IgniteCheckedException {
    int partId = PageIdUtils.partId(pageId);
    PageStore store = getStore(cacheId, partId);
    try {
        store.write(pageId, pageBuf, tag, calculateCrc);
    } catch (PersistentStorageIOException e) {
        NodeInvalidator.INSTANCE.invalidate(cctx.kernalContext(), e);
        throw e;
    }
    return store;
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore)

Example 19 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class DiskPageCompressionIntegrationTest method doTestPageCompression.

/**
 * @throws Exception If failed.
 */
@Override
protected void doTestPageCompression() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    String cacheName = "test";
    CacheConfiguration<Integer, TestVal> ccfg = new CacheConfiguration<Integer, TestVal>().setName(cacheName).setBackups(0).setAtomicityMode(ATOMIC).setIndexedTypes(Integer.class, TestVal.class).setDiskPageCompression(compression).setDiskPageCompressionLevel(compressionLevel);
    IgniteCache<Integer, TestVal> cache = ignite.getOrCreateCache(ccfg);
    int cnt = 2_000;
    for (int i = 0; i < cnt; i++) assertTrue(cache.putIfAbsent(i, new TestVal(i)));
    for (int i = 0; i < cnt; i += 2) assertEquals(new TestVal(i), cache.getAndRemove(i));
    GridCacheDatabaseSharedManager dbMgr = ((GridCacheDatabaseSharedManager) ignite.context().cache().context().database());
    dbMgr.forceCheckpoint("test compression").futureFor(FINISHED).get();
    FilePageStoreManager storeMgr = dbMgr.getFileStoreManager();
    checkFileIOFactory(storeMgr.getPageStoreFileIoFactory());
    // Wait for metrics update.
    Thread.sleep(100);
    long storeSize = ignite.dataStorageMetrics().getStorageSize();
    long sparseStoreSize = ignite.dataStorageMetrics().getSparseStorageSize();
    assertTrue("storeSize: " + storeSize, storeSize > 0);
    if (U.isLinux()) {
        assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
        assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
    } else
        assertTrue(sparseStoreSize < 0);
    GridCacheContext<?, ?> cctx = ignite.cachex(cacheName).context();
    int cacheId = cctx.cacheId();
    int groupId = cctx.groupId();
    assertEquals(cacheId, groupId);
    MetricRegistry mreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, cctx.group().cacheOrGroupName()));
    storeSize = mreg.<LongMetric>findMetric("StorageSize").value();
    sparseStoreSize = mreg.<LongMetric>findMetric("SparseStorageSize").value();
    assertTrue("storeSize: " + storeSize, storeSize > 0);
    if (U.isLinux()) {
        assertTrue("sparseSize: " + sparseStoreSize, sparseStoreSize > 0);
        assertTrue(storeSize + " > " + sparseStoreSize, storeSize > sparseStoreSize);
    } else
        assertTrue(sparseStoreSize < 0);
    int parts = cctx.affinity().partitions();
    for (int i = 0; i < parts; i++) {
        PageStore store = storeMgr.getStore(cacheId, i);
        long realSize = store.size();
        long virtualSize = store.getPageSize() * store.pages();
        long sparseSize = store.getSparseSize();
        assertTrue(virtualSize > 0);
        error("virt: " + virtualSize + ",  real: " + realSize + ",  sparse: " + sparseSize);
        if (!store.exists())
            continue;
        if (virtualSize > sparseSize)
            return;
    }
    fail("No files were compacted.");
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) LongMetric(org.apache.ignite.spi.metric.LongMetric) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 20 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class FilePageStoreManager method getStore.

/**
 * @param grpId Cache group ID.
 * @param partId Partition ID.
 * @return Page store for the corresponding parameters.
 * @throws IgniteCheckedException If cache or partition with the given ID was not created.
 *
 * Note: visible for testing.
 */
@Override
public PageStore getStore(int grpId, int partId) throws IgniteCheckedException {
    CacheStoreHolder holder = getHolder(grpId);
    if (holder == null)
        throw new IgniteCheckedException("Failed to get page store for the given cache ID " + "(cache has not been started): " + grpId);
    if (partId == INDEX_PARTITION)
        return holder.idxStore;
    if (partId > MAX_PARTITION_ID)
        throw new IgniteCheckedException("Partition ID is reserved: " + partId);
    PageStore store = holder.partStores[partId];
    if (store == null)
        throw new IgniteCheckedException("Failed to get page store for the given partition ID " + "(partition has not been created) [grpId=" + grpId + ", partId=" + partId + ']');
    return store;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PageStore(org.apache.ignite.internal.pagemem.store.PageStore)

Aggregations

PageStore (org.apache.ignite.internal.pagemem.store.PageStore)27 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)9 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 IgniteException (org.apache.ignite.IgniteException)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)5 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)5 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)5 File (java.io.File)4 ByteBuffer (java.nio.ByteBuffer)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 FailureContext (org.apache.ignite.failure.FailureContext)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)4