Search in sources :

Example 1 with GridCacheVersionManager

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager 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 2 with GridCacheVersionManager

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager in project ignite by apache.

the class GridCommandHandlerConsistencyTest method fillCache.

/**
 */
private void fillCache(String name, Ignite filtered, boolean incVal) throws Exception {
    for (Ignite node : G.allGrids()) {
        if (node.equals(filtered))
            continue;
        while (// Waiting for cache internals to init.
        ((IgniteEx) node).cachex(name) == null) U.sleep(1);
    }
    GridCacheVersionManager mgr = ((GridCacheAdapter) (grid(1)).cachex(name).cache()).context().shared().versions();
    for (int key = 0; key < PARTITIONS; key++) {
        List<Ignite> nodes = new ArrayList<>();
        nodes.add(primaryNode(key, name));
        nodes.addAll(backupNodes(key, name));
        Collections.shuffle(nodes);
        int val = key;
        Object obj;
        for (Ignite node : nodes) {
            IgniteInternalCache cache = ((IgniteEx) node).cachex(name);
            GridCacheAdapter adapter = ((GridCacheAdapter) cache.cache());
            GridCacheEntryEx entry = adapter.entryEx(key);
            val = incVal ? ++val : val;
            if (binaryCache()) {
                BinaryObjectBuilder builder = node.binary().builder("org.apache.ignite.TestValue");
                builder.setField("val", val);
                obj = builder.build();
            } else
                obj = val;
            boolean init = entry.initialValue(// Incremental or same value.
            new CacheObjectImpl(obj, null), // Incremental version.
            mgr.next(entry.context().kernalContext().discovery().topologyVersion()), 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
            assertTrue("iterableKey " + key + " already inited", init);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 3 with GridCacheVersionManager

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager in project ignite by apache.

the class AbstractReadRepairTest method setDifferentValuesForSameKey.

/**
 */
private InconsistentMapping setDifferentValuesForSameKey(int key, boolean misses, boolean nulls, ReadRepairStrategy strategy) throws Exception {
    List<Ignite> nodes = new ArrayList<>();
    Map<Ignite, T2<Integer, GridCacheVersion>> mapping = new HashMap<>();
    Ignite primary = primaryNode(key, DEFAULT_CACHE_NAME);
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    if (rnd.nextBoolean()) {
        // Reversed order.
        nodes.addAll(backupNodes(key, DEFAULT_CACHE_NAME));
        nodes.add(primary);
    } else {
        nodes.add(primary);
        nodes.addAll(backupNodes(key, DEFAULT_CACHE_NAME));
    }
    if (// Random order.
    rnd.nextBoolean())
        Collections.shuffle(nodes);
    IgniteInternalCache<Integer, Integer> internalCache = (grid(1)).cachex(DEFAULT_CACHE_NAME);
    GridCacheVersionManager mgr = ((GridCacheAdapter) internalCache.cache()).context().shared().versions();
    int incVal = 0;
    Integer primVal = null;
    Collection<T2<Integer, GridCacheVersion>> vals = new ArrayList<>();
    if (misses) {
        List<Ignite> keeped = nodes.subList(0, rnd.nextInt(1, nodes.size()));
        nodes.stream().filter(node -> !keeped.contains(node)).forEach(node -> {
            T2<Integer, GridCacheVersion> nullT2 = new T2<>(null, null);
            vals.add(nullT2);
            mapping.put(node, nullT2);
        });
        // Recording nulls (missed values).
        nodes = keeped;
    }
    boolean rmvd = false;
    boolean incVer = rnd.nextBoolean();
    GridCacheVersion ver = null;
    for (Ignite node : nodes) {
        IgniteInternalCache<Integer, Integer> cache = ((IgniteEx) node).cachex(DEFAULT_CACHE_NAME);
        GridCacheAdapter<Integer, Integer> adapter = (GridCacheAdapter) cache.cache();
        GridCacheEntryEx entry = adapter.entryEx(key);
        if (ver == null || incVer)
            // Incremental version.
            ver = mgr.next(entry.context().kernalContext().discovery().topologyVersion());
        boolean rmv = nulls && (!rmvd || rnd.nextBoolean());
        Integer val = rmv ? null : rnd.nextBoolean() ? /*increment or same as previously*/
        ++incVal : incVal;
        T2<Integer, GridCacheVersion> valVer = new T2<>(val, val != null ? ver : null);
        vals.add(valVer);
        mapping.put(node, valVer);
        GridKernalContext kctx = ((IgniteEx) node).context();
        // Incremental value.
        byte[] bytes = kctx.cacheObjects().marshal(entry.context().cacheObjectContext(), rmv ? -1 : val);
        try {
            kctx.cache().context().database().checkpointReadLock();
            boolean init = entry.initialValue(new CacheObjectImpl(null, bytes), ver, 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
            if (rmv) {
                if (cache.configuration().getAtomicityMode() == ATOMIC)
                    entry.innerUpdate(ver, ((IgniteEx) node).localNode().id(), ((IgniteEx) node).localNode().id(), GridCacheOperation.DELETE, null, null, false, false, false, false, null, false, false, false, false, AffinityTopologyVersion.NONE, null, GridDrType.DR_NONE, 0, 0, null, false, false, null, null, null, null, false);
                else
                    entry.innerRemove(null, ((IgniteEx) node).localNode().id(), ((IgniteEx) node).localNode().id(), false, false, false, false, false, null, AffinityTopologyVersion.NONE, CU.empty0(), GridDrType.DR_NONE, null, null, null, 1L);
                rmvd = true;
                assertFalse(entry.hasValue());
            } else
                assertTrue(entry.hasValue());
            assertTrue("iterableKey " + key + " already inited", init);
            if (node.equals(primary))
                primVal = val;
        } finally {
            ((IgniteEx) node).context().cache().context().database().checkpointReadUnlock();
        }
    }
    assertEquals(vals.size(), mapping.size());
    assertEquals(vals.size(), internalCache.configuration().getCacheMode() == REPLICATED ? serverNodesCount() : backupsCount() + 1);
    if (!misses && !nulls)
        // Primary value set.
        assertTrue(primVal != null);
    Integer fixed;
    boolean consistent;
    boolean repairable;
    if (vals.stream().distinct().count() == 1) {
        // Consistent value.
        consistent = true;
        repairable = true;
        fixed = vals.iterator().next().getKey();
    } else {
        consistent = false;
        // Currently, Atomic caches can not be repaired.
        repairable = atomicityMode() != ATOMIC;
        switch(strategy) {
            case LWW:
                if (misses || rmvd || !incVer) {
                    repairable = false;
                    // Should never be returned.
                    fixed = Integer.MIN_VALUE;
                } else
                    fixed = incVal;
                break;
            case PRIMARY:
                fixed = primVal;
                break;
            case RELATIVE_MAJORITY:
                // Should never be returned.
                fixed = Integer.MIN_VALUE;
                Map<T2<Integer, GridCacheVersion>, Integer> counts = new HashMap<>();
                for (T2<Integer, GridCacheVersion> val : vals) {
                    counts.putIfAbsent(val, 0);
                    counts.compute(val, (k, v) -> v + 1);
                }
                int[] sorted = counts.values().stream().sorted(Comparator.reverseOrder()).mapToInt(v -> v).toArray();
                int max = sorted[0];
                if (sorted.length > 1 && sorted[1] == max)
                    repairable = false;
                if (repairable)
                    for (Map.Entry<T2<Integer, GridCacheVersion>, Integer> count : counts.entrySet()) if (count.getValue().equals(max)) {
                        fixed = count.getKey().getKey();
                        break;
                    }
                break;
            case REMOVE:
                fixed = null;
                break;
            case CHECK_ONLY:
                repairable = false;
                // Should never be returned.
                fixed = Integer.MIN_VALUE;
                break;
            default:
                throw new UnsupportedOperationException(strategy.toString());
        }
    }
    return new InconsistentMapping(mapping, primVal, fixed, repairable, consistent);
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Map(java.util.Map) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) ClusterState(org.apache.ignite.cluster.ClusterState) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteIrreparableConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteIrreparableConsistencyViolationException) GridDrType(org.apache.ignite.internal.processors.dr.GridDrType) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteEvents(org.apache.ignite.IgniteEvents) G(org.apache.ignite.internal.util.typedef.G) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) CacheConsistencyViolationEvent(org.apache.ignite.events.CacheConsistencyViolationEvent) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) T2(org.apache.ignite.internal.util.typedef.T2) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) Consumer(java.util.function.Consumer) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) TreeMap(java.util.TreeMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) EVT_CONSISTENCY_VIOLATION(org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION) Comparator(java.util.Comparator) Collections(java.util.Collections) CacheMode(org.apache.ignite.cache.CacheMode) HashMap(java.util.HashMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ArrayList(java.util.ArrayList) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2) CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 4 with GridCacheVersionManager

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager in project ignite by apache.

the class InconsistentNodeApplication method run.

/**
 * {@inheritDoc}
 */
@Override
protected void run(JsonNode jsonNode) throws Exception {
    String cacheName = jsonNode.get("cacheName").asText();
    int amount = jsonNode.get("amount").asInt();
    int parts = jsonNode.get("parts").asInt();
    boolean tx = jsonNode.get("tx").asBoolean();
    markInitialized();
    waitForActivation();
    CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(cacheName);
    cfg.setAtomicityMode(tx ? TRANSACTIONAL : ATOMIC);
    cfg.setCacheMode(CacheMode.REPLICATED);
    cfg.setAffinity(new RendezvousAffinityFunction().setPartitions(parts));
    ignite.getOrCreateCache(cfg);
    GridCacheVersionManager mgr = ((GridCacheAdapter) ((IgniteEx) ignite).cachex(cacheName).cache()).context().shared().versions();
    int cnt = 0;
    for (int key = 0; key < amount; key += ThreadLocalRandom.current().nextInt(1, 3)) {
        // Random shift.
        IgniteInternalCache<?, ?> cache = ((IgniteEx) ignite).cachex(cacheName);
        GridCacheAdapter<?, ?> adapter = (GridCacheAdapter) cache.cache();
        GridCacheEntryEx entry = adapter.entryEx(key);
        boolean init = entry.initialValue(// Incremental value.
        new CacheObjectImpl(cnt, null), // Incremental version.
        mgr.next(entry.context().kernalContext().discovery().topologyVersion()), 0, 0, false, AffinityTopologyVersion.NONE, GridDrType.DR_NONE, false, false);
        assert init : "iterableKey " + key + " already inited";
        if (cnt % 1_000 == 0)
            log.info("APPLICATION_STREAMED [entries=" + cnt + "]");
        cnt++;
    }
    log.info("APPLICATION_STREAMING_FINISHED [entries=" + cnt + "]");
    while (!terminated()) // Keeping node alive.
    U.sleep(100);
    markFinished();
}
Also used : CacheObjectImpl(org.apache.ignite.internal.processors.cache.CacheObjectImpl) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

GridCacheVersionManager (org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager)4 IgniteEx (org.apache.ignite.internal.IgniteEx)3 CacheObjectImpl (org.apache.ignite.internal.processors.cache.CacheObjectImpl)3 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)3 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)3 ArrayList (java.util.ArrayList)2 Ignite (org.apache.ignite.Ignite)2 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Consumer (java.util.function.Consumer)1