Repository: incubator-mnemonic
Updated Branches:
  refs/heads/master fe9b53852 -> cda2b43ee


MNEMONIC-327: Provide a feature set for durable memory services


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

Branch: refs/heads/master
Commit: cda2b43ee864daafc3f4c991e8037582bc9d73e7
Parents: fe9b538
Author: Wang, Gang(Gary) <gang1.w...@intel.com>
Authored: Tue Aug 8 10:23:49 2017 -0700
Committer: Wang, Gang(Gary) <gang1.w...@intel.com>
Committed: Tue Aug 8 10:23:49 2017 -0700

----------------------------------------------------------------------
 .../mnemonic/NonVolatileMemAllocator.java       |  7 +++-
 .../apache/mnemonic/VolatileMemAllocator.java   |  8 +++--
 .../memoryservice/MemoryServiceFeature.java     | 36 ++++++++++++++++++++
 .../VolatileMemoryAllocatorService.java         |  8 +++++
 .../internal/JavaVMemServiceImpl.java           | 10 ++++++
 .../memoryservice/internal/PMemServiceImpl.java | 11 ++++++
 .../memoryservice/internal/VMemServiceImpl.java | 10 ++++++
 .../internal/PMallocServiceImpl.java            | 11 ++++++
 .../internal/SysVMemServiceImpl.java            | 10 ++++++
 9 files changed, 108 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/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 99c4198..81ecfa1 100644
--- 
a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
+++ 
b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
@@ -17,11 +17,13 @@
 
 package org.apache.mnemonic;
 
-import java.nio.ByteBuffer;
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
 import org.flowcomputing.commons.resgc.ResCollector;
 import org.flowcomputing.commons.resgc.ResReclaim;
 
+import java.nio.ByteBuffer;
+
 /**
  * manage a big native persistent memory pool through libpmalloc.so provided by
  * pmalloc project.
@@ -60,6 +62,9 @@ public class NonVolatileMemAllocator extends 
RestorableAllocator<NonVolatileMemA
     if (null == nvmasvc) {
       throw new IllegalArgumentException("NonVolatileMemoryAllocatorService 
object is null");
     }
+    if (!nvmasvc.getFeatures().contains(MemoryServiceFeature.NONVOLATILE)) {
+      throw new ConfigurationException("The specified memory service does not 
support non-volatile feature");
+    }
     if (isnew && capacity <= 0) {
       throw new IllegalArgumentException("NonVolatileMemAllocator cannot be 
initialized with capacity <= 0.");
     }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/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 51282b1..e4eaffa 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
@@ -17,12 +17,13 @@
 
 package org.apache.mnemonic;
 
-import java.nio.ByteBuffer;
-
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
 import org.flowcomputing.commons.resgc.ResCollector;
 import org.flowcomputing.commons.resgc.ResReclaim;
 
+import java.nio.ByteBuffer;
+
 /**
  * manage a big native memory pool through libvmem.so that is provied by Intel
  * nvml library.
@@ -57,6 +58,9 @@ public class VolatileMemAllocator extends 
RestorableAllocator<VolatileMemAllocat
     if (null == vmasvc) {
       throw new IllegalArgumentException("VolatileMemoryAllocatorService 
object is null");
     }
+    if (!vmasvc.getFeatures().contains(MemoryServiceFeature.VOLATILE)) {
+      throw new ConfigurationException("The specified memory service does not 
support volatile feature");
+    }
     if (capacity <= 0) {
       throw new IllegalArgumentException("VolatileMemAllocator cannot be 
initialized with capacity <= 0.");
     }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/MemoryServiceFeature.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/MemoryServiceFeature.java
 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/MemoryServiceFeature.java
new file mode 100644
index 0000000..80be41c
--- /dev/null
+++ 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/MemoryServiceFeature.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.mnemonic.service.memoryservice;
+
+public enum MemoryServiceFeature {
+
+  VOLATILE(1),
+  NONVOLATILE(2),
+  TRANSACTABLE(3),
+  QUERYABLE(4);
+
+  private int value;
+
+  MemoryServiceFeature(int val) {
+    this.value = val;
+  }
+
+  public int getValue() {
+    return value;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
index c758e3e..fc11cd2 100644
--- 
a/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
+++ 
b/mnemonic-core/src/main/java/org/apache/mnemonic/service/memoryservice/VolatileMemoryAllocatorService.java
@@ -18,6 +18,7 @@
 package org.apache.mnemonic.service.memoryservice;
 
 import java.nio.ByteBuffer;
+import java.util.Set;
 
 public interface VolatileMemoryAllocatorService {
 
@@ -297,4 +298,11 @@ public interface VolatileMemoryAllocatorService {
    */
   boolean isInTransaction();
 
+  /**
+   * provide a set of features that the memory service can offer
+   *
+   * @return a set of features that supported by this memory service
+   */
+  Set<MemoryServiceFeature> getFeatures();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-memory-services/mnemonic-java-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/JavaVMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-java-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/JavaVMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-java-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/JavaVMemServiceImpl.java
index cb34c06..3a402eb 100644
--- 
a/mnemonic-memory-services/mnemonic-java-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/JavaVMemServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-java-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/JavaVMemServiceImpl.java
@@ -18,6 +18,7 @@
 package org.apache.mnemonic.service.memoryservice.internal;
 
 import org.apache.mnemonic.ConfigurationException;
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
 
 import java.io.File;
@@ -29,6 +30,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 public class JavaVMemServiceImpl implements VolatileMemoryAllocatorService {
 
@@ -219,6 +222,13 @@ public class JavaVMemServiceImpl implements 
VolatileMemoryAllocatorService {
     throw new UnsupportedOperationException("Not support transaction");
   }
 
+  @Override
+  public Set<MemoryServiceFeature> getFeatures() {
+    Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+    ret.add(MemoryServiceFeature.VOLATILE);
+    return ret;
+  }
+
   public Map<Long, Long> getMInfo() {
     return this.m_info;
   }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
index d14e133..0e0b7a5 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-nvml-pmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMemServiceImpl.java
@@ -17,10 +17,13 @@
 
 package org.apache.mnemonic.service.memoryservice.internal;
 
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
 import org.flowcomputing.commons.primitives.NativeLibraryLoader;
 
 import java.nio.ByteBuffer;
+import java.util.HashSet;
+import java.util.Set;
 
 public class PMemServiceImpl implements NonVolatileMemoryAllocatorService {
   static {
@@ -161,6 +164,14 @@ public class PMemServiceImpl implements 
NonVolatileMemoryAllocatorService {
     throw new UnsupportedOperationException("Not support transaction");
   }
 
+  @Override
+  public Set<MemoryServiceFeature> getFeatures() {
+    Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+    ret.add(MemoryServiceFeature.VOLATILE);
+    ret.add(MemoryServiceFeature.NONVOLATILE);
+    return ret;
+  }
+
   protected native long ninit(long capacity, String uri, boolean isnew);
 
   protected native void nclose(long id);

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
index 3656c8f..00a2a39 100644
--- 
a/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-nvml-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/VMemServiceImpl.java
@@ -17,6 +17,7 @@
 
 package org.apache.mnemonic.service.memoryservice.internal;
 
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
 import org.flowcomputing.commons.primitives.NativeLibraryLoader;
 
@@ -24,6 +25,8 @@ import java.nio.ByteBuffer;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 public class VMemServiceImpl implements VolatileMemoryAllocatorService {
   static {
@@ -154,6 +157,13 @@ public class VMemServiceImpl implements 
VolatileMemoryAllocatorService {
     throw new UnsupportedOperationException("Not support transaction");
   }
 
+  @Override
+  public Set<MemoryServiceFeature> getFeatures() {
+    Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+    ret.add(MemoryServiceFeature.VOLATILE);
+    return ret;
+  }
+
   protected native long ninit(long capacity, String uri, boolean isnew);
 
   protected native void nclose(long id);

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
index 618847d..e6faf4b 100644
--- 
a/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-pmalloc-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/PMallocServiceImpl.java
@@ -17,10 +17,13 @@
 
 package org.apache.mnemonic.service.memoryservice.internal;
 
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
 import org.flowcomputing.commons.primitives.NativeLibraryLoader;
 
 import java.nio.ByteBuffer;
+import java.util.HashSet;
+import java.util.Set;
 
 public class PMallocServiceImpl implements NonVolatileMemoryAllocatorService {
   static {
@@ -161,6 +164,14 @@ public class PMallocServiceImpl implements 
NonVolatileMemoryAllocatorService {
     throw new UnsupportedOperationException("Not support transaction");
   }
 
+  @Override
+  public Set<MemoryServiceFeature> getFeatures() {
+    Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+    ret.add(MemoryServiceFeature.VOLATILE);
+    ret.add(MemoryServiceFeature.NONVOLATILE);
+    return ret;
+  }
+
   protected native long ninit(long capacity, String uri, boolean isnew);
 
   protected native void nclose(long id);

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/cda2b43e/mnemonic-memory-services/mnemonic-sys-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/SysVMemServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/mnemonic-memory-services/mnemonic-sys-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/SysVMemServiceImpl.java
 
b/mnemonic-memory-services/mnemonic-sys-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/SysVMemServiceImpl.java
index 26e1bba..628897d 100644
--- 
a/mnemonic-memory-services/mnemonic-sys-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/SysVMemServiceImpl.java
+++ 
b/mnemonic-memory-services/mnemonic-sys-vmem-service/src/main/java/org/apache/mnemonic/service/memoryservice/internal/SysVMemServiceImpl.java
@@ -17,6 +17,7 @@
 
 package org.apache.mnemonic.service.memoryservice.internal;
 
+import org.apache.mnemonic.service.memoryservice.MemoryServiceFeature;
 import 
org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
 import org.flowcomputing.commons.primitives.NativeLibraryLoader;
 
@@ -24,6 +25,8 @@ import java.nio.ByteBuffer;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 public class SysVMemServiceImpl implements VolatileMemoryAllocatorService {
   static {
@@ -154,6 +157,13 @@ public class SysVMemServiceImpl implements 
VolatileMemoryAllocatorService {
     throw new UnsupportedOperationException("Not support transaction");
   }
 
+  @Override
+  public Set<MemoryServiceFeature> getFeatures() {
+    Set<MemoryServiceFeature> ret = new HashSet<MemoryServiceFeature>();
+    ret.add(MemoryServiceFeature.VOLATILE);
+    return ret;
+  }
+
   protected native long ninit(long capacity, String uri, boolean isnew);
 
   protected native void nclose(long id);

Reply via email to