You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2019/06/28 02:30:19 UTC

[incubator-iotdb] branch feature_async_close_tsfile updated: fix incorrect pivot usage

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

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


The following commit(s) were added to refs/heads/feature_async_close_tsfile by this push:
     new 2be01c8  fix incorrect pivot usage
2be01c8 is described below

commit 2be01c8b7c559ae6bf05bd78bbc46b2ef85f2780
Author: 江天 <jt...@163.com>
AuthorDate: Fri Jun 28 10:28:08 2019 +0800

    fix incorrect pivot usage
---
 .../iotdb/db/utils/datastructure/DoubleTVList.java | 27 +++++++++++++++-------
 .../iotdb/db/utils/datastructure/LongTVList.java   | 18 +++++++++++++++
 .../iotdb/db/utils/datastructure/TVList.java       | 26 ++++++++++++++++++++-
 3 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
index 9fa7fd8..f7d08ff 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java
@@ -27,6 +27,8 @@ public class DoubleTVList extends TVList {
 
   private double[] sortedValues;
 
+  private double pivotValue;
+
   public DoubleTVList() {
     super();
     values = new ArrayList<>();
@@ -34,10 +36,7 @@ public class DoubleTVList extends TVList {
 
   @Override
   public void putDouble(long timestamp, double value) {
-    if ((size % SINGLE_ARRAY_SIZE) == 0) {
-      values.add(new double[SINGLE_ARRAY_SIZE]);
-      timestamps.add(new long[SINGLE_ARRAY_SIZE]);
-    }
+    checkExpansion();
     int arrayIndex = size / SINGLE_ARRAY_SIZE;
     int elementIndex = size % SINGLE_ARRAY_SIZE;
     timestamps.get(arrayIndex)[elementIndex] = timestamp;
@@ -97,10 +96,6 @@ public class DoubleTVList extends TVList {
     return cloneArray;
   }
 
-  public void reset() {
-    size = 0;
-  }
-
   public void sort() {
     sortedTimestamps = new long[size];
     sortedValues = new double[size];
@@ -137,4 +132,20 @@ public class DoubleTVList extends TVList {
       set(hi--, loT, loV);
     }
   }
+
+  @Override
+  protected void expandValues() {
+    values.add(new double[SINGLE_ARRAY_SIZE]);
+  }
+
+  @Override
+  protected void saveAsPivot(int pos) {
+    pivotTime = getTime(pos);
+    pivotValue = getDouble(pos);
+  }
+
+  @Override
+  protected void setPivotTo(int pos) {
+    set(pos, pivotTime, pivotValue);
+  }
 }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
index 6cec61f..f91ae23 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java
@@ -27,6 +27,8 @@ public class LongTVList extends TVList {
 
   private long[] sortedValues;
 
+  private long pivotValue;
+
   public LongTVList() {
     super();
     values = new ArrayList<>();
@@ -137,4 +139,20 @@ public class LongTVList extends TVList {
       set(hi--, loT, loV);
     }
   }
+
+  @Override
+  protected void expandValues() {
+
+  }
+
+  @Override
+  protected void saveAsPivot(int pos) {
+    pivotTime = getTime(pos);
+    pivotValue = getLong(pos);
+  }
+
+  @Override
+  protected void setPivotTo(int pos) {
+    set(pos, pivotTime, pivotValue);
+  }
 }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
index b0812b3..782b062 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java
@@ -31,15 +31,19 @@ public abstract class TVList {
 
   protected List<long[]> timestamps;
   protected int size;
+  protected int limit;
 
   protected long[] sortedTimestamps;
   protected boolean sorted = false;
 
   private long timeOffset = -1;
 
+  protected long pivotTime;
+
   public TVList() {
     timestamps = new ArrayList<>();
     size = 0;
+    limit = 0;
   }
 
   public int size() {
@@ -117,8 +121,23 @@ public abstract class TVList {
 
   protected abstract void reverseRange(int lo, int hi);
 
+  protected abstract void expandValues();
+
   public abstract TVList clone();
 
+  public void reset() {
+    size = 0;
+    limit = 0;
+  }
+
+  protected void checkExpansion() {
+    if ((size == limit) && (size % SINGLE_ARRAY_SIZE) == 0) {
+      expandValues();
+      timestamps.add(new long[SINGLE_ARRAY_SIZE]);
+      limit += SINGLE_ARRAY_SIZE;
+    }
+  }
+
   protected long[] cloneTime(long[] array) {
     long[] cloneArray = new long[array.length];
     System.arraycopy(array, 0, cloneArray, 0, array.length);
@@ -186,6 +205,10 @@ public abstract class TVList {
     return Long.compare(t1, t2);
   }
 
+  protected abstract void saveAsPivot(int pos);
+
+  protected abstract void setPivotTo(int pos);
+
   /**
    * From TimSort.java
    */
@@ -195,6 +218,7 @@ public abstract class TVList {
       start++;
     for ( ; start < hi; start++) {
 
+      saveAsPivot(start);
       // Set left (and right) to the index where a[start] (pivot) belongs
       int left = lo;
       int right = start;
@@ -224,7 +248,7 @@ public abstract class TVList {
       for (int i = n; i >= 1; i--) {
         set(left + i - 1, left + i);
       }
-      set(left, start);
+      setPivotTo(left);
     }
     for (int i = lo; i < hi; i++) {
       setSorted(i, i);