ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject incubator-ignite git commit: # IGNITE-283: Fixes.
Date Tue, 24 Feb 2015 07:40:36 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-283-tx 7309772dc -> bfaebf2d3


# IGNITE-283: Fixes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bfaebf2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bfaebf2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bfaebf2d

Branch: refs/heads/ignite-283-tx
Commit: bfaebf2d3e3d250b851e53cc176de211e085ad1f
Parents: 7309772
Author: vozerov <vozerov@gridgain.com>
Authored: Tue Feb 24 10:40:32 2015 +0300
Committer: vozerov <vozerov@gridgain.com>
Committed: Tue Feb 24 10:40:32 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheMapEntry.java     | 74 ++++++++------------
 .../GridDistributedTxRemoteAdapter.java         |  3 +-
 .../cache/transactions/IgniteTxAdapter.java     | 54 +++++++-------
 3 files changed, 60 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfaebf2d/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 653d8ec..cc76206 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
@@ -47,6 +47,7 @@ import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.events.EventType.*;
 import static org.apache.ignite.internal.processors.cache.CacheFlag.*;
+import static org.apache.ignite.internal.processors.cache.GridCacheOperation.DELETE;
 import static org.apache.ignite.internal.processors.dr.GridDrType.*;
 import static org.apache.ignite.transactions.TransactionState.*;
 
@@ -1612,8 +1613,8 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
                         valBytes = null;
                     }
 
-                    GridTuple3<Long, Long, Boolean> expiration = ttlAndExpireTime(expiryPlc,
-                        explicitTtl, explicitExpireTime);
+                    GridTuple3<Long, Long, Boolean> expiration = ttlAndExpireTime(expiryPlc,
explicitTtl,
+                        explicitExpireTime);
 
                     // Prepare old and new entries for conflict resolution.
                     GridCacheVersionedEntryEx<K, V> oldEntry = versionedEntry();
@@ -2144,60 +2145,41 @@ public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K,
V>
      * Get TTL, expire time and remove flag for the given entry, expiration policy and explicit
TTL and expire time.
      *
      * @param expiry Expiration policy.
-     * @param explicitTtl Explicit TTL.
-     * @param explicitExpireTime Explicit expire time.
+     * @param ttl Explicit TTL.
+     * @param expireTime Explicit expire time.
      * @return Result.
      */
-    private GridTuple3<Long, Long, Boolean> ttlAndExpireTime(IgniteCacheExpiryPolicy
expiry, long explicitTtl,
-        long explicitExpireTime) {
-        long ttl;
-        long expireTime;
-        boolean rmv;
+    private GridTuple3<Long, Long, Boolean> ttlAndExpireTime(IgniteCacheExpiryPolicy
expiry, long ttl, long expireTime)
+        throws GridCacheEntryRemovedException {
+        boolean rmv = false;
 
-        if (explicitTtl != CU.TTL_NOT_CHANGED) {
-            // TTL is set explicitly.
-            assert explicitTtl != CU.TTL_MINIMUM && explicitTtl >= 0L;
+        // 1. If TTL is not changed, then calculate it based on expiry.
+        if (ttl == CU.TTL_NOT_CHANGED) {
+            if (expiry != null)
+                ttl = hasValueUnlocked() ? expiry.forUpdate() : expiry.forCreate();
+        }
 
-            ttl = explicitTtl;
-            expireTime = explicitExpireTime != CU.EXPIRE_TIME_CALCULATE ?
-                explicitExpireTime : CU.toExpireTime(explicitTtl);
-            rmv = false;
+        // 2. If TTL is zero, then set delete marker.
+        if (ttl == CU.TTL_ZERO) {
+            rmv = true;
+
+            ttl = CU.TTL_ETERNAL;
         }
-        else {
-            // Need to calculate TTL.
-            if (expiry != null) {
-                // Expiry exists.
-                long sysTtl = hasValueUnlocked() ? expiry.forUpdate() : expiry.forCreate();
-
-                if (sysTtl == CU.TTL_ZERO) {
-                    // Entry must be expired immediately.
-                    ttl = CU.TTL_MINIMUM;
-                    expireTime = CU.expireTimeInPast();
-                    rmv = true;
-                }
-                else if (sysTtl == CU.TTL_NOT_CHANGED) {
-                    // TTL is not changed.
-                    ttl = ttlExtras();
-                    expireTime = CU.toExpireTime(ttl);
-                    rmv = false;
-                }
-                else {
-                    // TTL is changed.
-                    assert sysTtl >= 0;
 
-                    ttl = sysTtl;
-                    expireTime = CU.toExpireTime(ttl);
-                    rmv = false;
-                }
-            }
-            else {
-                // No expiry, entry is immortal.
+        // 3. If TTL is still not changed, then either use old entry TTL or set it to "ETERNAL".
+        if (ttl == CU.TTL_NOT_CHANGED) {
+            if (isNew())
                 ttl = CU.TTL_ETERNAL;
-                expireTime = CU.EXPIRE_TIME_ETERNAL;
-                rmv = false;
+            else {
+                ttl = ttlExtras();
+                expireTime = expireTimeExtras();
             }
         }
 
+        // 1.4 If expire time was not set explicitly, then calculate it.
+        if (expireTime == CU.EXPIRE_TIME_CALCULATE)
+            expireTime = CU.toExpireTime(ttl);
+
         return F.t(ttl, expireTime, rmv);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfaebf2d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
index f920e04..473d025 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
@@ -629,7 +629,8 @@ public class GridDistributedTxRemoteAdapter<K, V> extends IgniteTxAdapter<K,
V>
                                                         val0 = (V) valBytesTuple.get();
                                                     else
                                                         valBytes0 = valBytesTuple.get();
-                                                } else
+                                                }
+                                                else
                                                     val0 = cached.rawGet();
 
                                                 nearCached.updateOrEvict(xidVer, val0, valBytes0,
cached.expireTime(),

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfaebf2d/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
index 0dbd552..ae4020a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
@@ -1296,50 +1296,56 @@ public abstract class IgniteTxAdapter<K, V> extends GridMetadataAwareAdapter
      * @throws IgniteCheckedException In case of eny exception.
      * @throws GridCacheEntryRemovedException If entry got removed.
      */
+    @SuppressWarnings({"unchecked", "ConstantConditions"})
     protected IgniteBiTuple<GridCacheOperation, GridCacheVersionConflictContext<K,
V>> conflictResolve(
         GridCacheOperation op, IgniteTxEntry txEntry, V newVal, byte[] newValBytes, GridCacheVersion
newVer,
         GridCacheEntryEx<K, V> old)
         throws IgniteCheckedException, GridCacheEntryRemovedException {
         assert newVer != null;
 
-        // 1. Convert TTL and expire time.
+        // 1. Calculate TTL and expire time.
         long newTtl = txEntry.ttl();
         long newExpireTime = txEntry.conflictExpireTime();
 
+        // 1.1. If TTL is not changed, then calculate it based on expiry.
         if (newTtl == CU.TTL_NOT_CHANGED) {
-            assert op == DELETE || newVer.conflictVersion().dataCenterId() == cctx.dataCenterId()
:
-                "TTL can be not-explicit only for local updates.";
-
             ExpiryPolicy expiry = txEntry.context().expiryForTxEntry(txEntry);
 
-            if (expiry == null) {
-                newTtl = CU.TTL_ETERNAL;
-                newExpireTime = CU.EXPIRE_TIME_ETERNAL;
-            }
-            else {
-                if (op == DELETE) {
-                    newTtl = CU.TTL_ETERNAL;
-                    newExpireTime = CU.EXPIRE_TIME_ETERNAL;
-                }
-                else if (op == CREATE)
-                    newTtl = CU.toTtl(expiry.getExpiryForUpdate());
+            if (expiry != null) {
+                if (op == CREATE)
+                    newTtl = CU.toTtl(expiry.getExpiryForCreation());
                 else if (op == UPDATE)
                     newTtl = CU.toTtl(expiry.getExpiryForUpdate());
             }
+        }
 
-            if (newTtl == CU.TTL_ZERO) {
-                newTtl = CU.TTL_MINIMUM;
-                newExpireTime = CU.expireTimeInPast();
-            }
+        // 1.2. If TTL is set to zero, then mark operation as "DELETE".
+        if (newTtl == CU.TTL_ZERO) {
+            op = DELETE;
+
+            newTtl = CU.TTL_ETERNAL;
         }
-        else if (newTtl == CU.TTL_ZERO) {
-            assert newVer.conflictVersion().dataCenterId() == cctx.dataCenterId() :
-                "TTL can be not-explicit only for local updates.";
 
-            newTtl = CU.TTL_MINIMUM;
-            newExpireTime = CU.expireTimeInPast();
+        // 1.3. If TTL is still not changed, then either use old entry TTL or set it to "ETERNAL".
+        if (newTtl == CU.TTL_NOT_CHANGED) {
+            if (old.isNew())
+                newTtl = CU.TTL_ETERNAL;
+            else {
+                newTtl = old.rawTtl();
+                newExpireTime = old.rawExpireTime();
+            }
         }
 
+        // TTL must be resolved at this point.
+        assert newTtl != CU.TTL_ZERO && newTtl != CU.TTL_NOT_CHANGED;
+
+        // 1.4 If expire time was not set explicitly, then calculate it.
+        if (newExpireTime == CU.EXPIRE_TIME_CALCULATE)
+            newExpireTime = CU.toExpireTime(newTtl);
+
+        // Expire time must be resolved at this point.
+        assert newExpireTime != CU.EXPIRE_TIME_CALCULATE;
+
         // Construct old entry info.
         GridCacheVersionedEntryEx<K, V> oldEntry = old.versionedEntry();
 


Mime
View raw message