Repository: ignite Updated Branches: refs/heads/ignite-1607 cd56f5a35 -> b9051da90
ignite-1607 WIP Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b9051da9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b9051da9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b9051da9 Branch: refs/heads/ignite-1607 Commit: b9051da90db97944d8671ee9946ee1feef257213 Parents: cd56f5a Author: sboikov <[email protected]> Authored: Mon Oct 19 09:52:24 2015 +0300 Committer: sboikov <[email protected]> Committed: Mon Oct 19 09:58:22 2015 +0300 ---------------------------------------------------------------------- .../processors/cache/GridCacheMapEntry.java | 10 ++- .../cache/distributed/near/GridNearTxLocal.java | 2 +- .../cache/transactions/IgniteTxEntry.java | 5 +- .../transactions/IgniteTxLocalAdapter.java | 14 ++-- .../CacheSerializableTransactionsTest.java | 70 ++++++++++++++++---- .../GridCacheAbstractFailoverSelfTest.java | 14 +++- 6 files changed, 88 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/b9051da9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java index 8d7d6ac..9a6eb06 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java @@ -2838,8 +2838,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme assert !obsolete() : this; if (!serReadVer.equals(ver)) { - if (!((isStartVersion() || deletedUnlocked()) && serReadVer.equals(IgniteTxEntry.READ_NEW_ENTRY_VER))) - return false; + boolean empty = isStartVersion() || deletedUnlocked(); + + if (serReadVer.equals(IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER)) + return empty; + else if (serReadVer.equals(IgniteTxEntry.SER_READ_NOT_EMPTY_VER)) + return !empty; + + return false; } return true; http://git-wip-us.apache.org/repos/asf/ignite/blob/b9051da9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java index 2c0d285..35a3b22 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java @@ -445,7 +445,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter { c.apply(key, v, ver); } else - c.apply(key, null, IgniteTxEntry.READ_NEW_ENTRY_VER); + c.apply(key, null, IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/b9051da9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java index 7929167..04393a5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java @@ -67,7 +67,10 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message { private static final long serialVersionUID = 0L; /** Dummy version for non-existing entry read in SERIALIZABLE transaction. */ - public static final GridCacheVersion READ_NEW_ENTRY_VER = new GridCacheVersion(0, 0, 0, 0); + public static final GridCacheVersion SER_READ_EMPTY_ENTRY_VER = new GridCacheVersion(0, 0, 0, 0); + + /** Dummy version for any existing entry read in SERIALIZABLE transaction. */ + public static final GridCacheVersion SER_READ_NOT_EMPTY_VER = new GridCacheVersion(0, 0, 0, 1); /** Owning transaction. */ @GridToStringExclude http://git-wip-us.apache.org/repos/asf/ignite/blob/b9051da9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java index 0c48b93..7668bca 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java @@ -105,6 +105,8 @@ import static org.apache.ignite.internal.processors.cache.GridCacheOperation.REA import static org.apache.ignite.internal.processors.cache.GridCacheOperation.RELOAD; import static org.apache.ignite.internal.processors.cache.GridCacheOperation.TRANSFORM; import static org.apache.ignite.internal.processors.cache.GridCacheOperation.UPDATE; +import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER; +import static org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_NOT_EMPTY_VER; import static org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE; import static org.apache.ignite.internal.processors.dr.GridDrType.DR_PRIMARY; import static org.apache.ignite.transactions.TransactionState.COMMITTED; @@ -429,7 +431,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter if (!readThrough || !cacheCtx.readThrough()) { for (KeyCacheObject key : keys) - c.apply(key, null, IgniteTxEntry.READ_NEW_ENTRY_VER); + c.apply(key, null, SER_READ_EMPTY_ENTRY_VER); return new GridFinishedFuture<>(); } @@ -525,14 +527,14 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter } } else - ver = IgniteTxEntry.READ_NEW_ENTRY_VER; + ver = SER_READ_EMPTY_ENTRY_VER; c.apply(key, val, ver); } }); for (KeyCacheObject key : misses0.keySet()) - c.apply(key, null, IgniteTxEntry.READ_NEW_ENTRY_VER); + c.apply(key, null, SER_READ_EMPTY_ENTRY_VER); } return new GridFinishedFuture<>(); @@ -2181,7 +2183,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter if (needReadVer) { assert readVer != null; - txEntry.serializableReadVersion(readVer); + txEntry.serializableReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer); } } @@ -2236,7 +2238,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter if (needReadVer) { assert readVer != null; - txEntry.serializableReadVersion(readVer); + txEntry.serializableReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer); } if (retval && !transform) @@ -2377,7 +2379,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter if (needReadVer) { assert loadVer != null; - e.serializableReadVersion(loadVer); + e.serializableReadVersion(singleRmv && val != null ? SER_READ_NOT_EMPTY_VER : loadVer); } if (singleRmv) { http://git-wip-us.apache.org/repos/asf/ignite/blob/b9051da9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java index 1cf30b6..67134f0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheSerializableTransactionsTest.java @@ -1735,36 +1735,70 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest { List<Integer> keys = testKeys(cache); - for (Integer key : keys) { + for (final Integer key : keys) { log.info("Test key: " + key); if (!noVal) cache.put(key, -1); - try { - try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - boolean res = cache.remove(key); + if (noVal) { + try { + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + boolean res = cache.remove(key); - assertEquals(!noVal, res); + assertFalse(res); - updateKey(cache, key, 1); + updateKey(cache, key, -1); - tx.commit(); + tx.commit(); + } + + fail(); + } + catch (TransactionOptimisticException e) { + log.info("Expected exception: " + e); } - fail(); - } - catch (TransactionOptimisticException e) { - log.info("Expected exception: " + e); + checkValue(key, -1, cache.getName()); } + else { + try { + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + boolean res = cache.remove(key); - checkValue(key, 1, cache.getName()); + assertTrue(res); + + txAsync(cache, PESSIMISTIC, REPEATABLE_READ, + new IgniteClosure<IgniteCache<Integer, Integer>, Void>() { + @Override public Void apply(IgniteCache<Integer, Integer> cache) { + cache.remove(key); + + return null; + } + } + ); + + tx.commit(); + } + + fail(); + } + catch (TransactionOptimisticException e) { + log.info("Expected exception: " + e); + } + + checkValue(key, null, cache.getName()); + + cache.put(key, -1); + } try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { boolean res = cache.remove(key); assertTrue(res); + updateKey(cache, key, 2); + tx.commit(); } @@ -1774,7 +1808,15 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest { try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { cache.removeAll(Collections.singleton(key)); - updateKey(cache, key, 1); + txAsync(cache, PESSIMISTIC, REPEATABLE_READ, + new IgniteClosure<IgniteCache<Integer, Integer>, Void>() { + @Override public Void apply(IgniteCache<Integer, Integer> cache) { + cache.remove(key); + + return null; + } + } + ); tx.commit(); } @@ -2970,7 +3012,7 @@ public class CacheSerializableTransactionsTest extends GridCommonAbstractTest { } }, THREADS, "tx-thread"); - fut.get(30_000); + fut.get(60_000); if (nonSerFut != null) nonSerFut.get(); http://git-wip-us.apache.org/repos/asf/ignite/blob/b9051da9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java index f4813ff..da54d15 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFailoverSelfTest.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.cache; +import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; import javax.cache.CacheException; import org.apache.ignite.Ignite; @@ -330,14 +331,21 @@ public abstract class GridCacheAbstractFailoverSelfTest extends GridCacheAbstrac * @throws IgniteCheckedException If failed. */ private void remove(Ignite ignite, IgniteCache<String, Integer> cache, final int cnt, - TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { + TransactionConcurrency concurrency, final TransactionIsolation isolation) throws Exception { try { info("Removing values form cache [0," + cnt + ')'); CU.inTx(ignite, cache, concurrency, isolation, new CIX1<IgniteCache<String, Integer>>() { @Override public void applyx(IgniteCache<String, Integer> cache) { - for (int i = 0; i < cnt; i++) - cache.remove("key" + i); + for (int i = 0; i < cnt; i++) { + String key = "key" + i; + + // Use removeAll for serializable tx to avoid version check. + if (isolation == TransactionIsolation.SERIALIZABLE) + cache.removeAll(Collections.singleton(key)); + else + cache.remove(key); + } } }); }
