You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ea...@apache.org on 2019/12/16 13:34:38 UTC

[incubator-iotdb] 02/02: update

This is an automated email from the ASF dual-hosted git repository.

east pushed a commit to branch nvmlogging
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit c4fd53cbac784838e2d792fc467d1eb77f2ef4e8
Author: mdf369 <95...@qq.com>
AuthorDate: Mon Dec 16 21:34:16 2019 +0800

    update
---
 .../db/nvm/datastructure/NVMBooleanTVList.java     | 197 +++++++++++++++++++++
 .../db/nvm/datastructure/NVMDoubleTVList.java      | 197 +++++++++++++++++++++
 .../iotdb/db/nvm/datastructure/NVMFloatTVList.java | 197 +++++++++++++++++++++
 .../iotdb/db/nvm/datastructure/NVMTVList.java      |   6 +-
 .../iotdb/db/nvm/rescon/NVMPrimitiveArrayPool.java |   2 +-
 .../apache/iotdb/db/nvm/space/NVMSpaceManager.java |  42 +++--
 .../apache/iotdb/db/rescon/TVListAllocator.java    |  21 ++-
 .../java/org/apache/iotdb/db/service/IoTDB.java    |   3 +
 .../apache/iotdb/db/utils/EnvironmentUtils.java    |   6 +-
 9 files changed, 640 insertions(+), 31 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMBooleanTVList.java b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMBooleanTVList.java
new file mode 100644
index 0000000..96f48d6
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMBooleanTVList.java
@@ -0,0 +1,197 @@
+package org.apache.iotdb.db.nvm.datastructure;
+
+import static org.apache.iotdb.db.nvm.rescon.NVMPrimitiveArrayPool.ARRAY_SIZE;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.db.nvm.rescon.NVMPrimitiveArrayPool;
+import org.apache.iotdb.db.nvm.space.NVMSpaceManager.NVMSpace;
+import org.apache.iotdb.db.rescon.PrimitiveArrayPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+public class NVMBooleanTVList extends NVMTVList {
+
+  private List<NVMSpace> values;
+
+  // TODO
+  private boolean[][] sortedValues;
+
+  private boolean pivotValue;
+
+  NVMBooleanTVList() {
+    super();
+    values = new ArrayList<>();
+  }
+
+  @Override
+  public void putBoolean(long timestamp, boolean value) {
+    checkExpansion();
+    int arrayIndex = size / ARRAY_SIZE;
+    int elementIndex = size % ARRAY_SIZE;
+    minTime = minTime <= timestamp ? minTime : timestamp;
+    timestamps.get(arrayIndex).set(elementIndex, timestamp);
+    values.get(arrayIndex).set(elementIndex, value);
+    size++;
+    if (sorted && size > 1 && timestamp < getTime(size - 2)) {
+      sorted = false;
+    }
+  }
+
+  @Override
+  public boolean getBoolean(int index) {
+    if (index >= size) {
+      throw new ArrayIndexOutOfBoundsException(index);
+    }
+    int arrayIndex = index / ARRAY_SIZE;
+    int elementIndex = index % ARRAY_SIZE;
+    return (boolean) values.get(arrayIndex).get(elementIndex);
+  }
+
+  protected void set(int index, long timestamp, boolean value) {
+    if (index >= size) {
+      throw new ArrayIndexOutOfBoundsException(index);
+    }
+    int arrayIndex = index / ARRAY_SIZE;
+    int elementIndex = index % ARRAY_SIZE;
+    timestamps.get(arrayIndex).set(elementIndex, timestamp);
+    values.get(arrayIndex).set(elementIndex, value);
+  }
+
+  @Override
+  public NVMBooleanTVList clone() {
+    NVMBooleanTVList cloneList = new NVMBooleanTVList();
+    cloneAs(cloneList);
+    for (NVMSpace valueSpace : values) {
+      cloneList.values.add(cloneValue(valueSpace));
+    }
+    return cloneList;
+  }
+
+  private NVMSpace cloneValue(NVMSpace valueSpace) {
+    return valueSpace.clone();
+  }
+
+  @Override
+  public void sort() {
+    if (sortedTimestamps == null || sortedTimestamps.length < size) {
+      sortedTimestamps = (long[][]) PrimitiveArrayPool
+          .getInstance().getDataListsByType(TSDataType.INT64, size);
+    }
+    if (sortedValues == null || sortedValues.length < size) {
+      sortedValues = (boolean[][]) PrimitiveArrayPool
+          .getInstance().getDataListsByType(TSDataType.BOOLEAN, size);
+    }
+    sort(0, size);
+    clearSortedValue();
+    clearSortedTime();
+    sorted = true;
+  }
+
+  @Override
+  protected void clearValue() {
+    if (values != null) {
+      for (NVMSpace valueSpace : values) {
+        PrimitiveArrayPool.getInstance().release(valueSpace);
+      }
+      values.clear();
+    }
+  }
+
+  @Override
+  protected void clearSortedValue() {
+    if (sortedValues != null) {
+      for (boolean[] dataArray : sortedValues) {
+        PrimitiveArrayPool.getInstance().release(dataArray);
+      }
+      sortedValues = null;
+    }
+  }
+
+  @Override
+  protected void setFromSorted(int src, int dest) {
+    set(dest, sortedTimestamps[src/ARRAY_SIZE][src%ARRAY_SIZE], sortedValues[src/ARRAY_SIZE][src%ARRAY_SIZE]);
+  }
+
+  @Override
+  protected void set(int src, int dest) {
+    long srcT = getTime(src);
+    boolean srcV = getBoolean(src);
+    set(dest, srcT, srcV);
+  }
+
+  @Override
+  protected void setToSorted(int src, int dest) {
+    sortedTimestamps[dest/ARRAY_SIZE][dest% ARRAY_SIZE] = getTime(src);
+    sortedValues[dest/ARRAY_SIZE][dest%ARRAY_SIZE] = getBoolean(src);
+  }
+
+  @Override
+  protected void reverseRange(int lo, int hi) {
+    hi--;
+    while (lo < hi) {
+      long loT = getTime(lo);
+      boolean loV = getBoolean(lo);
+      long hiT = getTime(hi);
+      boolean hiV = getBoolean(hi);
+      set(lo++, hiT, hiV);
+      set(hi--, loT, loV);
+    }
+  }
+
+  @Override
+  protected void expandValues() {
+    values.add(NVMPrimitiveArrayPool
+        .getInstance().getPrimitiveDataListByType(TSDataType.BOOLEAN));
+  }
+
+  @Override
+  protected void saveAsPivot(int pos) {
+    pivotTime = getTime(pos);
+    pivotValue = getBoolean(pos);
+  }
+
+  @Override
+  protected void setPivotTo(int pos) {
+    set(pos, pivotTime, pivotValue);
+  }
+
+  @Override
+  protected void releaseLastValueArray() {
+    PrimitiveArrayPool.getInstance().release(values.remove(values.size() - 1));
+  }
+
+  @Override
+  public void putBooleans(long[] time, boolean[] value) {
+    checkExpansion();
+    int idx = 0;
+    int length = time.length;
+
+    for (int i = 0; i < length; i++) {
+      putBoolean(time[i], value[i]);
+    }
+
+//    updateMinTimeAndSorted(time);
+//
+//    while (idx < length) {
+//      int inputRemaining = length - idx;
+//      int arrayIdx = size / ARRAY_SIZE;
+//      int elementIdx = size % ARRAY_SIZE;
+//      int internalRemaining  = ARRAY_SIZE - elementIdx;
+//      if (internalRemaining >= inputRemaining) {
+//        // the remaining inputs can fit the last array, copy all remaining inputs into last array
+//        System.arraycopy(time, idx, timestamps.get(arrayIdx), elementIdx, inputRemaining);
+//        System.arraycopy(value, idx, values.get(arrayIdx), elementIdx, inputRemaining);
+//        size += inputRemaining;
+//        break;
+//      } else {
+//        // the remaining inputs cannot fit the last array, fill the last array and create a new
+//        // one and enter the next loop
+//        System.arraycopy(time, idx, timestamps.get(arrayIdx), elementIdx, internalRemaining);
+//        System.arraycopy(value, idx, values.get(arrayIdx), elementIdx, internalRemaining);
+//        idx += internalRemaining;
+//        size += internalRemaining;
+//        checkExpansion();
+//      }
+//    }
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMDoubleTVList.java b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMDoubleTVList.java
new file mode 100644
index 0000000..12ffc2e
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMDoubleTVList.java
@@ -0,0 +1,197 @@
+package org.apache.iotdb.db.nvm.datastructure;
+
+import static org.apache.iotdb.db.nvm.rescon.NVMPrimitiveArrayPool.ARRAY_SIZE;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.db.nvm.rescon.NVMPrimitiveArrayPool;
+import org.apache.iotdb.db.nvm.space.NVMSpaceManager.NVMSpace;
+import org.apache.iotdb.db.rescon.PrimitiveArrayPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+public class NVMDoubleTVList extends NVMTVList {
+
+  private List<NVMSpace> values;
+
+  // TODO
+  private double[][] sortedValues;
+
+  private double pivotValue;
+
+  NVMDoubleTVList() {
+    super();
+    values = new ArrayList<>();
+  }
+
+  @Override
+  public void putDouble(long timestamp, double value) {
+    checkExpansion();
+    int arrayIndex = size / ARRAY_SIZE;
+    int elementIndex = size % ARRAY_SIZE;
+    minTime = minTime <= timestamp ? minTime : timestamp;
+    timestamps.get(arrayIndex).set(elementIndex, timestamp);
+    values.get(arrayIndex).set(elementIndex, value);
+    size++;
+    if (sorted && size > 1 && timestamp < getTime(size - 2)) {
+      sorted = false;
+    }
+  }
+
+  @Override
+  public double getDouble(int index) {
+    if (index >= size) {
+      throw new ArrayIndexOutOfBoundsException(index);
+    }
+    int arrayIndex = index / ARRAY_SIZE;
+    int elementIndex = index % ARRAY_SIZE;
+    return (double) values.get(arrayIndex).get(elementIndex);
+  }
+
+  protected void set(int index, long timestamp, double value) {
+    if (index >= size) {
+      throw new ArrayIndexOutOfBoundsException(index);
+    }
+    int arrayIndex = index / ARRAY_SIZE;
+    int elementIndex = index % ARRAY_SIZE;
+    timestamps.get(arrayIndex).set(elementIndex, timestamp);
+    values.get(arrayIndex).set(elementIndex, value);
+  }
+
+  @Override
+  public NVMDoubleTVList clone() {
+    NVMDoubleTVList cloneList = new NVMDoubleTVList();
+    cloneAs(cloneList);
+    for (NVMSpace valueSpace : values) {
+      cloneList.values.add(cloneValue(valueSpace));
+    }
+    return cloneList;
+  }
+
+  private NVMSpace cloneValue(NVMSpace valueSpace) {
+    return valueSpace.clone();
+  }
+
+  @Override
+  public void sort() {
+    if (sortedTimestamps == null || sortedTimestamps.length < size) {
+      sortedTimestamps = (long[][]) PrimitiveArrayPool
+          .getInstance().getDataListsByType(TSDataType.INT64, size);
+    }
+    if (sortedValues == null || sortedValues.length < size) {
+      sortedValues = (double[][]) PrimitiveArrayPool
+          .getInstance().getDataListsByType(TSDataType.DOUBLE, size);
+    }
+    sort(0, size);
+    clearSortedValue();
+    clearSortedTime();
+    sorted = true;
+  }
+
+  @Override
+  protected void clearValue() {
+    if (values != null) {
+      for (NVMSpace valueSpace : values) {
+        PrimitiveArrayPool.getInstance().release(valueSpace);
+      }
+      values.clear();
+    }
+  }
+
+  @Override
+  protected void clearSortedValue() {
+    if (sortedValues != null) {
+      for (double[] dataArray : sortedValues) {
+        PrimitiveArrayPool.getInstance().release(dataArray);
+      }
+      sortedValues = null;
+    }
+  }
+
+  @Override
+  protected void setFromSorted(int src, int dest) {
+    set(dest, sortedTimestamps[src/ARRAY_SIZE][src%ARRAY_SIZE], sortedValues[src/ARRAY_SIZE][src%ARRAY_SIZE]);
+  }
+
+  @Override
+  protected void set(int src, int dest) {
+    long srcT = getTime(src);
+    double srcV = getDouble(src);
+    set(dest, srcT, srcV);
+  }
+
+  @Override
+  protected void setToSorted(int src, int dest) {
+    sortedTimestamps[dest/ARRAY_SIZE][dest% ARRAY_SIZE] = getTime(src);
+    sortedValues[dest/ARRAY_SIZE][dest%ARRAY_SIZE] = getDouble(src);
+  }
+
+  @Override
+  protected void reverseRange(int lo, int hi) {
+    hi--;
+    while (lo < hi) {
+      long loT = getTime(lo);
+      double loV = getDouble(lo);
+      long hiT = getTime(hi);
+      double hiV = getDouble(hi);
+      set(lo++, hiT, hiV);
+      set(hi--, loT, loV);
+    }
+  }
+
+  @Override
+  protected void expandValues() {
+    values.add(NVMPrimitiveArrayPool
+        .getInstance().getPrimitiveDataListByType(TSDataType.DOUBLE));
+  }
+
+  @Override
+  protected void saveAsPivot(int pos) {
+    pivotTime = getTime(pos);
+    pivotValue = getDouble(pos);
+  }
+
+  @Override
+  protected void setPivotTo(int pos) {
+    set(pos, pivotTime, pivotValue);
+  }
+
+  @Override
+  protected void releaseLastValueArray() {
+    PrimitiveArrayPool.getInstance().release(values.remove(values.size() - 1));
+  }
+
+  @Override
+  public void putDoubles(long[] time, double[] value) {
+    checkExpansion();
+    int idx = 0;
+    int length = time.length;
+
+    for (int i = 0; i < length; i++) {
+      putDouble(time[i], value[i]);
+    }
+
+//    updateMinTimeAndSorted(time);
+//
+//    while (idx < length) {
+//      int inputRemaining = length - idx;
+//      int arrayIdx = size / ARRAY_SIZE;
+//      int elementIdx = size % ARRAY_SIZE;
+//      int internalRemaining  = ARRAY_SIZE - elementIdx;
+//      if (internalRemaining >= inputRemaining) {
+//        // the remaining inputs can fit the last array, copy all remaining inputs into last array
+//        System.arraycopy(time, idx, timestamps.get(arrayIdx), elementIdx, inputRemaining);
+//        System.arraycopy(value, idx, values.get(arrayIdx), elementIdx, inputRemaining);
+//        size += inputRemaining;
+//        break;
+//      } else {
+//        // the remaining inputs cannot fit the last array, fill the last array and create a new
+//        // one and enter the next loop
+//        System.arraycopy(time, idx, timestamps.get(arrayIdx), elementIdx, internalRemaining);
+//        System.arraycopy(value, idx, values.get(arrayIdx), elementIdx, internalRemaining);
+//        idx += internalRemaining;
+//        size += internalRemaining;
+//        checkExpansion();
+//      }
+//    }
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMFloatTVList.java b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMFloatTVList.java
new file mode 100644
index 0000000..9e527fc
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMFloatTVList.java
@@ -0,0 +1,197 @@
+package org.apache.iotdb.db.nvm.datastructure;
+
+import static org.apache.iotdb.db.nvm.rescon.NVMPrimitiveArrayPool.ARRAY_SIZE;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.iotdb.db.nvm.rescon.NVMPrimitiveArrayPool;
+import org.apache.iotdb.db.nvm.space.NVMSpaceManager.NVMSpace;
+import org.apache.iotdb.db.rescon.PrimitiveArrayPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+
+public class NVMFloatTVList extends NVMTVList {
+
+  private List<NVMSpace> values;
+
+  // TODO
+  private float[][] sortedValues;
+
+  private float pivotValue;
+
+  NVMFloatTVList() {
+    super();
+    values = new ArrayList<>();
+  }
+
+  @Override
+  public void putFloat(long timestamp, float value) {
+    checkExpansion();
+    int arrayIndex = size / ARRAY_SIZE;
+    int elementIndex = size % ARRAY_SIZE;
+    minTime = minTime <= timestamp ? minTime : timestamp;
+    timestamps.get(arrayIndex).set(elementIndex, timestamp);
+    values.get(arrayIndex).set(elementIndex, value);
+    size++;
+    if (sorted && size > 1 && timestamp < getTime(size - 2)) {
+      sorted = false;
+    }
+  }
+
+  @Override
+  public float getFloat(int index) {
+    if (index >= size) {
+      throw new ArrayIndexOutOfBoundsException(index);
+    }
+    int arrayIndex = index / ARRAY_SIZE;
+    int elementIndex = index % ARRAY_SIZE;
+    return (float) values.get(arrayIndex).get(elementIndex);
+  }
+
+  protected void set(int index, long timestamp, float value) {
+    if (index >= size) {
+      throw new ArrayIndexOutOfBoundsException(index);
+    }
+    int arrayIndex = index / ARRAY_SIZE;
+    int elementIndex = index % ARRAY_SIZE;
+    timestamps.get(arrayIndex).set(elementIndex, timestamp);
+    values.get(arrayIndex).set(elementIndex, value);
+  }
+
+  @Override
+  public NVMFloatTVList clone() {
+    NVMFloatTVList cloneList = new NVMFloatTVList();
+    cloneAs(cloneList);
+    for (NVMSpace valueSpace : values) {
+      cloneList.values.add(cloneValue(valueSpace));
+    }
+    return cloneList;
+  }
+
+  private NVMSpace cloneValue(NVMSpace valueSpace) {
+    return valueSpace.clone();
+  }
+
+  @Override
+  public void sort() {
+    if (sortedTimestamps == null || sortedTimestamps.length < size) {
+      sortedTimestamps = (long[][]) PrimitiveArrayPool
+          .getInstance().getDataListsByType(TSDataType.INT64, size);
+    }
+    if (sortedValues == null || sortedValues.length < size) {
+      sortedValues = (float[][]) PrimitiveArrayPool
+          .getInstance().getDataListsByType(TSDataType.FLOAT, size);
+    }
+    sort(0, size);
+    clearSortedValue();
+    clearSortedTime();
+    sorted = true;
+  }
+
+  @Override
+  protected void clearValue() {
+    if (values != null) {
+      for (NVMSpace valueSpace : values) {
+        PrimitiveArrayPool.getInstance().release(valueSpace);
+      }
+      values.clear();
+    }
+  }
+
+  @Override
+  protected void clearSortedValue() {
+    if (sortedValues != null) {
+      for (float[] dataArray : sortedValues) {
+        PrimitiveArrayPool.getInstance().release(dataArray);
+      }
+      sortedValues = null;
+    }
+  }
+
+  @Override
+  protected void setFromSorted(int src, int dest) {
+    set(dest, sortedTimestamps[src/ARRAY_SIZE][src%ARRAY_SIZE], sortedValues[src/ARRAY_SIZE][src%ARRAY_SIZE]);
+  }
+
+  @Override
+  protected void set(int src, int dest) {
+    long srcT = getTime(src);
+    float srcV = getFloat(src);
+    set(dest, srcT, srcV);
+  }
+
+  @Override
+  protected void setToSorted(int src, int dest) {
+    sortedTimestamps[dest/ARRAY_SIZE][dest% ARRAY_SIZE] = getTime(src);
+    sortedValues[dest/ARRAY_SIZE][dest%ARRAY_SIZE] = getFloat(src);
+  }
+
+  @Override
+  protected void reverseRange(int lo, int hi) {
+    hi--;
+    while (lo < hi) {
+      long loT = getTime(lo);
+      float loV = getFloat(lo);
+      long hiT = getTime(hi);
+      float hiV = getFloat(hi);
+      set(lo++, hiT, hiV);
+      set(hi--, loT, loV);
+    }
+  }
+
+  @Override
+  protected void expandValues() {
+    values.add(NVMPrimitiveArrayPool
+        .getInstance().getPrimitiveDataListByType(TSDataType.FLOAT));
+  }
+
+  @Override
+  protected void saveAsPivot(int pos) {
+    pivotTime = getTime(pos);
+    pivotValue = getFloat(pos);
+  }
+
+  @Override
+  protected void setPivotTo(int pos) {
+    set(pos, pivotTime, pivotValue);
+  }
+
+  @Override
+  protected void releaseLastValueArray() {
+    PrimitiveArrayPool.getInstance().release(values.remove(values.size() - 1));
+  }
+
+  @Override
+  public void putFloats(long[] time, float[] value) {
+    checkExpansion();
+    int idx = 0;
+    int length = time.length;
+
+    for (int i = 0; i < length; i++) {
+      putFloat(time[i], value[i]);
+    }
+
+//    updateMinTimeAndSorted(time);
+//
+//    while (idx < length) {
+//      int inputRemaining = length - idx;
+//      int arrayIdx = size / ARRAY_SIZE;
+//      int elementIdx = size % ARRAY_SIZE;
+//      int internalRemaining  = ARRAY_SIZE - elementIdx;
+//      if (internalRemaining >= inputRemaining) {
+//        // the remaining inputs can fit the last array, copy all remaining inputs into last array
+//        System.arraycopy(time, idx, timestamps.get(arrayIdx), elementIdx, inputRemaining);
+//        System.arraycopy(value, idx, values.get(arrayIdx), elementIdx, inputRemaining);
+//        size += inputRemaining;
+//        break;
+//      } else {
+//        // the remaining inputs cannot fit the last array, fill the last array and create a new
+//        // one and enter the next loop
+//        System.arraycopy(time, idx, timestamps.get(arrayIdx), elementIdx, internalRemaining);
+//        System.arraycopy(value, idx, values.get(arrayIdx), elementIdx, internalRemaining);
+//        idx += internalRemaining;
+//        size += internalRemaining;
+//        checkExpansion();
+//      }
+//    }
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMTVList.java b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMTVList.java
index 45df453..e7ffebd 100644
--- a/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMTVList.java
+++ b/server/src/main/java/org/apache/iotdb/db/nvm/datastructure/NVMTVList.java
@@ -108,15 +108,15 @@ public abstract class NVMTVList extends AbstractTVList {
         // TODO
 //        return new BinaryTVList();
       case FLOAT:
-//        return new FloatTVList();
+        return new NVMFloatTVList();
       case INT32:
         return new NVMIntTVList();
       case INT64:
         return new NVMLongTVList();
       case DOUBLE:
-//        return new DoubleTVList();
+        return new NVMDoubleTVList();
       case BOOLEAN:
-//        return new BooleanTVList();
+        return new NVMBooleanTVList();
     }
     return null;
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/nvm/rescon/NVMPrimitiveArrayPool.java b/server/src/main/java/org/apache/iotdb/db/nvm/rescon/NVMPrimitiveArrayPool.java
index 0647217..7cfef5a 100644
--- a/server/src/main/java/org/apache/iotdb/db/nvm/rescon/NVMPrimitiveArrayPool.java
+++ b/server/src/main/java/org/apache/iotdb/db/nvm/rescon/NVMPrimitiveArrayPool.java
@@ -40,7 +40,7 @@ public class NVMPrimitiveArrayPool {
 
     long size = NVMSpaceManager.getPrimitiveTypeByteSize(dataType);
     if (nvmSpace == null) {
-      nvmSpace = NVMSpaceManager.allocate(size * ARRAY_SIZE, dataType);
+      nvmSpace = NVMSpaceManager.getInstance().allocate(size * ARRAY_SIZE, dataType);
     }
 
     return nvmSpace;
diff --git a/server/src/main/java/org/apache/iotdb/db/nvm/space/NVMSpaceManager.java b/server/src/main/java/org/apache/iotdb/db/nvm/space/NVMSpaceManager.java
index 24d3d0d..d504e9f 100644
--- a/server/src/main/java/org/apache/iotdb/db/nvm/space/NVMSpaceManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/nvm/space/NVMSpaceManager.java
@@ -6,8 +6,11 @@ import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileChannel.MapMode;
 import java.util.concurrent.atomic.AtomicLong;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.StartupException;
 import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.fileSystem.FSFactoryProducer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -15,24 +18,31 @@ public class NVMSpaceManager {
 
   private static final Logger logger = LoggerFactory.getLogger(NVMSpaceManager.class);
 
-  private static String NVM_PATH;
-  private static FileChannel nvmFileChannel;
-  private static final MapMode MAP_MODE = MapMode.READ_WRITE;
-  private static long nvmSize;
-  private static AtomicLong curOffset = new AtomicLong(0L);
+  private final static NVMSpaceManager INSTANCE = new NVMSpaceManager();
 
-  public static void init(String dir) {
+  private String NVM_PATH;
+  private FileChannel nvmFileChannel;
+  private final MapMode MAP_MODE = MapMode.READ_WRITE;
+  private long nvmSize;
+  private AtomicLong curOffset = new AtomicLong(0L);
+
+  private NVMSpaceManager() {
+//    init();
+  }
+
+  public void init() throws StartupException {
     try {
-      NVM_PATH = dir + "/nvmFile";
+      NVM_PATH = IoTDBDescriptor.getInstance().getConfig().getNvmDir() + "/nvmFile";
+      FSFactoryProducer.getFSFactory().getFile(IoTDBDescriptor.getInstance().getConfig().getNvmDir()).mkdirs();
       nvmFileChannel = new RandomAccessFile(NVM_PATH, "rw").getChannel();
       nvmSize = nvmFileChannel.size();
     } catch (IOException e) {
       logger.error("Fail to open NVM space at {}.", NVM_PATH, e);
-      // TODO deal with error
+      throw new StartupException(e);
     }
   }
 
-  public static void close() throws IOException {
+  public void close() throws IOException {
     nvmFileChannel.close();
   }
 
@@ -63,7 +73,7 @@ public class NVMSpaceManager {
     return size >> 3;
   }
 
-  public static NVMSpace allocate(long size, TSDataType dataType) {
+  public NVMSpace allocate(long size, TSDataType dataType) {
     long offset = curOffset.getAndAdd(size);
     if (offset + size > nvmSize) {
       // TODO throw exception
@@ -78,7 +88,7 @@ public class NVMSpaceManager {
     }
   }
 
-  public static class NVMSpace {
+  public class NVMSpace {
 
     private long offset;
     private long size;
@@ -106,7 +116,7 @@ public class NVMSpaceManager {
 
     @Override
     public NVMSpace clone() {
-      NVMSpace cloneSpace = NVMSpaceManager.allocate(size, dataType);
+      NVMSpace cloneSpace = NVMSpaceManager.getInstance().allocate(size, dataType);
       int position = byteBuffer.position();
       byteBuffer.rewind();
       cloneSpace.getByteBuffer().put(byteBuffer);
@@ -168,11 +178,7 @@ public class NVMSpaceManager {
     }
   }
 
-  public static String getNvmPath() {
-    return NVM_PATH;
-  }
-
-  public static void setNvmPath(String nvmPath) {
-    NVM_PATH = nvmPath;
+  public static NVMSpaceManager getInstance() {
+    return INSTANCE;
   }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java b/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java
index f32950a..f7f8d91 100644
--- a/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java
+++ b/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java
@@ -26,6 +26,9 @@ import java.util.Queue;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.exception.StartupException;
 import org.apache.iotdb.db.nvm.datastructure.AbstractTVList;
+import org.apache.iotdb.db.nvm.datastructure.NVMBooleanTVList;
+import org.apache.iotdb.db.nvm.datastructure.NVMDoubleTVList;
+import org.apache.iotdb.db.nvm.datastructure.NVMFloatTVList;
 import org.apache.iotdb.db.nvm.datastructure.NVMIntTVList;
 import org.apache.iotdb.db.nvm.datastructure.NVMLongTVList;
 import org.apache.iotdb.db.nvm.datastructure.NVMTVList;
@@ -81,10 +84,20 @@ public class TVListAllocator implements TVListAllocatorMBean, IService {
 
   public synchronized void release(AbstractTVList list) {
     list.clear();
-    if (list instanceof NVMIntTVList) {
-      nvmTVListCache.get(TSDataType.INT32).add((NVMTVList) list);
-    } else if (list instanceof NVMLongTVList) {
-      nvmTVListCache.get(TSDataType.INT64).add((NVMTVList) list);
+    if (list instanceof NVMTVList) {
+      NVMTVList tvList = (NVMTVList) list;
+      if (list instanceof NVMIntTVList) {
+        nvmTVListCache.get(TSDataType.INT32).add(tvList);
+      } else if (list instanceof NVMLongTVList) {
+        nvmTVListCache.get(TSDataType.INT64).add(tvList);
+      } else if (list instanceof NVMFloatTVList) {
+        nvmTVListCache.get(TSDataType.FLOAT).add(tvList);
+      } else if (list instanceof NVMDoubleTVList) {
+        nvmTVListCache.get(TSDataType.DOUBLE).add(tvList);
+      } else if (list instanceof NVMBooleanTVList) {
+        nvmTVListCache.get(TSDataType.BOOLEAN).add(tvList);
+      }
+      // TODO Binary
     } else {
       TVList tvList = (TVList) list;
 
diff --git a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
index b191fa8..0095c63 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
@@ -32,6 +32,7 @@ import org.apache.iotdb.db.engine.flush.FlushManager;
 import org.apache.iotdb.db.exception.StartupException;
 import org.apache.iotdb.db.metadata.MManager;
 import org.apache.iotdb.db.monitor.StatMonitor;
+import org.apache.iotdb.db.nvm.space.NVMSpaceManager;
 import org.apache.iotdb.db.rescon.TVListAllocator;
 import org.apache.iotdb.db.sync.receiver.SyncServerManager;
 import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager;
@@ -107,6 +108,8 @@ public class IoTDB implements IoTDBMBean {
       StatMonitor.getInstance().recovery();
     }
 
+    NVMSpaceManager.getInstance().init();
+
     logger.info("IoTDB is set up.");
   }
 
diff --git a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
index eaee4bb..1a8111c 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
@@ -70,7 +70,7 @@ public class EnvironmentUtils {
   private static long oldGroupSizeInByte = config.getMemtableSizeThreshold();
 
   public static void cleanEnv() throws IOException, StorageEngineException {
-    NVMSpaceManager.close();
+    NVMSpaceManager.getInstance().close();
 
     QueryResourceManager.getInstance().endQuery(TEST_QUERY_JOB_ID);
 
@@ -170,8 +170,6 @@ public class EnvironmentUtils {
     MergeManager.getINSTANCE().start();
     TEST_QUERY_JOB_ID  = QueryResourceManager.getInstance().assignQueryId();
     TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID);
-
-    NVMSpaceManager.init(config.getNvmDir());
   }
 
   private static void createAllDir() {
@@ -187,8 +185,6 @@ public class EnvironmentUtils {
     createDir(config.getSystemDir());
     // create wal
     createDir(config.getWalFolder());
-    // create index
-    createDir(config.getIndexFileDir());
     // create query
     createDir(config.getQueryDir());
     createDir(TestConstant.OUTPUT_DATA_DIR);