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;
}
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);
}
}
}
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();
}
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));
}
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());
}
}
}
Aggregations