Search in sources :

Example 1 with SearchRow

use of org.apache.ignite.internal.processors.cache.tree.SearchRow 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)

Aggregations

Entry (javax.cache.Cache.Entry)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheDataStore (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager.CacheDataStore)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 CacheDataRowStore (org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore)1 CacheDataTree (org.apache.ignite.internal.processors.cache.tree.CacheDataTree)1 SearchRow (org.apache.ignite.internal.processors.cache.tree.SearchRow)1