This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 890020d Add javadoc for UDF framework (#4225)
890020d is described below
commit 890020db0e991e74b6f845e3b042a8d13e852352
Author: Zhong Wang <[email protected]>
AuthorDate: Mon Oct 25 18:15:19 2021 +0800
Add javadoc for UDF framework (#4225)
---
.../iotdb/db/query/udf/core/layer/SafetyLine.java | 3 ++
.../row/ElasticSerializableRowRecordList.java | 33 ++++++++++++++--------
.../row/SerializableRowRecordList.java | 8 ++++++
3 files changed, 32 insertions(+), 12 deletions(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/query/udf/core/layer/SafetyLine.java
b/server/src/main/java/org/apache/iotdb/db/query/udf/core/layer/SafetyLine.java
index 35be04d..9f36b05 100644
---
a/server/src/main/java/org/apache/iotdb/db/query/udf/core/layer/SafetyLine.java
+++
b/server/src/main/java/org/apache/iotdb/db/query/udf/core/layer/SafetyLine.java
@@ -19,6 +19,9 @@
package org.apache.iotdb.db.query.udf.core.layer;
+import
org.apache.iotdb.db.query.udf.datastructure.tv.ElasticSerializableTVList;
+
+/** Tells the {@link ElasticSerializableTVList} if it is safe to remove a
cache block. */
public class SafetyLine {
public static final int INITIAL_PILE_POSITION = -1;
diff --git
a/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/ElasticSerializableRowRecordList.java
b/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/ElasticSerializableRowRecordList.java
index 7171ca1..8484f74 100644
---
a/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/ElasticSerializableRowRecordList.java
+++
b/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/ElasticSerializableRowRecordList.java
@@ -30,6 +30,7 @@ import java.util.List;
import static
org.apache.iotdb.db.query.udf.datastructure.SerializableList.INITIAL_BYTE_ARRAY_LENGTH_FOR_MEMORY_CONTROL;
+/** An elastic list of records that implements memory control using LRU
strategy. */
public class ElasticSerializableRowRecordList {
protected static final int MEMORY_CHECK_THRESHOLD = 1000;
@@ -38,7 +39,7 @@ public class ElasticSerializableRowRecordList {
protected long queryId;
protected float memoryLimitInMB;
protected int internalRowRecordListCapacity;
- protected int cacheSize;
+ protected int numCacheBlock;
protected LRUCache cache;
protected List<SerializableRowRecordList> rowRecordLists;
@@ -51,8 +52,16 @@ public class ElasticSerializableRowRecordList {
protected long totalByteArrayLengthLimit;
protected long totalByteArrayLength;
+ /**
+ * Construct a ElasticSerializableRowRecordList.
+ *
+ * @param dataTypes Data types of columns.
+ * @param queryId Query ID.
+ * @param memoryLimitInMB Memory limit.
+ * @param numCacheBlock Number of cache blocks.
+ */
public ElasticSerializableRowRecordList(
- TSDataType[] dataTypes, long queryId, float memoryLimitInMB, int
cacheSize)
+ TSDataType[] dataTypes, long queryId, float memoryLimitInMB, int
numCacheBlock)
throws QueryProcessException {
this.dataTypes = dataTypes;
this.queryId = queryId;
@@ -60,14 +69,14 @@ public class ElasticSerializableRowRecordList {
int allocatableCapacity =
SerializableRowRecordList.calculateCapacity(
dataTypes, memoryLimitInMB,
INITIAL_BYTE_ARRAY_LENGTH_FOR_MEMORY_CONTROL);
- internalRowRecordListCapacity = allocatableCapacity / cacheSize;
+ internalRowRecordListCapacity = allocatableCapacity / numCacheBlock;
if (internalRowRecordListCapacity == 0) {
- cacheSize = 1;
+ numCacheBlock = 1;
internalRowRecordListCapacity = allocatableCapacity;
}
- this.cacheSize = cacheSize;
+ this.numCacheBlock = numCacheBlock;
- cache = new ElasticSerializableRowRecordList.LRUCache(cacheSize);
+ cache = new ElasticSerializableRowRecordList.LRUCache(numCacheBlock);
rowRecordLists = new ArrayList<>();
size = 0;
evictionUpperBound = 0;
@@ -97,14 +106,14 @@ public class ElasticSerializableRowRecordList {
long queryId,
float memoryLimitInMB,
int internalRowRecordListCapacity,
- int cacheSize) {
+ int numCacheBlock) {
this.dataTypes = dataTypes;
this.queryId = queryId;
this.memoryLimitInMB = memoryLimitInMB;
this.internalRowRecordListCapacity = internalRowRecordListCapacity;
- this.cacheSize = cacheSize;
+ this.numCacheBlock = numCacheBlock;
- cache = new ElasticSerializableRowRecordList.LRUCache(cacheSize);
+ cache = new ElasticSerializableRowRecordList.LRUCache(numCacheBlock);
rowRecordLists = new ArrayList<>();
size = 0;
evictionUpperBound = 0;
@@ -174,7 +183,7 @@ public class ElasticSerializableRowRecordList {
int newInternalTVListCapacity =
SerializableRowRecordList.calculateCapacity(
dataTypes, memoryLimitInMB, newByteArrayLengthForMemoryControl)
- / cacheSize;
+ / numCacheBlock;
if (0 < newInternalTVListCapacity) {
applyNewMemoryControlParameters(
newByteArrayLengthForMemoryControl, newInternalTVListCapacity);
@@ -193,7 +202,7 @@ public class ElasticSerializableRowRecordList {
newInternalTVListCapacity =
SerializableRowRecordList.calculateCapacity(
dataTypes, memoryLimitInMB, newByteArrayLengthForMemoryControl)
- / cacheSize;
+ / numCacheBlock;
if (0 < newInternalTVListCapacity) {
applyNewMemoryControlParameters(
newByteArrayLengthForMemoryControl, newInternalTVListCapacity);
@@ -208,7 +217,7 @@ public class ElasticSerializableRowRecordList {
throws IOException, QueryProcessException {
ElasticSerializableRowRecordList newElasticSerializableRowRecordList =
new ElasticSerializableRowRecordList(
- dataTypes, queryId, memoryLimitInMB,
newInternalRowRecordListCapacity, cacheSize);
+ dataTypes, queryId, memoryLimitInMB,
newInternalRowRecordListCapacity, numCacheBlock);
newElasticSerializableRowRecordList.evictionUpperBound =
evictionUpperBound;
int internalListEvictionUpperBound = evictionUpperBound /
newInternalRowRecordListCapacity;
diff --git
a/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/SerializableRowRecordList.java
b/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/SerializableRowRecordList.java
index cf63e72..8a76056 100644
---
a/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/SerializableRowRecordList.java
+++
b/server/src/main/java/org/apache/iotdb/db/query/udf/datastructure/row/SerializableRowRecordList.java
@@ -45,6 +45,14 @@ public class SerializableRowRecordList implements
SerializableList {
return new SerializableRowRecordList(recorder, dataTypes,
internalRowRecordListCapacity);
}
+ /**
+ * Calculate the number of rows that can be cached given the memory limit.
+ *
+ * @param dataTypes Data types of columns.
+ * @param memoryLimitInMB Memory limit.
+ * @param byteArrayLengthForMemoryControl Max memory usage for a {@link
TSDataType#TEXT}.
+ * @return Number of rows that can be cached.
+ */
protected static int calculateCapacity(
TSDataType[] dataTypes, float memoryLimitInMB, int
byteArrayLengthForMemoryControl)
throws QueryProcessException {