Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-23138 Fix TxWithKeyContentionSelfTest (Cache 12 group) #11512

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.TestRecordingCommunicationSpi;
import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse;
import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareResponse;
import org.apache.ignite.internal.util.future.GridCompoundFuture;
import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.typedef.G;
Expand Down Expand Up @@ -217,7 +217,7 @@ public void testOptimisticRepeatableReadCheckContentionTxMetricNear() throws Exc
* @throws Exception If failed.
*/
private void runKeyCollisionsMetric(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
Ignite ig = startGridsMultiThreaded(3);
Ignite ig = startGridsMultiThreaded(2);

int contCnt = (int)U.staticField(IgniteTxManager.class, "COLLISIONS_QUEUE_THRESHOLD") * 5;

Expand All @@ -229,11 +229,21 @@ private void runKeyCollisionsMetric(TransactionConcurrency concurrency, Transact

Ignite cl = startGrid();

CacheConfiguration<?, ?> dfltCacheCfg = getCacheConfiguration(DEFAULT_CACHE_NAME);

dfltCacheCfg.setStatisticsEnabled(true);

String cacheName = dfltCacheCfg.getName();

IgniteTransactions cliTxMgr = cl.transactions();

IgniteCache<Integer, Integer> cache = ig.cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Integer> cache = ig.cache(cacheName);

IgniteCache<Integer, Integer> cache0 = cl.cache(cacheName);

ig.cache(DEFAULT_CACHE_NAME).enableStatistics(true);

IgniteCache<Integer, Integer> cache0 = cl.cache(DEFAULT_CACHE_NAME);
cl.cache(DEFAULT_CACHE_NAME).enableStatistics(true);

final Integer keyId = primaryKey(cache);

Expand All @@ -248,7 +258,7 @@ private void runKeyCollisionsMetric(TransactionConcurrency concurrency, Transact

commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridNearTxFinishResponse && blockOnce.getCount() > 0) {
if (msg instanceof GridNearTxPrepareResponse && blockOnce.getCount() > 0) {
blockOnce.countDown();

return true;
Expand Down Expand Up @@ -296,26 +306,43 @@ private void runKeyCollisionsMetric(TransactionConcurrency concurrency, Transact
commSpi0.stopBlock();
}

Thread.sleep(1000);

IgniteTxManager srvTxMgr = ((IgniteEx)ig).context().cache().context().tm();

assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
CountDownLatch latch = new CountDownLatch(1);

try {
U.invoke(IgniteTxManager.class, srvTxMgr, "collectTxCollisionsInfo");
latch.countDown();
}
catch (IgniteCheckedException e) {
fail(e.toString());
}

latch.await();

Thread.sleep(1000);

final int[] i = {0};

assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { // failed here
@Override public boolean apply() {
try {
U.invoke(IgniteTxManager.class, srvTxMgr, "collectTxCollisionsInfo");
}
catch (IgniteCheckedException e) {
fail(e.toString());
}
log.warning("Apply action number " + i[0]);

i[0] = i[0] + 1;

CacheMetrics metrics = ig.cache(DEFAULT_CACHE_NAME).localMetrics();

String coll1 = metrics.getTxKeyCollisions();

log.warning("!!!!!! coll1 = " + coll1);

if (!coll1.isEmpty()) {
String coll2 = metrics.getTxKeyCollisions();

// check idempotent
assertEquals(coll1, coll2);
assertEquals(coll1, coll2); //сравнивает жопу с жопой

assertTrue(coll1.contains("queueSize"));

Expand All @@ -324,7 +351,7 @@ private void runKeyCollisionsMetric(TransactionConcurrency concurrency, Transact
else
return false;
}
}, 10_000));
}, 25_000));

f.get();

Expand Down