You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/09/12 08:34:38 UTC

[GitHub] [iotdb] LittleHealth opened a new pull request, #7290: Add QuickSort in TVList

LittleHealth opened a new pull request, #7290:
URL: https://github.com/apache/iotdb/pull/7290

   Add quick sort algorithm;
   1. add config, choose to use tim or quick
   2. reformat: move clone, deserialize functions to abstract class IntTVList
   3. fix the test
   
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #7290: [IOTDB-4431] Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r973888604


##########
server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java:
##########
@@ -1381,6 +1382,11 @@ private void loadTimedService(Properties properties) {
     if (unseqMemTableFlushCheckInterval > 0) {
       conf.setUnseqMemtableFlushCheckInterval(unseqMemTableFlushCheckInterval);
     }
+
+    conf.setTvListSortAlgorithm(
+        TVListSortAlgorithm.valueOf(
+            properties.getProperty(
+                "tvList_sort_algorithm", conf.getTvListSortAlgorithm().toString())));

Review Comment:
   ```suggestion
                   "tvlist_sort_algorithm", conf.getTvListSortAlgorithm().toString())));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HeimingZ commented on a diff in pull request #7290: Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HeimingZ commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r969210078


##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java:
##########
@@ -46,6 +49,42 @@ public abstract class BinaryTVList extends TVList {
     values = new ArrayList<>();
   }
 
+  public static BinaryTVList newList() {
+    if (TVLIST_SORT_ALGORITHM == 1) {
+      return new QuickBinaryTVList();
+    }
+    return new TimBinaryTVList();
+  }
+
+  public static BinaryTVList deserialize(DataInputStream stream) throws IOException {
+    BinaryTVList tvList = BinaryTVList.newList();
+    int rowCount = stream.readInt();
+    long[] times = new long[rowCount];
+    Binary[] values = new Binary[rowCount];
+    for (int rowIdx = 0; rowIdx < rowCount; ++rowIdx) {
+      times[rowIdx] = stream.readLong();
+      values[rowIdx] = ReadWriteIOUtils.readBinary(stream);
+    }
+    tvList.putBinaries(times, values, null, 0, rowCount);
+    return tvList;
+  }

Review Comment:
   If user uses tim sort to serialize and uses quick sort to deserialize, this deserialization method will throw an exception. We should serialize sort type and choose different implementations when deserializing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] LittleHealth commented on a diff in pull request #7290: [IOTDB-4431] Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
LittleHealth commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r973983703


##########
server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java:
##########
@@ -1381,6 +1382,11 @@ private void loadTimedService(Properties properties) {
     if (unseqMemTableFlushCheckInterval > 0) {
       conf.setUnseqMemtableFlushCheckInterval(unseqMemTableFlushCheckInterval);
     }
+
+    conf.setTvListSortAlgorithm(
+        TVListSortAlgorithm.valueOf(
+            properties.getProperty(
+                "tvList_sort_algorithm", conf.getTvListSortAlgorithm().toString())));

Review Comment:
   fixed, move it to the function loadProperties in line 395.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #7290: [IOTDB-4431] Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r973889614


##########
server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java:
##########
@@ -1381,6 +1382,11 @@ private void loadTimedService(Properties properties) {
     if (unseqMemTableFlushCheckInterval > 0) {
       conf.setUnseqMemtableFlushCheckInterval(unseqMemTableFlushCheckInterval);
     }
+
+    conf.setTvListSortAlgorithm(
+        TVListSortAlgorithm.valueOf(
+            properties.getProperty(
+                "tvList_sort_algorithm", conf.getTvListSortAlgorithm().toString())));

Review Comment:
   Why added this in `loadTimedService` method?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou merged pull request #7290: [IOTDB-4431] Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HTHou merged PR #7290:
URL: https://github.com/apache/iotdb/pull/7290


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #7290: [IOTDB-4431] Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r973888129


##########
server/src/assembly/resources/conf/iotdb-datanode.properties:
##########
@@ -370,6 +370,12 @@ timestamp_precision=ms
 # Datatype: long
 # unseq_memtable_flush_check_interval_in_ms=600000
 
+# The sort algorithms used in the memtable's TVList
+# TIM: default tim sort,
+# QUICK: quick sort,
+# BACK: backward sort
+tvList_sort_algorithm=TIM

Review Comment:
   ```suggestion
   # tvlist_sort_algorithm=TIM
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HeimingZ commented on a diff in pull request #7290: Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HeimingZ commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r969217906


##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -70,17 +70,17 @@ public TVList() {
   public static TVList newList(TSDataType dataType) {
     switch (dataType) {
       case TEXT:
-        return new TimBinaryTVList();
+        return BinaryTVList.newList();
       case FLOAT:
-        return new TimFloatTVList();
+        return FloatTVList.newList();
       case INT32:
-        return new TimIntTVList();
+        return IntTVList.newList();
       case INT64:
-        return new TimLongTVList();
+        return LongTVList.newList();
       case DOUBLE:
-        return new TimDoubleTVList();
+        return DoubleTVList.newList();
       case BOOLEAN:
-        return new TimBooleanTVList();
+        return BooleanTVList.newList();
       default:
         break;
     }

Review Comment:
   Modify deserialize method like this.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TimAlignedTVList.java:
##########
@@ -73,39 +73,6 @@ public TVList getTvListByColumnIndex(List<Integer> columnIndex, List<TSDataType>
     return alignedTvList;
   }
 
-  @Override
-  public AlignedTVList clone() {

Review Comment:
   Move deserialize method to AlignedTVList.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java:
##########
@@ -46,6 +49,42 @@ public abstract class BinaryTVList extends TVList {
     values = new ArrayList<>();
   }
 
+  public static BinaryTVList newList() {
+    if (TVLIST_SORT_ALGORITHM == 1) {
+      return new QuickBinaryTVList();
+    }
+    return new TimBinaryTVList();
+  }
+
+  public static BinaryTVList deserialize(DataInputStream stream) throws IOException {
+    BinaryTVList tvList = BinaryTVList.newList();
+    int rowCount = stream.readInt();
+    long[] times = new long[rowCount];
+    Binary[] values = new Binary[rowCount];
+    for (int rowIdx = 0; rowIdx < rowCount; ++rowIdx) {
+      times[rowIdx] = stream.readLong();
+      values[rowIdx] = ReadWriteIOUtils.readBinary(stream);
+    }
+    tvList.putBinaries(times, values, null, 0, rowCount);
+    return tvList;
+  }

Review Comment:
   If user uses tim sort to serialize and uses quick sort to deserialize, this deserialization method will throw an exception. We should serialize sort type and choose different implementations when deserializing.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java:
##########
@@ -76,11 +77,44 @@ public abstract class AlignedTVList extends TVList {
   }
 
   public static AlignedTVList newAlignedList(List<TSDataType> dataTypes) {
+    if (TVLIST_SORT_ALGORITHM == 1) {
+      return new QuickAlignedTVList(dataTypes);
+    }
     return new TimAlignedTVList(dataTypes);
   }

Review Comment:
   Field dataTypes seems useless when initialization.



##########
server/src/assembly/resources/conf/iotdb-datanode.properties:
##########
@@ -370,6 +370,10 @@ timestamp_precision=ms
 # Datatype: long
 # unseq_memtable_flush_check_interval_in_ms=600000
 
+# The sort algorithms used in the memtable's TVList
+# 0: default tim sort, 1: quick, 2: backward
+tvList_sort_algorithm=0

Review Comment:
   It’s better to use enumeration here, you can refer to compaction_priority. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #7290: [IOTDB-4431] Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r974860500


##########
server/src/assembly/resources/conf/iotdb-datanode.properties:
##########
@@ -370,6 +370,12 @@ timestamp_precision=ms
 # Datatype: long
 # unseq_memtable_flush_check_interval_in_ms=600000
 
+# The sort algorithms used in the memtable's TVList
+# TIM: default tim sort,
+# QUICK: quick sort,
+# BACKWARD: backward sort
+tvlist_sort_algorithm=TIM

Review Comment:
   ```suggestion
   # tvlist_sort_algorithm=TIM
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HeimingZ commented on a diff in pull request #7290: Add QuickSort in TVList

Posted by GitBox <gi...@apache.org>.
HeimingZ commented on code in PR #7290:
URL: https://github.com/apache/iotdb/pull/7290#discussion_r969087301


##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java:
##########
@@ -76,11 +77,44 @@ public abstract class AlignedTVList extends TVList {
   }
 
   public static AlignedTVList newAlignedList(List<TSDataType> dataTypes) {
+    if (TVLIST_SORT_ALGORITHM == 1) {
+      return new QuickAlignedTVList(dataTypes);
+    }
     return new TimAlignedTVList(dataTypes);
   }

Review Comment:
   Field dataTypes seems useless when initialization.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org