ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/2] incubator-ignite git commit: #ignite-460: Add class GridDistributedOffHeapCacheEntry.
Date Wed, 06 May 2015 15:06:01 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-460 [created] 9d1869c95


#ignite-460: Add class GridDistributedOffHeapCacheEntry.


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

Branch: refs/heads/ignite-460
Commit: d484af76ad4d922daec5b3d3d2386bbffb10953f
Parents: a33d3d4
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Wed May 6 17:11:03 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Wed May 6 17:11:03 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheMapEntry.java     | 70 ++++++++++++--------
 .../GridDistributedOffHeapCacheEntry.java       | 38 +++++++++++
 2 files changed, 82 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d484af76/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 71858d1..917b3ed 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
@@ -115,9 +115,6 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     @GridToStringInclude
     private final int hash;
 
-    /** Off-heap value pointer. */
-    protected long valPtr;
-
     /** Extras */
     @GridToStringInclude
     private GridCacheEntryExtras extras;
@@ -188,7 +185,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         if (cctx.cache().isIgfsDataCache() &&
             cctx.kernalContext().igfsHelper().isIgfsBlockKey(key.value(cctx.cacheObjectContext(),
false))) {
             int newSize = valueLength0(val, null);
-            int oldSize = valueLength0(this.val, (this.val == null && valPtr != 0)
? valueBytes0() : null);
+            int oldSize = valueLength0(this.val, (this.val == null && hasValPtr())
? valueBytes0() : null);
 
             int delta = newSize - oldSize;
 
@@ -199,7 +196,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         if (!isOffHeapValuesOnly()) {
             this.val = val;
 
-            valPtr = 0;
+            setValPtr(0);
         }
         else {
             try {
@@ -227,12 +224,12 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
                 if (val != null) {
                     byte type = val.type();
 
-                    valPtr = mem.putOffHeap(valPtr, val.valueBytes(cctx.cacheObjectContext()),
type);
+                    setValPtr(mem.putOffHeap(valPtr(), val.valueBytes(cctx.cacheObjectContext()),
type));
                 }
                 else {
-                    mem.removeOffHeap(valPtr);
+                    mem.removeOffHeap(valPtr());
 
-                    valPtr = 0;
+                    setValPtr(0);
                 }
             }
             catch (IgniteCheckedException e) {
@@ -270,7 +267,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
         CacheObject val0 = val;
 
-        if (val0 == null && valPtr != 0) {
+        if (val0 == null && hasValPtr()) {
             IgniteBiTuple<byte[], Byte> t = valueBytes0();
 
             return cctx.cacheObjects().toCacheObject(cctx.cacheObjectContext(), t.get2(),
t.get1());
@@ -434,16 +431,16 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
 
                     if (e != null) {
                         if (e.offheapPointer() > 0) {
-                            valPtr = e.offheapPointer();
+                            setValPtr(e.offheapPointer());
 
                             if (needVal) {
-                                CacheObject val = cctx.fromOffheap(valPtr, false);
+                                CacheObject val = cctx.fromOffheap(valPtr(), false);
 
                                 e.value(val);
                             }
                         }
                         else // Read from swap.
-                            valPtr = 0;
+                            setValPtr(0);
                     }
                 }
                 else
@@ -468,7 +465,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
                         // Must update valPtr again since update() will reset it.
                         if (cctx.offheapTiered() && e.offheapPointer() > 0)
-                            valPtr = e.offheapPointer();
+                            setValPtr(e.offheapPointer());
 
                         return val;
                     }
@@ -495,13 +492,13 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
                 if (cctx.offheapTiered()) {
                     cctx.swap().removeOffheap(key);
 
-                    valPtr = 0;
+                    setValPtr(0);
                 }
 
                 return;
             }
 
-            if (val == null && cctx.offheapTiered() && valPtr != 0) {
+            if (val == null && cctx.offheapTiered() && hasValPtr()) {
                 if (log.isDebugEnabled())
                     log.debug("Value did not change, skip write swap entry: " + this);
 
@@ -540,10 +537,10 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
     protected IgniteBiTuple<byte[], Byte> valueBytes0() {
         assert Thread.holdsLock(this);
 
-        if (valPtr != 0) {
+        if (hasValPtr()) {
             assert isOffHeapValuesOnly() || cctx.offheapTiered();
 
-            return cctx.unsafeMemory().get(valPtr);
+            return cctx.unsafeMemory().get(valPtr());
         }
         else {
             assert val != null;
@@ -672,7 +669,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
             CacheObject val = this.val;
 
-            hasOldBytes = valPtr != 0;
+            hasOldBytes = hasValPtr();
 
             if ((unmarshal || isOffHeapValuesOnly()) && !expired && val ==
null && hasOldBytes)
                 val = rawGetOrUnmarshalUnlocked(tmp);
@@ -816,7 +813,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                         // Update indexes before actual write to entry.
                         updateIndex(ret, expTime, nextVer, prevVal);
 
-                    boolean hadValPtr = valPtr != 0;
+                    boolean hadValPtr = hasValPtr();
 
                     // Don't change version for read-through.
                     update(ret, expTime, ttl, nextVer);
@@ -1164,7 +1161,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
             // can be updated without actually holding entry lock.
             clearIndex(old);
 
-            boolean hadValPtr = valPtr != 0;
+            boolean hadValPtr = hasValPtr();
 
             update(null, 0, 0, newVer);
 
@@ -1521,7 +1518,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
                     // Must persist inside synchronization in non-tx mode.
                     cctx.store().remove(null, keyValue(false));
 
-                boolean hasValPtr = valPtr != 0;
+                boolean hasValPtr = hasValPtr();
 
                 // Update index inside synchronization since it can be updated
                 // in load methods without actually holding entry lock.
@@ -2122,7 +2119,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
 
                 enqueueVer = newVer;
 
-                boolean hasValPtr = valPtr != 0;
+                boolean hasValPtr = hasValPtr();
 
                 // Clear value on backup. Entry will be removed from cache when it got evicted
from queue.
                 update(null, CU.TTL_ETERNAL, CU.EXPIRE_TIME_ETERNAL, newVer);
@@ -2929,8 +2926,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
         if (val != null)
             return val;
 
-        if (valPtr != 0) {
-            CacheObject val0 = cctx.fromOffheap(valPtr, tmp);
+        if (hasValPtr()) {
+            CacheObject val0 = cctx.fromOffheap(valPtr(), tmp);
 
             if (!tmp && cctx.kernalContext().config().isPeerClassLoadingEnabled())
                 val0.finishUnmarshal(cctx.cacheObjectContext(), cctx.deploy().globalLoader());
@@ -2952,7 +2949,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
     protected boolean hasValueUnlocked() {
         assert Thread.holdsLock(this);
 
-        return val != null || valPtr != 0;
+        return val != null || hasValPtr();
     }
 
     /** {@inheritDoc} */
@@ -3298,7 +3295,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
             synchronized (this) {
                 CacheObject expiredVal = saveValueForIndexUnlocked();
 
-                boolean hasOldBytes = valPtr != 0;
+                boolean hasOldBytes = hasValPtr();
 
                 boolean expired = checkExpired();
 
@@ -4102,6 +4099,27 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx
{
     }
 
     /**
+     * @return True if entry has off-heap value pointer.
+     */
+    protected boolean hasValPtr() {
+        return false;
+    }
+
+    /**
+     * @return Off-heap value pointer.
+     */
+    protected long valPtr() {
+        return 0;
+    }
+
+    /**
+     * @param valPtr Off-heap value pointer.
+     */
+    protected void setValPtr(long valPtr) {
+        // No-op.
+    }
+
+    /**
      * @return Size of extras object.
      */
     private int extrasSize() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d484af76/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedOffHeapCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedOffHeapCacheEntry.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedOffHeapCacheEntry.java
new file mode 100644
index 0000000..290d97c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedOffHeapCacheEntry.java
@@ -0,0 +1,38 @@
+package org.apache.ignite.internal.processors.cache.distributed;
+
+import org.apache.ignite.internal.processors.cache.*;
+
+/**
+ * Entry for distributed (replicated/partitioned) cache in off-heap tiered/off-heap values
memory mode.
+ */
+public class GridDistributedOffHeapCacheEntry extends GridDistributedCacheEntry {
+    /** Off-heap value pointer. */
+    protected long valPtr;
+
+    /**
+     * @param ctx   Cache context.
+     * @param key   Cache key.
+     * @param hash  Key hash value.
+     * @param val   Entry value.
+     * @param next  Next entry in the linked list.
+     * @param hdrId Cache map header ID.
+     */
+    public GridDistributedOffHeapCacheEntry(GridCacheContext ctx, KeyCacheObject key, int
hash, CacheObject val, GridCacheMapEntry next, int hdrId) {
+        super(ctx, key, hash, val, next, hdrId);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasValPtr() {
+        return valPtr != 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long valPtr() {
+        return valPtr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void setValPtr(long valPtr) {
+        this.valPtr = valPtr;
+    }
+}


Mime
View raw message