Skip to content

Commit

Permalink
IGNITE-23110 Disallow IgniteCache#clear() within transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Bakuli committed Nov 13, 2024
1 parent 82f5771 commit 2fddaa7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,10 @@ public List<GridCacheClearAllRunnable<K, V>> splitClearLocally(boolean srv, bool

/** {@inheritDoc} */
@Override public void clear() throws IgniteCheckedException {
if (ctx.transactional() && ctx.grid().transactions().tx() != null)
if (ctx.transactional() && ctx.grid().transactions().tx() != null) {
throw new CacheException("Failed to invoke a non-transactional operation within a transaction: " +
"IgniteCache.clear().");
}

clear((Set<? extends K>)null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class NonTransactionalOperationsInTxTest extends GridCommonAbstractTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName)
.setCacheConfiguration(defaultCacheConfiguration().setAtomicityMode(TRANSACTIONAL));
.setCacheConfiguration(defaultCacheConfiguration().setAtomicityMode(TRANSACTIONAL));

return cfg;
}
Expand Down Expand Up @@ -62,6 +62,7 @@ public void testIgniteCacheClearOnClientNode() throws Exception {

/**
* It should throw exception.
*
* @param ignite Ignite.
*/
private void checkIgniteCacheClear(IgniteEx ignite) {
Expand All @@ -70,15 +71,15 @@ private void checkIgniteCacheClear(IgniteEx ignite) {
cache.put(1, 1);

assertThrows(null,
() -> doInTransaction(ignite, () -> {
cache.put(2, 2);
() -> doInTransaction(ignite, () -> {
cache.put(2, 2);

cache.clear();
cache.clear();

return null;
}),
CacheException.class,
"Failed to invoke a non-transactional operation within a transaction"
return null;
}),
CacheException.class,
"Failed to invoke a non-transactional operation within a transaction"
);

assertTrue(cache.containsKey(1));
Expand Down

0 comments on commit 2fddaa7

Please sign in to comment.