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-270: Durable object wise persistence feature
Date Fri, 19 May 2017 18:54:50 GMT
Repository: incubator-mnemonic
Updated Branches:
  refs/heads/master c3f487b54 -> 13eeb4983


MNEMONIC-270: Durable object wise persistence feature


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

Branch: refs/heads/master
Commit: 13eeb4983f39648b00d1b5e52aaf3cfb2d9d83aa
Parents: c3f487b
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Fri May 19 11:35:56 2017 -0700
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Fri May 19 11:35:56 2017 -0700

----------------------------------------------------------------------
 .../mnemonic/collections/DurableArrayImpl.java  |  24 +++
 .../collections/DurableHashMapImpl.java         |  24 +++
 .../collections/DurableHashSetImpl.java         |  24 +++
 .../mnemonic/collections/DurableTreeImpl.java   |  24 +++
 .../java/org/apache/mnemonic/Allocator.java     |  22 ++-
 .../mnemonic/AnnotatedDurableEntityClass.java   |  16 +-
 .../main/java/org/apache/mnemonic/Durable.java  |  15 ++
 .../java/org/apache/mnemonic/DurableBuffer.java |  32 ++++
 .../java/org/apache/mnemonic/DurableChunk.java  |  32 ++++
 .../java/org/apache/mnemonic/GenericField.java  | 171 ++++++++++++++++++-
 .../mnemonic/NonVolatileMemAllocator.java       |  50 +++++-
 .../java/org/apache/mnemonic/Persistence.java   | 101 +++++++++++
 .../org/apache/mnemonic/SysMemAllocator.java    |  34 +++-
 .../apache/mnemonic/VolatileMemAllocator.java   |  17 +-
 14 files changed, 563 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
index 3654f9c..d0c01b3 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
@@ -134,6 +134,30 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>,
E>
     return autoReclaim;
   }
 
+  /**
+   * sync. this object
+   */
+  @Override
+  public void sync() {
+
+  }
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  @Override
+  public void persist() {
+
+  }
+
+  /**
+   * flush processors cache for this object
+   */
+  @Override
+  public void flush() {
+
+  }
+
   @Override
   public long[][] getNativeFieldInfo() {
     return fieldInfo;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
index 0df8c39..cb17c3c 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
@@ -372,6 +372,30 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>,
K, V>
     return autoReclaim;
   }
 
+  /**
+   * sync. this object
+   */
+  @Override
+  public void sync() {
+
+  }
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  @Override
+  public void persist() {
+
+  }
+
+  /**
+   * flush processors cache for this object
+   */
+  @Override
+  public void flush() {
+
+  }
+
   @Override
   public long[][] getNativeFieldInfo() {
     return fieldInfo;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
index 372cf49..032480b 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
@@ -85,6 +85,30 @@ public class DurableHashSetImpl<A extends RestorableAllocator<A>,
E>
     return autoReclaim;
   }
 
+  /**
+   * sync. this object
+   */
+  @Override
+  public void sync() {
+
+  }
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  @Override
+  public void persist() {
+
+  }
+
+  /**
+   * flush processors cache for this object
+   */
+  @Override
+  public void flush() {
+
+  }
+
   @Override
   public long[][] getNativeFieldInfo() {
     return fieldInfo;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
index f57ef00..e3a3108 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
@@ -372,6 +372,30 @@ public class DurableTreeImpl<A extends RestorableAllocator<A>,
E extends Compara
     return autoReclaim;
   }
 
+  /**
+   * sync. this object
+   */
+  @Override
+  public void sync() {
+
+  }
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  @Override
+  public void persist() {
+
+  }
+
+  /**
+   * flush processors cache for this object
+   */
+  @Override
+  public void flush() {
+
+  }
+
   @Override
   public long[][] getNativeFieldInfo() {
     return fieldInfo;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/Allocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Allocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Allocator.java
index 28a1119..b6505b6 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/Allocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Allocator.java
@@ -30,10 +30,28 @@ public interface Allocator<A extends CommonAllocator<A>> extends
Allocatable<A>
   void close();
 
   /**
-   * sync. dirty data to underlying memory-like device
+   * sync. dirty data to memory
    *
    */
-  void sync();
+  void sync(long addr, long length, boolean autodetect);
+
+  /**
+   * sync. a buffer to memory.
+   *
+   * @param mbuf
+   *         specify a buffer to be sync.
+   */
+  void sync(MemBufferHolder<A> mbuf);
+
+  /**
+   * sync. a chunk to memory.
+   *
+   * @param mchunk
+   *         specify a chunk to be sync.
+   */
+  void sync(MemChunkHolder<A> mchunk);
+
+  void syncAll();
 
   /**
    * enable active garbage collection. the GC will be forced to collect garbages

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
b/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
index 7158a5c..4f13687 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
@@ -105,7 +105,7 @@ public class AnnotatedDurableEntityClass {
   private TypeName m_factoryproxystypename = TypeName.get(EntityFactoryProxy[].class);
   private TypeName m_gfieldstypename = TypeName.get(DurableType[].class);
   private TypeVariableName m_alloctypevarname = TypeVariableName.get(cALLOCTYPENAME,
-      ParameterizedTypeName.get(ClassName.get(RestorableAllocator.class), TypeVariableName.get(cALLOCTYPENAME)));
+      ParameterizedTypeName.get(ClassName.get(RestorableAllocator.class), m_alloctypename));
 
   private Map<String, MethodInfo> m_gettersinfo = new HashMap<String, MethodInfo>();
   private Map<String, MethodInfo> m_settersinfo = new HashMap<String, MethodInfo>();
@@ -186,6 +186,9 @@ public class AnnotatedDurableEntityClass {
     m_durablemtdinfo.put("getHandler", new MethodInfo());
     m_durablemtdinfo.put("autoReclaim", new MethodInfo());
     m_durablemtdinfo.put("destroy", new MethodInfo());
+    m_durablemtdinfo.put("sync", new MethodInfo());
+    m_durablemtdinfo.put("persist", new MethodInfo());
+    m_durablemtdinfo.put("flush", new MethodInfo());
     m_durablemtdinfo.put("getNativeFieldInfo", new MethodInfo());
 
     m_entitymtdinfo.put("initializeDurableEntity", new MethodInfo());
@@ -223,7 +226,7 @@ public class AnnotatedDurableEntityClass {
 
     fieldinfo = new FieldInfo();
     fieldinfo.name = String.format("m_holder_%s", Utils.genRandomString());
-    fieldinfo.type = ParameterizedTypeName.get(ClassName.get(MemChunkHolder.class), m_alloctypename);
+    fieldinfo.type = ParameterizedTypeName.get(ClassName.get(DurableChunk.class), m_alloctypename);
     fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
     m_fieldsinfo.put("holder", fieldinfo);
 
@@ -749,6 +752,15 @@ public class AnnotatedDurableEntityClass {
       case "autoReclaim":
         code.addStatement("return $1N", autoreclaimname);
         break;
+      case "sync":
+        code.addStatement("$1N.sync()", holdername);
+        break;
+      case "persist":
+        code.addStatement("$1N.persist()", holdername);
+        break;
+      case "flush":
+        code.addStatement("$1N.flush()", holdername);
+        break;
       case "destroy":
         for (String fname : m_dynfieldsinfo.keySet()) {
           dynfieldinfo = m_dynfieldsinfo.get(fname);

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/Durable.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Durable.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Durable.java
index a38e7f3..8120c62 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/Durable.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Durable.java
@@ -81,6 +81,21 @@ public interface Durable {
   boolean autoReclaim();
 
   /**
+   * sync. this object
+   */
+  void sync();
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  void persist();
+
+  /**
+   * flush processors cache for this object
+   */
+  void flush();
+
+  /**
    * manually destroy this object and release its memory resource
    *
    */

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/DurableBuffer.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/DurableBuffer.java b/mnemonic-core/src/main/java/org/apache/mnemonic/DurableBuffer.java
index 2694dd1..870e7cb 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/DurableBuffer.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/DurableBuffer.java
@@ -20,9 +20,13 @@ package org.apache.mnemonic;
 import java.nio.ByteBuffer;
 
 public class DurableBuffer<A extends RetrievableAllocator<A>> extends MemBufferHolder<A>
implements Durable {
+  protected Persistence<A> m_persistOps = null;
 
   public DurableBuffer(A ar, ByteBuffer mres) {
     super(ar, mres);
+    if (ar instanceof Persistence) {
+      m_persistOps = (Persistence<A>) ar;
+    }
   }
 
   @Override
@@ -42,6 +46,34 @@ public class DurableBuffer<A extends RetrievableAllocator<A>>
extends MemBufferH
     return m_allocator.getBufferHandler(this);
   }
 
+  /**
+   * sync. this object
+   */
+  @Override
+  public void sync() {
+    m_allocator.sync(this);
+  }
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  @Override
+  public void persist() {
+    if (null != m_persistOps) {
+      m_persistOps.persist(this);
+    }
+  }
+
+  /**
+   * flush processors cache for this object
+   */
+  @Override
+  public void flush() {
+    if (null != m_persistOps) {
+      m_persistOps.flush(this);
+    }
+  }
+
   @Override
   public long[][] getNativeFieldInfo() {
     return null;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/DurableChunk.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/DurableChunk.java b/mnemonic-core/src/main/java/org/apache/mnemonic/DurableChunk.java
index 93d43bf..688137b 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/DurableChunk.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/DurableChunk.java
@@ -18,9 +18,13 @@
 package org.apache.mnemonic;
 
 public class DurableChunk<A extends RetrievableAllocator<A>> extends MemChunkHolder<A>
implements Durable {
+  protected Persistence<A> m_persistOps = null;
 
   public DurableChunk(A ar, Long mres, long size) {
     super(ar, mres, size);
+    if (ar instanceof Persistence) {
+      m_persistOps = (Persistence<A>) ar;
+    }
   }
 
   @Override
@@ -40,6 +44,34 @@ public class DurableChunk<A extends RetrievableAllocator<A>>
extends MemChunkHol
     return m_allocator.getChunkHandler(this);
   }
 
+  /**
+   * sync. this object
+   */
+  @Override
+  public void sync() {
+    m_allocator.sync(this);
+  }
+
+  /**
+   * Make any cached changes to this object persistent.
+   */
+  @Override
+  public void persist() {
+    if (null != m_persistOps) {
+      m_persistOps.persist(this);
+    }
+  }
+
+  /**
+   * flush processors cache for this object
+   */
+  @Override
+  public void flush() {
+    if (null != m_persistOps) {
+      m_persistOps.flush(this);
+    }
+  }
+
   @Override
   public long[][] getNativeFieldInfo() {
     return null;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java b/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
index d8fa254..6c417a5 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
@@ -31,10 +31,11 @@ public class GenericField<A extends RestorableAllocator<A>, E>
implements Durabl
   private long m_fpos;
   private DurableType m_dgftype = null;
   private Durable m_field = null;
-  private MemBufferHolder<A> m_strfield = null;
+  private DurableBuffer<A> m_strfield = null;
   private DurableChunk<A> m_chunkfield = null;
   private DurableBuffer<A> m_bufferfield = null;
   private A m_allocator;
+  private Persistence<A> m_persistOps = null;
   private boolean m_autoreclaim;
   private EntityFactoryProxy m_defproxy = null;
   private EntityFactoryProxy[] m_efproxies;
@@ -79,6 +80,9 @@ public class GenericField<A extends RestorableAllocator<A>, E>
implements Durabl
     m_gftypes = gftypes;
     m_defproxy = defproxy;
     m_dgftype = dgftype;
+    if (m_allocator instanceof Persistence) {
+      m_persistOps = (Persistence<A>) m_allocator;
+    }
   }
 
   /**
@@ -358,6 +362,171 @@ public class GenericField<A extends RestorableAllocator<A>,
E> implements Durabl
   }
 
   /**
+   * sync. this generic field
+   */
+  @Override
+  public void sync() {
+    if (null != m_allocator) {
+      switch (m_dgftype) {
+        case BYTE:
+          m_allocator.sync(m_fpos, Byte.BYTES, false);
+          break;
+        case BOOLEAN:
+          m_allocator.sync(m_fpos, Byte.BYTES, false);
+          break;
+        case CHARACTER:
+          m_allocator.sync(m_fpos, Character.BYTES, false);
+          break;
+        case SHORT:
+          m_allocator.sync(m_fpos, Short.BYTES, false);
+          break;
+        case INTEGER:
+          m_allocator.sync(m_fpos, Integer.BYTES, false);
+          break;
+        case LONG:
+          m_allocator.sync(m_fpos, Long.BYTES, false);
+          break;
+        case FLOAT:
+          m_allocator.sync(m_fpos, Float.BYTES, false);
+          break;
+        case DOUBLE:
+          m_allocator.sync(m_fpos, Double.BYTES, false);
+          break;
+        case STRING:
+          if (null != m_strfield) {
+            m_strfield.sync();
+          }
+          break;
+        case DURABLE:
+          if (null != m_field) {
+            m_field.sync();
+          }
+          break;
+        case CHUNK:
+          if (null != m_chunkfield) {
+            m_chunkfield.sync();
+          }
+          break;
+        case BUFFER:
+          if (null != m_bufferfield) {
+            m_bufferfield.sync();
+          }
+          break;
+      }
+    }
+  }
+
+  /**
+   * Make any cached changes to this generic field persistent.
+   */
+  @Override
+  public void persist() {
+    if (null != m_persistOps) {
+      switch (m_dgftype) {
+        case BYTE:
+          m_persistOps.persist(m_fpos, Byte.BYTES, false);
+          break;
+        case BOOLEAN:
+          m_persistOps.persist(m_fpos, Byte.BYTES, false);
+          break;
+        case CHARACTER:
+          m_persistOps.persist(m_fpos, Character.BYTES, false);
+          break;
+        case SHORT:
+          m_persistOps.persist(m_fpos, Short.BYTES, false);
+          break;
+        case INTEGER:
+          m_persistOps.persist(m_fpos, Integer.BYTES, false);
+          break;
+        case LONG:
+          m_persistOps.persist(m_fpos, Long.BYTES, false);
+          break;
+        case FLOAT:
+          m_persistOps.persist(m_fpos, Float.BYTES, false);
+          break;
+        case DOUBLE:
+          m_persistOps.persist(m_fpos, Double.BYTES, false);
+          break;
+        case STRING:
+          if (null != m_strfield) {
+            m_strfield.persist();
+          }
+          break;
+        case DURABLE:
+          if (null != m_field) {
+            m_field.persist();
+          }
+          break;
+        case CHUNK:
+          if (null != m_chunkfield) {
+            m_chunkfield.persist();
+          }
+          break;
+        case BUFFER:
+          if (null != m_bufferfield) {
+            m_bufferfield.persist();
+          }
+          break;
+      }
+    }
+  }
+
+  /**
+   * flush processors cache for this generic field
+   */
+  @Override
+  public void flush() {
+    if (null != m_persistOps) {
+      switch (m_dgftype) {
+        case BYTE:
+          m_persistOps.flush(m_fpos, Byte.BYTES, false);
+          break;
+        case BOOLEAN:
+          m_persistOps.flush(m_fpos, Byte.BYTES, false);
+          break;
+        case CHARACTER:
+          m_persistOps.flush(m_fpos, Character.BYTES, false);
+          break;
+        case SHORT:
+          m_persistOps.flush(m_fpos, Short.BYTES, false);
+          break;
+        case INTEGER:
+          m_persistOps.flush(m_fpos, Integer.BYTES, false);
+          break;
+        case LONG:
+          m_persistOps.flush(m_fpos, Long.BYTES, false);
+          break;
+        case FLOAT:
+          m_persistOps.flush(m_fpos, Float.BYTES, false);
+          break;
+        case DOUBLE:
+          m_persistOps.flush(m_fpos, Double.BYTES, false);
+          break;
+        case STRING:
+          if (null != m_strfield) {
+            m_strfield.flush();
+          }
+          break;
+        case DURABLE:
+          if (null != m_field) {
+            m_field.flush();
+          }
+          break;
+        case CHUNK:
+          if (null != m_chunkfield) {
+            m_chunkfield.flush();
+          }
+          break;
+        case BUFFER:
+          if (null != m_bufferfield) {
+            m_bufferfield.flush();
+          }
+          break;
+      }
+    }
+  }
+
+  /**
    * {@inheritDoc}
    */
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/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 25d69ba..02dc48b 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
@@ -29,7 +29,7 @@ import org.flowcomputing.commons.resgc.ResReclaim;
  *
  */
 public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemAllocator>
-    implements AddressTranslator {
+    implements AddressTranslator, Persistence<NonVolatileMemAllocator> {
 
   private boolean m_activegc = true;
   private long m_gctimeout = 100;
@@ -145,12 +145,12 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
   }
 
   /**
-   * force to synchronize uncommitted data to backed memory pool (this is a
-   * placeholder).
+   * force to synchronize uncommitted data to memory.
    *
    */
   @Override
-  public void sync() {
+  public void sync(long addr, long length, boolean autodetect) {
+    m_nvmasvc.sync(m_nid, addr, length, autodetect);
   }
 
   /**
@@ -376,20 +376,22 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
 
   /**
    * sync. a buffer to underlying memory device.
-   * 
+   *
    * @param mbuf
    *         specify a buffer to be sync.
    */
+  @Override
   public void sync(MemBufferHolder<NonVolatileMemAllocator> mbuf) {
     m_nvmasvc.sync(m_nid, getBufferAddress(mbuf), 0L, true);
   }
 
   /**
    * sync. a chunk to underlying memory device.
-   * 
+   *
    * @param mchunk
    *         specify a chunk to be sync.
    */
+  @Override
   public void sync(MemChunkHolder<NonVolatileMemAllocator> mchunk) {
     m_nvmasvc.sync(m_nid, getChunkAddress(mchunk), 0L, true);
   }
@@ -397,26 +399,53 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
   /**
    * sync. the memory pool to underlying memory device.
    */
+  @Override
   public void syncAll() {
     m_nvmasvc.sync(m_nid, 0L, 0L, true);
   }
 
   /**
+   * Make any cached changes to a memory resource persistent.
+   *
+   * @param addr       the address of a memory resource
+   * @param length     the length of the memory resource
+   * @param autodetect if NULL == address and autodetect : persist whole pool
+   */
+  @Override
+  public void persist(long addr, long length, boolean autodetect) {
+    m_nvmasvc.persist(m_nid, addr, length, autodetect);
+  }
+
+  /**
+   * flush processors cache for a memory resource
+   *
+   * @param addr       the address of a memory resource
+   * @param length     the length of the memory resource
+   * @param autodetect if NULL == address and autodetect : flush whole pool
+   */
+  @Override
+  public void flush(long addr, long length, boolean autodetect) {
+    m_nvmasvc.flush(m_nid, addr, length, autodetect);
+  }
+
+  /**
    * persist a buffer to persistent memory.
-   * 
+   *
    * @param mbuf
    *         specify a buffer to be persisted
    */
+  @Override
   public void persist(MemBufferHolder<NonVolatileMemAllocator> mbuf) {
     m_nvmasvc.persist(m_nid, getBufferAddress(mbuf), 0L, true);
   }
 
   /**
    * persist a chunk to persistent memory.
-   * 
+   *
    * @param mchunk
    *         specify a chunk to be persisted
    */
+  @Override
   public void persist(MemChunkHolder<NonVolatileMemAllocator> mchunk) {
     m_nvmasvc.persist(m_nid, getChunkAddress(mchunk), 0L, true);
   }
@@ -424,6 +453,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
   /**
    * persist the memory pool to persistent memory.
    */
+  @Override
   public void persistAll() {
     m_nvmasvc.persist(m_nid, 0L, 0L, true);
   }
@@ -434,6 +464,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
    * @param mbuf
    *         specify a buffer to be flushed
    */
+  @Override
   public void flush(MemBufferHolder<NonVolatileMemAllocator> mbuf) {
     m_nvmasvc.flush(m_nid, getBufferAddress(mbuf), 0L, true);
   }
@@ -444,6 +475,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
    * @param mchunk
    *         specify a chunk to be flushed
    */
+  @Override
   public void flush(MemChunkHolder<NonVolatileMemAllocator> mchunk) {
     m_nvmasvc.flush(m_nid, getChunkAddress(mchunk), 0L, true);
   }
@@ -451,6 +483,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
   /**
    * flush the memory pool to persistent memory.
    */
+  @Override
   public void flushAll() {
     m_nvmasvc.flush(m_nid, 0L, 0L, true);
   }
@@ -458,6 +491,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
   /**
    * drain memory caches to persistent memory.
    */
+  @Override
   public void drain() {
     m_nvmasvc.drain(m_nid);
   }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/mnemonic-core/src/main/java/org/apache/mnemonic/Persistence.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Persistence.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Persistence.java
new file mode 100644
index 0000000..cc8af68
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Persistence.java
@@ -0,0 +1,101 @@
+/*
+ * 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;
+
+/**
+ * Provide persist operations
+ */
+public interface Persistence<A extends RetrievableAllocator<A>> {
+
+    /**
+     * Make any cached changes to a memory resource persistent.
+     *
+     * @param addr
+     *          the address of a memory resource
+     *
+     * @param length
+     *          the length of the memory resource
+     *
+     * @param autodetect
+     *          if NULL == address and autodetect : persist whole pool
+     *          if 0L == length and autodetect : persist block
+     */
+    void persist(long addr, long length, boolean autodetect);
+
+    /**
+     * flush processors cache for a memory resource
+     *
+     * @param addr
+     *          the address of a memory resource
+     *
+     * @param length
+     *          the length of the memory resource
+     *
+     * @param autodetect
+     *          if NULL == address and autodetect : flush whole pool
+     *          if 0L == length and autodetect : flush block
+     */
+    void flush(long addr, long length, boolean autodetect);
+
+    /**
+     * persist a buffer to persistent memory.
+     *
+     * @param mbuf
+     *         specify a buffer to be persisted
+     */
+    void persist(MemBufferHolder<A> mbuf);
+
+    /**
+     * persist a chunk to persistent memory.
+     *
+     * @param mchunk
+     *         specify a chunk to be persisted
+     */
+    void persist(MemChunkHolder<A> mchunk);
+
+    /**
+     * persist the memory pool to persistent memory.
+     */
+    void persistAll();
+
+    /**
+     * flush a buffer to persistent memory.
+     *
+     * @param mbuf
+     *         specify a buffer to be flushed
+     */
+    void flush(MemBufferHolder<A> mbuf);
+
+    /**
+     * flush a chunk to persistent memory.
+     *
+     * @param mchunk
+     *         specify a chunk to be flushed
+     */
+    void flush(MemChunkHolder<A> mchunk);
+
+    /**
+     * flush the memory pool to persistent memory.
+     */
+    void flushAll();
+
+    /**
+     * drain memory caches to persistent memory.
+     */
+    void drain();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/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 1d68937..71c6211 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
@@ -149,12 +149,40 @@ public class SysMemAllocator extends CommonAllocator<SysMemAllocator>
{
   }
 
   /**
-   * force to synchronize uncommitted data to backed memory pool (this is a
-   * placeholder).
+   * sync. dirty data to memory
    *
+   * @param addr
+   * @param length
+   * @param autodetect
    */
   @Override
-  public void sync() {
+  public void sync(long addr, long length, boolean autodetect) {
+    throw new UnsupportedOperationException("SysMemAllocator doesn't support sync");
+  }
+
+  /**
+   * sync. a buffer to memory.
+   *
+   * @param mbuf specify a buffer to be sync.
+   */
+  @Override
+  public void sync(MemBufferHolder<SysMemAllocator> mbuf) {
+    throw new UnsupportedOperationException("SysMemAllocator doesn't support sync");
+  }
+
+  /**
+   * sync. a chunk to memory.
+   *
+   * @param mchunk specify a chunk to be sync.
+   */
+  @Override
+  public void sync(MemChunkHolder<SysMemAllocator> mchunk) {
+    throw new UnsupportedOperationException("SysMemAllocator doesn't support sync");
+  }
+
+  @Override
+  public void syncAll() {
+    throw new UnsupportedOperationException("SysMemAllocator doesn't support sync");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/13eeb498/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 a94b751..517b496 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/VolatileMemAllocator.java
@@ -141,12 +141,12 @@ public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocat
   }
 
   /**
-   * force to synchronize uncommitted data to backed memory pool (this is a
-   * placeholder).
+   * force to synchronize uncommitted data to memory.
    *
    */
   @Override
-  public void sync() {
+  public void sync(long addr, long length, boolean autodetect) {
+    m_vmasvc.sync(m_nid, addr, length, autodetect);
   }
 
   /**
@@ -367,21 +367,23 @@ public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocat
   }
 
   /**
-   * sync. a buffer to underlying memory device.
-   * 
+   * sync. a buffer to memory.
+   *
    * @param mbuf
    *         specify a buffer to be sync.
    */
+  @Override
   public void sync(MemBufferHolder<VolatileMemAllocator> mbuf) {
     m_vmasvc.sync(m_nid, getBufferAddress(mbuf), 0L, true);
   }
 
   /**
-   * sync. a chunk to underlying memory device.
-   * 
+   * sync. a chunk to memory.
+   *
    * @param mchunk
    *         specify a chunk to be sync.
    */
+  @Override
   public void sync(MemChunkHolder<VolatileMemAllocator> mchunk) {
     m_vmasvc.sync(m_nid, getChunkAddress(mchunk), 0L, true);
   }
@@ -389,6 +391,7 @@ public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocat
   /**
    * sync. the memory pool to underlying memory device.
    */
+  @Override
   public void syncAll() {
     m_vmasvc.sync(m_nid, 0L, 0L, true);
   }


Mime
View raw message