Search in sources :

Example 11 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class IgniteTxStateImpl method syncMode.

/**
 * {@inheritDoc}
 */
@Override
public CacheWriteSynchronizationMode syncMode(GridCacheSharedContext cctx) {
    CacheWriteSynchronizationMode syncMode = CacheWriteSynchronizationMode.FULL_ASYNC;
    for (int i = 0; i < activeCacheIds.size(); i++) {
        int cacheId = activeCacheIds.get(i);
        CacheWriteSynchronizationMode cacheSyncMode = cctx.cacheContext(cacheId).config().getWriteSynchronizationMode();
        switch(cacheSyncMode) {
            case FULL_SYNC:
                return FULL_SYNC;
            case PRIMARY_SYNC:
                {
                    if (syncMode == FULL_ASYNC)
                        syncMode = PRIMARY_SYNC;
                    break;
                }
            case FULL_ASYNC:
                break;
        }
    }
    return syncMode;
}
Also used : CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode)

Example 12 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class GridNearTxFinishFuture method finish.

/**
 * @param miniId Mini future ID.
 * @param m Mapping.
 * @param commit Commit flag.
 * @param useCompletedVer {@code True} if need to add completed version on finish.
 */
private void finish(int miniId, GridDistributedTxMapping m, boolean commit, boolean useCompletedVer) {
    ClusterNode n = m.primary();
    assert !m.empty() || m.queryUpdate() : m + " " + tx.state();
    CacheWriteSynchronizationMode syncMode = tx.syncMode();
    if (m.explicitLock() || m.queryUpdate())
        syncMode = FULL_SYNC;
    GridNearTxFinishRequest req = new GridNearTxFinishRequest(futId, tx.xidVersion(), tx.threadId(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), syncMode, m.explicitLock(), tx.storeEnabled(), tx.topologyVersion(), null, null, null, tx.size(), tx.taskNameHash(), tx.mvccSnapshot(), tx.activeCachesDeploymentEnabled());
    // If this is the primary node for the keys.
    if (n.isLocal()) {
        req.miniId(miniId);
        IgniteInternalFuture<IgniteInternalTx> fut = cctx.tm().txHandler().finish(n.id(), tx, req);
        // Add new future.
        if (fut != null && syncMode == FULL_SYNC)
            add(fut);
    } else {
        FinishMiniFuture fut = new FinishMiniFuture(miniId, m);
        req.miniId(fut.futureId());
        // Append new future.
        add(fut);
        try {
            cctx.io().send(n, req, tx.ioPolicy());
            if (msgLog.isDebugEnabled()) {
                msgLog.debug("Near finish fut, sent request [" + "txId=" + tx.nearXidVersion() + ", node=" + n.id() + ']');
            }
            boolean wait = syncMode != FULL_ASYNC;
            // If we don't wait for result, then mark future as done.
            if (!wait)
                fut.onDone();
        } catch (ClusterTopologyCheckedException ignored) {
            // Remove previous mapping.
            mappings.remove(m.primary().id());
            fut.onNodeLeft(n.id(), false);
        } catch (IgniteCheckedException e) {
            if (msgLog.isDebugEnabled()) {
                msgLog.debug("Near finish fut, failed to send request [" + "txId=" + tx.nearXidVersion() + ", node=" + n.id() + ", err=" + e + ']');
            }
            // Fail the whole thing.
            fut.onDone(e);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 13 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class JmhCacheLocksBenchmark method main.

/**
 * Run benchmarks.
 *
 * @param args Arguments.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    final String simpleClsName = JmhCacheLocksBenchmark.class.getSimpleName();
    final int threads = 4;
    final boolean client = true;
    final CacheAtomicityMode atomicityMode = CacheAtomicityMode.TRANSACTIONAL;
    final CacheWriteSynchronizationMode writeSyncMode = CacheWriteSynchronizationMode.FULL_SYNC;
    final String output = simpleClsName + "-" + threads + "-threads" + "-" + (client ? "client" : "data") + "-" + atomicityMode + "-" + writeSyncMode;
    final Options opt = new OptionsBuilder().threads(threads).include(simpleClsName).output(output + ".jmh.log").jvmArgs("-Xms1g", "-Xmx1g", "-XX:+UnlockCommercialFeatures", JmhIdeBenchmarkRunner.createProperty(PROP_ATOMICITY_MODE, atomicityMode), JmhIdeBenchmarkRunner.createProperty(PROP_WRITE_SYNC_MODE, writeSyncMode), JmhIdeBenchmarkRunner.createProperty(PROP_DATA_NODES, 4), JmhIdeBenchmarkRunner.createProperty(PROP_CLIENT_MODE, client)).build();
    new Runner(opt).run();
}
Also used : Options(org.openjdk.jmh.runner.options.Options) JmhIdeBenchmarkRunner(org.apache.ignite.internal.benchmarks.jmh.runner.JmhIdeBenchmarkRunner) Runner(org.openjdk.jmh.runner.Runner) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder)

Example 14 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class IgnitePdsBinaryMetadataAsyncWritingTest method putRequestFromServer.

/**
 * @param expectedBlocked
 * @throws Exception
 */
private void putRequestFromServer(boolean expectedBlocked) throws Exception {
    String cacheName = "testCache";
    CacheWriteSynchronizationMode syncMode = expectedBlocked ? FULL_SYNC : PRIMARY_SYNC;
    CacheConfiguration testCacheCfg = new CacheConfiguration(cacheName).setBackups(2).setAtomicityMode(CacheAtomicityMode.ATOMIC).setCacheMode(CacheMode.PARTITIONED).setWriteSynchronizationMode(syncMode);
    IgniteEx ig0 = startGrid(0);
    startGrid(1);
    final CountDownLatch fileWriteLatch = initSlowFileIOFactory();
    IgniteEx ig2 = startGrid(2);
    specialFileIOFactory = null;
    startGrid(3);
    ig0.cluster().active(true);
    IgniteCache cache = ig0.createCache(testCacheCfg);
    int key = 0;
    Affinity<Object> aff = ig0.affinity(cacheName);
    while (true) {
        key = findNonAffinityKeyForNode(aff, ig0.localNode(), key);
        if (aff.isBackup(ig2.localNode(), key))
            break;
        else
            key++;
    }
    AtomicBoolean putFinished = new AtomicBoolean(false);
    int key0 = key;
    GridTestUtils.runAsync(() -> {
        cache.put(key0, new TestAddress(key0, "USA", "NYC"));
        putFinished.set(true);
    });
    if (expectedBlocked) {
        assertFalse(GridTestUtils.waitForCondition(() -> putFinished.get(), 5_000));
        fileWriteLatch.countDown();
        assertTrue(GridTestUtils.waitForCondition(() -> putFinished.get(), 5_000));
    } else
        assertTrue(GridTestUtils.waitForCondition(() -> putFinished.get(), 5_000));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 15 with CacheWriteSynchronizationMode

use of org.apache.ignite.cache.CacheWriteSynchronizationMode in project ignite by apache.

the class IgniteClientReconnectCacheTest method testReconnectOperationInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectOperationInProgress() throws Exception {
    IgniteEx client = startClientGrid(SRV_CNT);
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED)
                info("Client disconnected: " + evt);
            else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED)
                info("Client reconnected: " + evt);
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    IgniteInClosure<IgniteCache<Object, Object>> putOp = new CI1<IgniteCache<Object, Object>>() {

        @Override
        public void apply(IgniteCache<Object, Object> cache) {
            while (true) {
                try {
                    cache.put(1, 1);
                    break;
                } catch (Exception e) {
                    if (e.getCause() instanceof IgniteClientDisconnectedException)
                        throw e;
                    else
                        MvccFeatureChecker.assertMvccWriteConflict(e);
                }
            }
        }
    };
    IgniteInClosure<IgniteCache<Object, Object>> getOp = new CI1<IgniteCache<Object, Object>>() {

        @Override
        public void apply(IgniteCache<Object, Object> cache) {
            cache.get(1);
        }
    };
    IgniteInClosure<IgniteCache<Object, Object>> getAllOp = new CI1<IgniteCache<Object, Object>>() {

        @Override
        public void apply(IgniteCache<Object, Object> cache) {
            cache.getAll(F.asSet(1, 2));
        }
    };
    int cnt = 0;
    for (CacheAtomicityMode atomicityMode : CacheAtomicityMode.values()) {
        for (CacheWriteSynchronizationMode syncMode : CacheWriteSynchronizationMode.values()) {
            CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
            ccfg.setAtomicityMode(atomicityMode);
            ccfg.setName("cache-" + cnt++);
            ccfg.setWriteSynchronizationMode(syncMode);
            if (syncMode != FULL_ASYNC) {
                Class<?> cls = (ccfg.getAtomicityMode() == ATOMIC) ? GridNearAtomicUpdateResponse.class : GridNearTxPrepareResponse.class;
                log.info("Test cache put [atomicity=" + atomicityMode + ", syncMode=" + syncMode + ']');
                checkOperationInProgressFails(client, ccfg, cls, putOp);
                client.destroyCache(ccfg.getName());
            }
            log.info("Test cache get [atomicity=" + atomicityMode + ", syncMode=" + syncMode + ']');
            checkOperationInProgressFails(client, ccfg, GridNearSingleGetResponse.class, getOp);
            checkOperationInProgressFails(client, ccfg, GridNearGetResponse.class, getAllOp);
            client.destroyCache(ccfg.getName());
        }
    }
}
Also used : CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCache(org.apache.ignite.IgniteCache) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Aggregations

CacheWriteSynchronizationMode (org.apache.ignite.cache.CacheWriteSynchronizationMode)20 Test (org.junit.Test)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 UUID (java.util.UUID)3 IgniteCache (org.apache.ignite.IgniteCache)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CacheException (javax.cache.CacheException)1 Factory (javax.cache.configuration.Factory)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheMode (org.apache.ignite.cache.CacheMode)1 FifoEvictionPolicyFactory (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicyFactory)1 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1