Search in sources :

Example 16 with GridCloseableIterator

use of org.apache.ignite.internal.util.lang.GridCloseableIterator in project ignite by apache.

the class CacheMvccAbstractTest method checkOldVersions.

/**
 * Checks if outdated versions were cleaned after the vacuum process.
 *
 * @param failIfNotCleaned Fail test if not cleaned.
 * @return {@code False} if not cleaned.
 * @throws IgniteCheckedException If failed.
 */
private boolean checkOldVersions(boolean failIfNotCleaned) throws IgniteCheckedException {
    for (Ignite node : G.allGrids()) {
        for (IgniteCacheProxy cache : ((IgniteKernal) node).caches()) {
            GridCacheContext cctx = cache.context();
            if (!cctx.userCache() || !cctx.group().mvccEnabled() || F.isEmpty(cctx.group().caches()) || cctx.shared().closed(cctx))
                continue;
            try (GridCloseableIterator it = (GridCloseableIterator) cache.withKeepBinary().iterator()) {
                while (it.hasNext()) {
                    IgniteBiTuple entry = (IgniteBiTuple) it.next();
                    KeyCacheObject key = cctx.toCacheKeyObject(entry.getKey());
                    List<IgniteBiTuple<Object, MvccVersion>> vers = cctx.offheap().mvccAllVersions(cctx, key).stream().filter(t -> t.get1() != null).collect(Collectors.toList());
                    if (vers.size() > 1) {
                        if (failIfNotCleaned)
                            fail("[key=" + key.value(null, false) + "; vers=" + vers + ']');
                        else
                            return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCompoundIdentityFuture(org.apache.ignite.internal.util.future.GridCompoundIdentityFuture) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Transaction(org.apache.ignite.transactions.Transaction) TRANSACTIONAL_SNAPSHOT(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) SqlQuery(org.apache.ignite.cache.query.SqlQuery) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) X(org.apache.ignite.internal.util.typedef.X) Cache(javax.cache.Cache) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridInClosure3(org.apache.ignite.internal.util.lang.GridInClosure3) WALMode(org.apache.ignite.configuration.WALMode) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) QuerySqlField(org.apache.ignite.cache.query.annotations.QuerySqlField) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) SQL_SUM(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.SQL_SUM) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) ScanQuery(org.apache.ignite.cache.query.ScanQuery) DML(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.WriteMode.DML) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) SQL(org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.SQL) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CacheException(javax.cache.CacheException) TransactionException(org.apache.ignite.transactions.TransactionException) TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) LinkedHashSet(java.util.LinkedHashSet) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) Iterator(java.util.Iterator) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Ignite(org.apache.ignite.Ignite) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) SF(org.apache.ignite.testframework.GridTestUtils.SF) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) IgniteTransactions(org.apache.ignite.IgniteTransactions) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Ignite(org.apache.ignite.Ignite) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridCloseableIterator (org.apache.ignite.internal.util.lang.GridCloseableIterator)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)6 Test (org.junit.Test)6 NoSuchElementException (java.util.NoSuchElementException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 ArrayList (java.util.ArrayList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 Callable (java.util.concurrent.Callable)3 CacheException (javax.cache.CacheException)3 IgniteException (org.apache.ignite.IgniteException)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Collection (java.util.Collection)2