mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject incubator-mnemonic git commit: MNEMONIC-376: Support shrinkable durable memory service
Date Tue, 10 Oct 2017 05:30:59 GMT
Repository: incubator-mnemonic
Updated Branches:
  refs/heads/master 70a9c0f46 -> 67f074a20


MNEMONIC-376: Support shrinkable durable memory service


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

Branch: refs/heads/master
Commit: 67f074a20b0452cfde71572d7377687f750fc34a
Parents: 70a9c0f
Author: paleyss <paleyitsky@gmail.com>
Authored: Sat Oct 7 22:48:36 2017 -0700
Committer: paleyss <paleyitsky@gmail.com>
Committed: Mon Oct 9 21:34:59 2017 -0700

----------------------------------------------------------------------
 .../org/apache/mnemonic/CommonAllocator.java    | 10 +++++++++
 .../mnemonic/NonVolatileMemAllocator.java       | 22 ++++++++++++++++++--
 .../org/apache/mnemonic/SysMemAllocator.java    | 22 ++++++++++++++++++--
 .../apache/mnemonic/VolatileMemAllocator.java   | 22 ++++++++++++++++++--
 .../service/memory/MemoryServiceFeature.java    |  3 ++-
 5 files changed, 72 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/67f074a2/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
index 5325d86..1e0cdf5 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
@@ -55,6 +55,16 @@ public abstract class CommonAllocator<A extends CommonAllocator<A>>
implements A
   public abstract long expand(long size);
 
   /**
+   * shrink this memory pool
+   *
+   * @param size
+   *          specify the size to shrink
+   *
+   * @return the real size shrinked
+   */
+  public abstract long shrink(long size);
+
+  /**
    * set a reclaimer to reclaim memory buffer
    * 
    * @param reclaimer

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/67f074a2/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
index 8d8f7bc..4058139 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
@@ -31,6 +31,7 @@ import java.nio.ByteBuffer;
 
 import static org.apache.mnemonic.service.memory.MemoryServiceFeature.EXPANDABLE;
 import static org.apache.mnemonic.service.memory.MemoryServiceFeature.QUERYABLE;
+import static org.apache.mnemonic.service.memory.MemoryServiceFeature.SHRINKABLE;
 
 /**
  * manage a big native persistent memory pool through underlying memory service.
@@ -728,10 +729,27 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
     long ret = 0L;
     if (null != m_features) {
       if (m_features.contains(EXPANDABLE)) {
-        return m_nvmasvc.adjustCapacity(m_nid, size);
+        ret = m_nvmasvc.adjustCapacity(m_nid, size);
+      } else {
+        throw new ConfigurationException("Do not support expand operation");
       }
     } else {
-      throw new ConfigurationException("Do not support expand operation");
+      throw new ConfigurationException("Do not support features");
+    }
+    return ret;
+  }
+
+  @Override
+  public long shrink(long size) {
+    long ret = 0L;
+    if (null != m_features) {
+      if (m_features.contains(SHRINKABLE)) {
+        ret = m_nvmasvc.adjustCapacity(m_nid, (-1) * size);
+      } else {
+        throw new ConfigurationException("Do not support shrink operation");
+      }
+    } else {
+      throw new ConfigurationException("Do not support features");
     }
     return ret;
   }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/67f074a2/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
index 827b704..37f06a2 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
 import static org.apache.mnemonic.service.memory.MemoryServiceFeature.EXPANDABLE;
+import static org.apache.mnemonic.service.memory.MemoryServiceFeature.SHRINKABLE;
 
 /**
  * manage a system memory pool as a internal volatile allocator
@@ -352,10 +353,27 @@ public class SysMemAllocator extends CommonAllocator<SysMemAllocator>
{
     long ret = 0L;
     if (null != m_features) {
       if (m_features.contains(EXPANDABLE)) {
-        return ret = size;
+        ret = size;
+      } else {
+        throw new ConfigurationException("Do not support expand operation");
       }
     } else {
-      throw new ConfigurationException("Do not support expand operation");
+      throw new ConfigurationException("Do not support features");
+    }
+    return ret;
+  }
+
+  @Override
+  public long shrink(long size) {
+    long ret = 0L;
+    if (null != m_features) {
+      if (m_features.contains(SHRINKABLE)) {
+        ret = size;
+      } else {
+        throw new ConfigurationException("Do not support shrink operation");
+      }
+    } else {
+      throw new ConfigurationException("Do not support features");
     }
     return ret;
   }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/67f074a2/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
index b54dfad..1392a22 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
@@ -31,6 +31,7 @@ import java.nio.ByteBuffer;
 
 import static org.apache.mnemonic.service.memory.MemoryServiceFeature.EXPANDABLE;
 import static org.apache.mnemonic.service.memory.MemoryServiceFeature.QUERYABLE;
+import static org.apache.mnemonic.service.memory.MemoryServiceFeature.SHRINKABLE;
 
 /**
  * manage a big native memory pool through underlying memory service.
@@ -150,10 +151,27 @@ public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocat
     long ret = 0L;
     if (null != m_features) {
       if (m_features.contains(EXPANDABLE)) {
-        return m_vmasvc.adjustCapacity(m_nid, size);
+        ret = m_vmasvc.adjustCapacity(m_nid, size);
+      } else {
+        throw new ConfigurationException("Do not support expand operation");
       }
     } else {
-      throw new ConfigurationException("Do not support expand operation");
+      throw new ConfigurationException("Do not support features");
+    }
+    return ret;
+  }
+
+  @Override
+  public long shrink(long size) {
+    long ret = 0L;
+    if (null != m_features) {
+      if (m_features.contains(SHRINKABLE)) {
+        ret = m_vmasvc.adjustCapacity(m_nid, (-1) * size);
+      } else {
+        throw new ConfigurationException("Do not support shrink operation");
+      }
+    } else {
+      throw new ConfigurationException("Do not support features");
     }
     return ret;
   }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/67f074a2/mnemonic-core/src/main/java/org/apache/mnemonic/service/memory/MemoryServiceFeature.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memory/MemoryServiceFeature.java
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memory/MemoryServiceFeature.java
index 3a6073f..ee607c0 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memory/MemoryServiceFeature.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memory/MemoryServiceFeature.java
@@ -23,7 +23,8 @@ public enum MemoryServiceFeature {
   TRANSACTABLE(3),
   QUERYABLE(4),
   ABSTRACTADDRESSING(5),
-  EXPANDABLE(6);
+  EXPANDABLE(6),
+  SHRINKABLE(7);
 
   private int value;
 


Mime
View raw message