Search in sources :

Example 31 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class UpgradePendingTreeToPerPartitionTask method processPendingTree.

/**
 * Move pending rows for CacheGroup entries to per-partition PendingTree.
 * Invalid pending rows will be ignored.
 *
 * @param grp Cache group.
 * @param oldPendingEntries Old-style PendingTree.
 * @throws IgniteCheckedException If error occurs.
 */
private void processPendingTree(CacheGroupContext grp, PendingEntriesTree oldPendingEntries) throws IgniteCheckedException {
    final PageMemory pageMemory = grp.dataRegion().pageMemory();
    final IgniteCacheDatabaseSharedManager db = grp.shared().database();
    final Set<Integer> cacheIds = grp.cacheIds();
    PendingRow row = null;
    int processedEntriesCnt = 0;
    int skippedEntries = 0;
    // Re-acquire checkpoint lock for every next batch.
    while (!Thread.currentThread().isInterrupted()) {
        int cnt = 0;
        db.checkpointReadLock();
        try {
            GridCursor<PendingRow> cursor = oldPendingEntries.find(row, null, WITHOUT_KEY);
            while (cnt++ < BATCH_SIZE && cursor.next()) {
                row = cursor.get();
                assert row.link != 0 && row.expireTime != 0 : row;
                GridCacheEntryEx entry;
                // Lost cache or lost entry.
                if (!cacheIds.contains(row.cacheId) || (entry = getEntry(grp, row)) == null) {
                    skippedEntries++;
                    oldPendingEntries.removex(row);
                    continue;
                }
                entry.lockEntry();
                try {
                    if (processRow(pageMemory, grp, row))
                        processedEntriesCnt++;
                    else
                        skippedEntries++;
                } finally {
                    entry.unlockEntry();
                }
                oldPendingEntries.removex(row);
            }
            if (cnt < BATCH_SIZE)
                break;
        } finally {
            db.checkpointReadUnlock();
        }
    }
    log.info("PendingTree upgraded: " + "[grpId=" + grp.groupId() + ", grpName=" + grp.name() + ", processedEntries=" + processedEntriesCnt + ", failedEntries=" + skippedEntries + ']');
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PendingRow(org.apache.ignite.internal.processors.cache.tree.PendingRow) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 32 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class UpgradePendingTreeToPerPartitionTask method processCacheGroup.

/**
 * Converts CacheGroup pending tree to per-partition basis.
 *
 * @param grp Cache group.
 * @throws IgniteCheckedException If error occurs.
 */
private void processCacheGroup(CacheGroupContext grp) throws IgniteCheckedException {
    assert grp.offheap() instanceof GridCacheOffheapManager;
    PendingEntriesTree oldPendingTree;
    final IgniteCacheDatabaseSharedManager db = grp.shared().database();
    db.checkpointReadLock();
    try {
        IndexStorage indexStorage = ((GridCacheOffheapManager) grp.offheap()).getIndexStorage();
        // TODO: IGNITE-5874: replace with some check-method to avoid unnecessary page allocation.
        RootPage pendingRootPage = indexStorage.allocateIndex(PENDING_ENTRIES_TREE_NAME);
        if (pendingRootPage.isAllocated()) {
            log.info("No pending tree found for cache group: [grpId=" + grp.groupId() + ", grpName=" + grp.name() + ']');
            // Nothing to do here as just allocated tree is obviously empty.
            indexStorage.dropIndex(PENDING_ENTRIES_TREE_NAME);
            return;
        }
        oldPendingTree = new PendingEntriesTree(grp, PENDING_ENTRIES_TREE_NAME, grp.dataRegion().pageMemory(), pendingRootPage.pageId().pageId(), ((GridCacheOffheapManager) grp.offheap()).reuseListForIndex(null), false, grp.shared().diagnostic().pageLockTracker(), PageIdAllocator.FLAG_IDX);
    } finally {
        db.checkpointReadUnlock();
    }
    processPendingTree(grp, oldPendingTree);
    if (Thread.currentThread().isInterrupted())
        return;
    db.checkpointReadLock();
    try {
        oldPendingTree.destroy();
    } finally {
        db.checkpointReadUnlock();
    }
}
Also used : GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) IndexStorage(org.apache.ignite.internal.processors.cache.persistence.IndexStorage) PendingEntriesTree(org.apache.ignite.internal.processors.cache.tree.PendingEntriesTree) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 33 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class GridCommandHandlerIndexingUtils method breakCacheDataTree.

/**
 * Deleting a rows from the cache without updating indexes.
 *
 * @param log Logger.
 * @param internalCache Cache.
 * @param partId Partition number.
 * @param filter Entry filter.
 */
static <K, V> void breakCacheDataTree(IgniteLogger log, IgniteInternalCache<K, V> internalCache, int partId, @Nullable BiPredicate<Integer, Entry<K, V>> filter) {
    requireNonNull(log);
    requireNonNull(internalCache);
    GridCacheContext<K, V> cacheCtx = internalCache.context();
    CacheDataStore cacheDataStore = cacheCtx.dht().topology().localPartition(partId).dataStore();
    String delegate = "delegate";
    if (hasField(cacheDataStore, delegate))
        cacheDataStore = field(cacheDataStore, delegate);
    CacheDataRowStore cacheDataRowStore = field(cacheDataStore, "rowStore");
    CacheDataTree cacheDataTree = field(cacheDataStore, "dataTree");
    String cacheName = internalCache.name();
    QueryCursor<Entry<K, V>> qryCursor = cacheCtx.kernalContext().grid().cache(cacheName).withKeepBinary().query(new ScanQuery<>(partId));
    Iterator<Entry<K, V>> cacheEntryIter = qryCursor.iterator();
    IgniteCacheDatabaseSharedManager db = cacheCtx.shared().database();
    int cacheId = CU.cacheId(cacheName);
    int i = 0;
    while (cacheEntryIter.hasNext()) {
        Entry<K, V> entry = cacheEntryIter.next();
        if (nonNull(filter) && !filter.test(i++, entry))
            continue;
        db.checkpointReadLock();
        try {
            CacheDataRow oldRow = cacheDataTree.remove(new SearchRow(cacheId, cacheCtx.toCacheKeyObject(entry.getKey())));
            if (nonNull(oldRow))
                cacheDataRowStore.removeRow(oldRow.link(), INSTANCE);
        } catch (IgniteCheckedException e) {
            throw new IgniteException("Failed to remove key skipping indexes: " + entry, e);
        } finally {
            db.checkpointReadUnlock();
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) CacheDataRowStore(org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore) Entry(javax.cache.Cache.Entry) CacheDataStore(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager.CacheDataStore) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheDataTree(org.apache.ignite.internal.processors.cache.tree.CacheDataTree) IgniteException(org.apache.ignite.IgniteException) SearchRow(org.apache.ignite.internal.processors.cache.tree.SearchRow) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 34 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class GridCacheProcessor method createSharedContext.

/**
 * Creates shared context.
 *
 * @param kernalCtx Kernal context.
 * @param storeSesLsnrs Store session listeners.
 * @return Shared context.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("unchecked")
private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, Collection<CacheStoreSessionListener> storeSesLsnrs) throws IgniteCheckedException {
    IgniteTxManager tm = new IgniteTxManager();
    GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
    GridCacheVersionManager verMgr = new GridCacheVersionManager();
    GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
    GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();
    IgniteCacheDatabaseSharedManager dbMgr;
    IgnitePageStoreManager pageStoreMgr = null;
    IgniteWriteAheadLogManager walMgr = null;
    if (CU.isPersistenceEnabled(ctx.config()) && !ctx.clientNode()) {
        dbMgr = new GridCacheDatabaseSharedManager(ctx);
        pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class);
        if (pageStoreMgr == null)
            pageStoreMgr = new FilePageStoreManager(ctx);
        walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class);
        if (walMgr == null)
            walMgr = new FileWriteAheadLogManager(ctx);
    } else {
        if (CU.isPersistenceEnabled(ctx.config()) && ctx.clientNode()) {
            U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + " configuration will be ignored).");
        }
        dbMgr = new IgniteCacheDatabaseSharedManager();
    }
    WalStateManager walStateMgr = new WalStateManager(ctx);
    IgniteSnapshotManager snapshotMgr = new IgniteSnapshotManager(ctx);
    IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class);
    if (snpMgr == null)
        snpMgr = new IgniteCacheSnapshotManager();
    GridCacheIoManager ioMgr = new GridCacheIoManager();
    CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager();
    GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager();
    PartitionsEvictManager evict = new PartitionsEvictManager();
    CacheJtaManagerAdapter jta = JTA.createOptional();
    MvccCachingManager mvccCachingMgr = new MvccCachingManager();
    DeadlockDetectionManager deadlockDetectionMgr = new DeadlockDetectionManager();
    CacheDiagnosticManager diagnosticMgr = new CacheDiagnosticManager();
    return new GridCacheSharedContext(kernalCtx, tm, verMgr, mvccMgr, pageStoreMgr, walMgr, walStateMgr, dbMgr, snapshotMgr, snpMgr, depMgr, exchMgr, topMgr, ioMgr, ttl, evict, jta, storeSesLsnrs, mvccCachingMgr, deadlockDetectionMgr, diagnosticMgr);
}
Also used : CacheJtaManagerAdapter(org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MvccCachingManager(org.apache.ignite.internal.processors.cache.mvcc.MvccCachingManager) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) DeadlockDetectionManager(org.apache.ignite.internal.processors.cache.mvcc.DeadlockDetectionManager) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) PartitionsEvictManager(org.apache.ignite.internal.processors.cache.distributed.dht.topology.PartitionsEvictManager) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 35 with IgniteCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager in project ignite by apache.

the class SystemViewCommandTest method testMetastorage.

/**
 */
@Test
public void testMetastorage() throws Exception {
    IgniteCacheDatabaseSharedManager db = ignite0.context().cache().context().database();
    String name = "test-key";
    String val = "test-value";
    db.checkpointReadLock();
    try {
        db.metaStorage().write(name, val);
    } finally {
        db.checkpointReadUnlock();
    }
    assertEquals(1, systemView(ignite0, METASTORE_VIEW).stream().filter(row -> name.equals(row.get(0)) && val.equals(row.get(1))).count());
}
Also used : IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Test(org.junit.Test)

Aggregations

IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)58 Test (org.junit.Test)27 IgniteEx (org.apache.ignite.internal.IgniteEx)24 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)10 GridInternalSubscriptionProcessor (org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor)9 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)8 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)7 GridSystemViewManager (org.apache.ignite.internal.managers.systemview.GridSystemViewManager)7 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)7 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)7 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)7 IgnitePluginProcessor (org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor)6 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)6 HashMap (java.util.HashMap)5 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)5 JmxSystemViewExporterSpi (org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi)5