ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [18/35] incubator-ignite git commit: ignite-946: simplified VersionedEntry interface
Date Sat, 15 Aug 2015 01:49:05 GMT
ignite-946: simplified VersionedEntry interface


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

Branch: refs/heads/ignite-264
Commit: b6bef13eef82d9a2e040c01881d07c186ade372e
Parents: dd3cecf
Author: Denis Magda <dmagda@gridgain.com>
Authored: Tue Aug 11 10:17:24 2015 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Tue Aug 11 10:17:24 2015 +0300

----------------------------------------------------------------------
 .../ignite/cache/version/VersionedEntry.java    | 83 +++++++++-----------
 .../cache/version/CacheVersionedEntryImpl.java  | 23 +-----
 .../cache/version/GridCacheVersionManager.java  |  4 +-
 .../CacheVersionedEntryAbstractTest.java        |  9 +--
 4 files changed, 45 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6bef13e/modules/core/src/main/java/org/apache/ignite/cache/version/VersionedEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/version/VersionedEntry.java
b/modules/core/src/main/java/org/apache/ignite/cache/version/VersionedEntry.java
index 1aac68a..135d681 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/version/VersionedEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/version/VersionedEntry.java
@@ -24,7 +24,7 @@ import javax.cache.processor.*;
 import java.util.*;
 
 /**
- * Cache entry that stores entry's version related information.
+ * Cache entry that stores entry's version related information along with its data.
  *
  * To get a {@code VersionedEntry} of an {@link Cache.Entry} use {@link Cache.Entry#unwrap(Class)}
by passing
  * {@code VersionedEntry} class to it as the argument.
@@ -42,62 +42,51 @@ import java.util.*;
  * is excluded from responses.
  * <h2 class="header">Java Example</h2>
  * <pre name="code" class="java">
- * Cache<Integer, String> cache = grid(0).cache(null);
+ * IgniteCache<Integer, String> cache = grid(0).cache(null);
  *
- *  cache.invoke(100, new EntryProcessor<Integer, String, Object>() {
- *      public Object process(MutableEntry<Integer, String> entry, Object... arguments)
throws EntryProcessorException {
- *          VersionedEntry<Integer, String> verEntry = entry.unwrap(VersionedEntry.class);
- *          return entry;
- *       }
- *   });
+ * VersionedEntry<String, Integer> entry1 = cache.invoke(100,
+ *     new EntryProcessor<Integer, String, VersionedEntry<String, Integer>>()
{
+ *          public VersionedEntry<String, Integer> process(MutableEntry<Integer,
String> entry,
+ *              Object... arguments) throws EntryProcessorException {
+ *                  return entry.unwrap(VersionedEntry.class);
+ *          }
+ *     });
+ *
+ * // Cache entry for the given key may be updated at some point later.
+ *
+ * VersionedEntry<String, Integer> entry2 = cache.invoke(100,
+ *     new EntryProcessor<Integer, String, VersionedEntry<String, Integer>>()
{
+ *          public VersionedEntry<String, Integer> process(MutableEntry<Integer,
String> entry,
+ *              Object... arguments) throws EntryProcessorException {
+ *                  return entry.unwrap(VersionedEntry.class);
+ *          }
+ *     });
+ *
+ * if (entry1.version().compareTo(entry2.version()) < 0) {
+ *     // the entry has been updated
+ * }
  * </pre>
  */
 public interface VersionedEntry<K, V> extends Cache.Entry<K, V> {
     /**
-     * Versions comparator.
-     */
-    public static final Comparator<VersionedEntry> VER_COMP = new Comparator<VersionedEntry>()
{
-        @Override public int compare(VersionedEntry o1, VersionedEntry o2) {
-            int res = Integer.compare(o1.topologyVersion(), o2.topologyVersion());
-
-            if (res != 0)
-                return res;
-
-            res = Long.compare(o1.order(), o2.order());
-
-            if (res != 0)
-                return res;
-
-            return Integer.compare(o1.nodeOrder(), o2.nodeOrder());
-        }
-    };
-
-    /**
-     * Gets the topology version at the time when the entry with a given pair of key and
value has been created.
-     *
-     * @return Topology version plus number of seconds from the start time of the first grid
node.
-     */
-    public int topologyVersion();
-
-    /**
-     * Gets versioned entry unique order.
-     * Each time a cache entry for a given key is updated a new {@code VersionedEntry} with
increased order is created.
-     *
-     * @return Versioned entry unique order.
-     */
-    public long order();
-
-    /**
-     * Gets local node order at the time when the entry with a given pair of key and value
has been created.
+     * Returns a comparable object representing the version of this cache entry.
+     * <p>
+     * It is valid to compare cache entries' versions for the same key. In this case the
latter update will be
+     * represented by a higher version. The result of versions comparison of cache entries
of different keys is
+     * undefined.
      *
-     * @return Local node order on which this version has been assigned.
+     * @return Version of this cache entry.
      */
-    public int nodeOrder();
+    public Comparable version();
 
     /**
-     * Gets the time when the entry with a given pair of key and value has been created.
+     * Returns the time when the cache entry for the given key has been updated or initially
created.
+     * <p>
+     * It is valid to compare cache entries' update time for the same key. In this case the
latter update will
+     * be represented by higher update time. The result of update time comparison of cache
entries of different keys is
+     * undefined.
      *
      * @return Time in milliseconds.
      */
-    public long creationTime();
+    public long updateTime();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6bef13e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryImpl.java
index 22b699a..97b1995 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryImpl.java
@@ -51,30 +51,13 @@ public class CacheVersionedEntryImpl<K, V> extends CacheEntryImpl<K,
V> implemen
         this.ver = ver;
     }
 
-    /**
-     * @return Version.
-     */
-    @Nullable public GridCacheVersion version() {
-        return ver;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int topologyVersion() {
-        return ver.topologyOrder();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int nodeOrder() {
-        return ver.nodeOrder();
-    }
-
     /** {@inheritDoc} */
-    @Override public long order() {
-        return ver.order();
+    public GridCacheVersion version() {
+        return ver;
     }
 
     /** {@inheritDoc} */
-    @Override public long creationTime() {
+    @Override public long updateTime() {
         return ver.globalTime();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6bef13e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
index d465a0c..85b14a4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/version/GridCacheVersionManager.java
@@ -224,6 +224,8 @@ public class GridCacheVersionManager extends GridCacheSharedManagerAdapter
{
         if (topVer == -1)
             topVer = cctx.kernalContext().discovery().topologyVersion();
 
+        long globalTime = cctx.kernalContext().clockSync().adjustedTime(topVer);
+
         if (addTime) {
             if (gridStartTime == 0)
                 gridStartTime = cctx.kernalContext().discovery().gridStartTime();
@@ -231,8 +233,6 @@ public class GridCacheVersionManager extends GridCacheSharedManagerAdapter
{
             topVer += (gridStartTime - TOP_VER_BASE_TIME) / 1000;
         }
 
-        long globalTime = cctx.kernalContext().clockSync().adjustedTime(topVer);
-
         int locNodeOrder = (int)cctx.localNode().order();
 
         if (txSerEnabled) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6bef13e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryAbstractTest.java
index 0ad8038..9648b9b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/version/CacheVersionedEntryAbstractTest.java
@@ -152,7 +152,8 @@ public abstract class CacheVersionedEntryAbstractTest extends GridCacheAbstractS
                     }
             });
 
-        assert VersionedEntry.VER_COMP.compare(ver1, ver2) < 0;
+        assert ver1.version().compareTo(ver2.version()) < 0;
+        assert ver1.updateTime() < ver2.updateTime();
     }
 
     /**
@@ -161,10 +162,8 @@ public abstract class CacheVersionedEntryAbstractTest extends GridCacheAbstractS
     private void checkVersionedEntry(VersionedEntry<Integer, String> entry) {
         assertNotNull(entry);
 
-        assert entry.topologyVersion() > 0;
-        assert entry.order() > 0;
-        assert entry.nodeOrder() > 0;
-        assert entry.creationTime() > 0;
+        assertNotNull(entry.version());
+        assert entry.updateTime() > 0;
 
         assertNotNull(entry.getKey());
         assertNotNull(entry.getValue());


Mime
View raw message