diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertRowNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertRowNode.java index d62703a608c0..04bef0b577c3 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertRowNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertRowNode.java @@ -151,7 +151,14 @@ public PlanNode clone() { @Override public String toString() { - return "InsertRowNode{" + "time=" + time + ", values=" + Arrays.toString(values) + '}'; + return "InsertRowNode{" + + "insertTarget=" + + targetPath + + ", time=" + + time + + ", values=" + + Arrays.toString(values) + + '}'; } @Override diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java index a9695475a184..c8b840cc6bba 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java @@ -1300,4 +1300,21 @@ public void updateLastCache(final String databaseName) { isAligned, measurementSchemas); } + + @Override + public String toString() { + return "InsertTabletNode{" + + "targetPath=" + + targetPath + + ", measurements=" + + Arrays.toString(measurements) + + ", rowCount=" + + rowCount + + ", timeRange=[," + + times[0] + + ", " + + times[times.length - 1] + + "]" + + '}'; + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/WALEntry.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/WALEntry.java index bb5969dde9d4..88cfb8b1564e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/WALEntry.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/WALEntry.java @@ -198,4 +198,9 @@ public WALFlushListener getWalFlushListener() { public abstract boolean isSignal(); public abstract long getMemorySize(); + + @Override + public String toString() { + return "WALEntry{" + "type=" + type + ", memTableId=" + memTableId + ", value=" + value + '}'; + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALInputStream.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALInputStream.java index e3f544a88944..aee0d9449733 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALInputStream.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALInputStream.java @@ -216,47 +216,58 @@ private void loadNextSegmentV1() throws IOException { } private void loadNextSegmentV2() throws IOException { + long position = channel.position(); SegmentInfo segmentInfo = getNextSegmentInfo(); - if (segmentInfo.compressionType != CompressionType.UNCOMPRESSED) { - // A compressed segment - if (Objects.isNull(dataBuffer) - || dataBuffer.capacity() < segmentInfo.uncompressedSize - || dataBuffer.capacity() > segmentInfo.uncompressedSize * 2) { - MmapUtil.clean(dataBuffer); - dataBuffer = ByteBuffer.allocateDirect(segmentInfo.uncompressedSize); - } - dataBuffer.clear(); + try { + if (segmentInfo.compressionType != CompressionType.UNCOMPRESSED) { + // A compressed segment + if (Objects.isNull(dataBuffer) + || dataBuffer.capacity() < segmentInfo.uncompressedSize + || dataBuffer.capacity() > segmentInfo.uncompressedSize * 2) { + MmapUtil.clean(dataBuffer); + dataBuffer = ByteBuffer.allocateDirect(segmentInfo.uncompressedSize); + } + dataBuffer.clear(); - if (Objects.isNull(compressedBuffer) - || compressedBuffer.capacity() < segmentInfo.dataInDiskSize - || compressedBuffer.capacity() > segmentInfo.dataInDiskSize * 2) { - MmapUtil.clean(compressedBuffer); - compressedBuffer = ByteBuffer.allocateDirect(segmentInfo.dataInDiskSize); - } - compressedBuffer.clear(); - // limit the buffer to prevent it from reading too much byte than expected - compressedBuffer.limit(segmentInfo.dataInDiskSize); - if (readWALBufferFromChannel(compressedBuffer) != segmentInfo.dataInDiskSize) { - throw new IOException("Unexpected end of file"); - } - compressedBuffer.flip(); - IUnCompressor unCompressor = IUnCompressor.getUnCompressor(segmentInfo.compressionType); - uncompressWALBuffer(compressedBuffer, dataBuffer, unCompressor); - } else { - // An uncompressed segment - if (Objects.isNull(dataBuffer) - || dataBuffer.capacity() < segmentInfo.dataInDiskSize - || dataBuffer.capacity() > segmentInfo.dataInDiskSize * 2) { - MmapUtil.clean(dataBuffer); - dataBuffer = ByteBuffer.allocateDirect(segmentInfo.dataInDiskSize); - } - dataBuffer.clear(); - // limit the buffer to prevent it from reading too much byte than expected - dataBuffer.limit(segmentInfo.dataInDiskSize); + if (Objects.isNull(compressedBuffer) + || compressedBuffer.capacity() < segmentInfo.dataInDiskSize + || compressedBuffer.capacity() > segmentInfo.dataInDiskSize * 2) { + MmapUtil.clean(compressedBuffer); + compressedBuffer = ByteBuffer.allocateDirect(segmentInfo.dataInDiskSize); + } + compressedBuffer.clear(); + // limit the buffer to prevent it from reading too much byte than expected + compressedBuffer.limit(segmentInfo.dataInDiskSize); + if (readWALBufferFromChannel(compressedBuffer) != segmentInfo.dataInDiskSize) { + throw new IOException("Unexpected end of file"); + } + compressedBuffer.flip(); + IUnCompressor unCompressor = IUnCompressor.getUnCompressor(segmentInfo.compressionType); + uncompressWALBuffer(compressedBuffer, dataBuffer, unCompressor); + } else { + // An uncompressed segment + if (Objects.isNull(dataBuffer) + || dataBuffer.capacity() < segmentInfo.dataInDiskSize + || dataBuffer.capacity() > segmentInfo.dataInDiskSize * 2) { + MmapUtil.clean(dataBuffer); + dataBuffer = ByteBuffer.allocateDirect(segmentInfo.dataInDiskSize); + } + dataBuffer.clear(); + // limit the buffer to prevent it from reading too much byte than expected + dataBuffer.limit(segmentInfo.dataInDiskSize); - if (readWALBufferFromChannel(dataBuffer) != segmentInfo.dataInDiskSize) { - throw new IOException("Unexpected end of file"); + if (readWALBufferFromChannel(dataBuffer) != segmentInfo.dataInDiskSize) { + throw new IOException("Unexpected end of file"); + } } + } catch (Exception e) { + logger.error( + "Unexpected error when loading a wal segment {} in {}@{}", + segmentInfo, + logFile, + position, + e); + throw new IOException(e); } dataBuffer.flip(); } @@ -389,5 +400,17 @@ int headerSize() { ? Byte.BYTES + Integer.BYTES : Byte.BYTES + Integer.BYTES * 2; } + + @Override + public String toString() { + return "SegmentInfo{" + + "compressionType=" + + compressionType + + ", dataInDiskSize=" + + dataInDiskSize + + ", uncompressedSize=" + + uncompressedSize + + '}'; + } } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALEntryPosition.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALEntryPosition.java index 1370745cea24..a5622d29c490 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALEntryPosition.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALEntryPosition.java @@ -25,6 +25,8 @@ import org.apache.iotdb.db.storageengine.dataregion.wal.node.WALNode; import org.apache.tsfile.utils.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -38,6 +40,9 @@ * and give some methods to read the content from the disk. */ public class WALEntryPosition { + + private static final Logger LOGGER = LoggerFactory.getLogger(WALEntryPosition.class); + private volatile String identifier = ""; private volatile long walFileVersionId = -1; private volatile long position; @@ -107,6 +112,14 @@ ByteBuffer read() throws IOException { ByteBuffer buffer = ByteBuffer.allocate(size); is.read(buffer); return buffer; + } catch (Exception e) { + LOGGER.error( + "Unexpected error when reading a wal entry from {}@{} with size {}", + walFile, + position, + size, + e); + throw new IOException(e); } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALPrintTool.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALPrintTool.java new file mode 100644 index 000000000000..99f27fbd6ac0 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALPrintTool.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.storageengine.dataregion.wal.utils;
+
+import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntry;
+import org.apache.iotdb.db.storageengine.dataregion.wal.io.WALReader;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Stack;
+
+public class WALPrintTool {
+
+ public void print(File file) throws IOException {
+ Stack