You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2020/06/17 02:54:15 UTC
[incubator-iotdb] 01/01: no last in restart
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch MTreeReplayBug
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 7180b58e58e722fe289134370296507a3d6eb471
Author: JackieTien97 <Ja...@foxmail.com>
AuthorDate: Wed Jun 17 10:53:48 2020 +0800
no last in restart
---
.../java/org/apache/iotdb/db/metadata/MTree.java | 63 +++++++++++-----------
1 file changed, 33 insertions(+), 30 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index 286408c..612a2f8 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -130,7 +130,8 @@ public class MTree implements Serializable {
if (alias != null && cur.hasChild(alias)) {
throw new AliasAlreadyExistException(path, alias);
}
- MeasurementMNode leaf = new MeasurementMNode(cur, leafName, alias, dataType, encoding, compressor, props);
+ MeasurementMNode leaf = new MeasurementMNode(cur, leafName, alias, dataType, encoding,
+ compressor, props);
cur.addChild(leafName, leaf);
// link alias to LeafMNode
if (alias != null) {
@@ -607,7 +608,7 @@ public class MTree implements Serializable {
if (child instanceof MeasurementMNode) {
cnt++;
}
- cnt += getCount(child, nodes, idx + 1);
+ cnt += getCount(child, nodes, idx + 1);
}
return cnt;
}
@@ -644,7 +645,7 @@ public class MTree implements Serializable {
}
List<String[]> allMatchedNodes = new ArrayList<>();
- findPath(root, nodes, 1, "", allMatchedNodes, false);
+ findPath(root, nodes, 1, "", allMatchedNodes, false, true);
Stream<String[]> sortedStream = allMatchedNodes.stream().sorted(
Comparator.comparingLong((String[] s) -> Long.parseLong(s[7])).reversed()
@@ -676,10 +677,10 @@ public class MTree implements Serializable {
count.set(0);
if (offset.get() != 0 || limit.get() != 0) {
res = new LinkedList<>();
- findPath(root, nodes, 1, "", res, true);
+ findPath(root, nodes, 1, "", res, true, false);
} else {
res = new LinkedList<>();
- findPath(root, nodes, 1, "", res, false);
+ findPath(root, nodes, 1, "", res, false, false);
}
// avoid memory leaks
limit.remove();
@@ -692,11 +693,13 @@ public class MTree implements Serializable {
/**
* Iterate through MTree to fetch metadata info of all leaf nodes under the given seriesPath
*
- * @param timeseriesSchemaList List<timeseriesSchema>
- * result: [name, alias, storage group, dataType, encoding, compression, offset, lastTimeStamp]
+ * @param needLast if false, lastTimeStamp in timeseriesSchemaList will be null
+ * @param timeseriesSchemaList List<timeseriesSchema> result: [name, alias, storage group,
+ * dataType, encoding, compression, offset, lastTimeStamp]
*/
private void findPath(MNode node, String[] nodes, int idx, String parent,
- List<String[]> timeseriesSchemaList, boolean hasLimit) throws MetadataException {
+ List<String[]> timeseriesSchemaList, boolean hasLimit, boolean needLast)
+ throws MetadataException {
if (node instanceof MeasurementMNode && nodes.length <= idx) {
if (hasLimit) {
curOffset.set(curOffset.get() + 1);
@@ -708,30 +711,30 @@ public class MTree implements Serializable {
if (node.getName().contains(TsFileConstant.PATH_SEPARATOR)) {
nodeName = "\"" + node + "\"";
} else {
- nodeName = node.getName();
- }
- String nodePath = parent + nodeName;
- String[] tsRow = new String[8];
- tsRow[0] = nodePath;
- tsRow[1] = ((MeasurementMNode) node).getAlias();
- MeasurementSchema measurementSchema = ((MeasurementMNode) node).getSchema();
- tsRow[2] = getStorageGroupName(nodePath);
- tsRow[3] = measurementSchema.getType().toString();
- tsRow[4] = measurementSchema.getEncodingType().toString();
- tsRow[5] = measurementSchema.getCompressor().toString();
- tsRow[6] = String.valueOf(((MeasurementMNode) node).getOffset());
- tsRow[7] = String.valueOf(getLastTimeStamp((MeasurementMNode) node));
+ nodeName = node.getName();
+ }
+ String nodePath = parent + nodeName;
+ String[] tsRow = new String[8];
+ tsRow[0] = nodePath;
+ tsRow[1] = ((MeasurementMNode) node).getAlias();
+ MeasurementSchema measurementSchema = ((MeasurementMNode) node).getSchema();
+ tsRow[2] = getStorageGroupName(nodePath);
+ tsRow[3] = measurementSchema.getType().toString();
+ tsRow[4] = measurementSchema.getEncodingType().toString();
+ tsRow[5] = measurementSchema.getCompressor().toString();
+ tsRow[6] = String.valueOf(((MeasurementMNode) node).getOffset());
+ tsRow[7] = needLast ? String.valueOf(getLastTimeStamp((MeasurementMNode) node)) : null;
timeseriesSchemaList.add(tsRow);
- if (hasLimit) {
- count.set(count.get() + 1);
- }
+ if (hasLimit) {
+ count.set(count.get() + 1);
+ }
}
String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes);
if (!nodeReg.contains(PATH_WILDCARD)) {
if (node.hasChild(nodeReg)) {
findPath(node.getChild(nodeReg), nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR,
- timeseriesSchemaList, hasLimit);
+ timeseriesSchemaList, hasLimit, needLast);
}
} else {
for (MNode child : node.getChildren().values()) {
@@ -739,7 +742,7 @@ public class MTree implements Serializable {
continue;
}
findPath(child, nodes, idx + 1, parent + node.getName() + PATH_SEPARATOR,
- timeseriesSchemaList, hasLimit);
+ timeseriesSchemaList, hasLimit, needLast);
}
}
}
@@ -840,10 +843,10 @@ public class MTree implements Serializable {
/**
* Traverse the MTree to match all devices with prefix path.
*
- * @param node the current traversing node
- * @param nodes split the prefix path with '.'
- * @param idx the current index of array nodes
- * @param res store all matched device names
+ * @param node the current traversing node
+ * @param nodes split the prefix path with '.'
+ * @param idx the current index of array nodes
+ * @param res store all matched device names
*/
private void findDevices(MNode node, String[] nodes, int idx, Set<String> res) {
String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes);