Index: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxAsyncOpsSemaphorePermitsExeededTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxAsyncOpsSemaphorePermitsExeededTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxAsyncOpsSemaphorePermitsExeededTest.java new file mode 100644 --- /dev/null (date 1658060328053) +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxAsyncOpsSemaphorePermitsExeededTest.java (date 1658060328053) @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.transactions; + +import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.ConnectorConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.junit.Test; + +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; + +/** + * + */ +public class TxAsyncOpsSemaphorePermitsExeededTest extends GridCommonAbstractTest { + /** Servers count. */ + public static final int SERVERS_COUNT = 3; + + /** Failed flag. */ + public final AtomicBoolean failed = new AtomicBoolean(false); + + /** {@inheritDoc} */ + @Override + protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setCacheConfiguration(new CacheConfiguration<>() + .setName(DEFAULT_CACHE_NAME) + .setAtomicityMode(TRANSACTIONAL) + .setBackups(2) + .setWriteSynchronizationMode(FULL_SYNC) + .setMaxConcurrentAsyncOperations(Integer.MAX_VALUE - 500)); + + cfg.setConnectorConfiguration(new ConnectorConfiguration()); + + cfg.setFailureHandler((ignite, ctx) -> { + failed.set(true); + + return true; + }); + + return cfg; + } + + /** {@inheritDoc} */ + @Override + protected void beforeTest() throws Exception { + startGrids(SERVERS_COUNT); + + failed.set(false); + } + + /** {@inheritDoc} */ + @Override + protected void afterTest() throws Exception { + stopAllGrids(); + } + + @Test + public void testOnClient() throws Exception { + doTest(startClientGrid(SERVERS_COUNT)); + } + + @Test + public void testOnServer() throws Exception { + doTest(startGrid(SERVERS_COUNT)); + } + + private void doTest(Ignite ignite) throws Exception { + GridTestUtils.runAsync(() -> { + ThreadLocalRandom rnd = ThreadLocalRandom.current(); + + while (!Thread.interrupted()) { + try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { + ignite.cache(DEFAULT_CACHE_NAME).put(rnd.nextInt(), rnd.nextInt()); + + tx.commit(); + } + } + }); + + boolean failed = GridTestUtils.waitForCondition(this.failed::get, getTestTimeout()); + + assertFalse("Critical failure occurred", failed); + } +} Index: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java (revision daca6c25039fb13e5307abc2bdad912bf20df420) +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java (date 1658059116066) @@ -4680,9 +4680,12 @@ */ @Nullable protected IgniteInternalFuture asyncOpAcquire(boolean retry) { try { - if (!retry && asyncOpsSem != null) + if (!retry && asyncOpsSem != null) { asyncOpsSem.acquire(); + log.warning(">>>>>> asyncOpsSem#acquire. Permits: " + asyncOpsSem.availablePermits()); + } + return null; } catch (InterruptedException e) { @@ -4699,8 +4702,11 @@ * @param retry Retry flag. */ protected final void asyncOpRelease(boolean retry) { - if (!retry && asyncOpsSem != null) + if (!retry && asyncOpsSem != null) { asyncOpsSem.release(); + + log.warning(">>>>>> asyncOpsSem#release. Permits: " + asyncOpsSem.availablePermits()); + } } /** {@inheritDoc} */