Skip to content

Commit 5cccdab

Browse files
committed
adjust according to review
1 parent f004858 commit 5cccdab

5 files changed

Lines changed: 26 additions & 30 deletions

File tree

example/tsfile/src/main/java/org/apache/iotdb/tsfile/TsFileSequenceRead.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class TsFileSequenceRead {
5353
"squid:S106"
5454
}) // Suppress high Cognitive Complexity and Standard outputs warning
5555
public static void main(String[] args) throws IOException {
56-
String filename = "C:\\Users\\MARKLAU\\Desktop\\13-13-0-0.tsfile";
56+
String filename = "test.tsfile";
5757
if (args.length >= 1) {
5858
filename = args[0];
5959
}

server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,10 @@ public void removeModFile() throws IOException {
506506
modFile = null;
507507
}
508508

509-
/** Remove the data file, its resource file, and its modification file physically. */
509+
/**
510+
* Remove the data file, its resource file, its chunk metadata temp file, and its modification
511+
* file physically.
512+
*/
510513
public boolean remove() {
511514
try {
512515
fsFactory.deleteIfExists(file);

tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/TsFileIOWriter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class TsFileIOWriter implements AutoCloseable {
114114
// record the total num of path in order to make bloom filter
115115
protected int pathCount = 0;
116116
protected boolean enableMemoryControl = false;
117-
Path lastSerializePath = null;
117+
private Path lastSerializePath = null;
118118
protected LinkedList<Long> endPosInCMTForDevice = new LinkedList<>();
119119
public static final String CHUNK_METADATA_TEMP_FILE_SUFFIX = ".cmt";
120120

@@ -625,16 +625,15 @@ protected void sortAndFlushChunkMetadata() throws IOException {
625625
tempOutput = new LocalTsFileOutput(new FileOutputStream(chunkMetadataTempFile));
626626
}
627627
hasChunkMetadataInDisk = true;
628-
// the file structure in temp file will be
629-
// chunkSize | chunkBuffer
630628
for (Pair<Path, List<IChunkMetadata>> pair : sortedChunkMetadataList) {
631629
Path seriesPath = pair.left;
632-
if (!seriesPath.equals(lastSerializePath)) {
630+
boolean isNewPath = !seriesPath.equals(lastSerializePath);
631+
if (isNewPath) {
633632
// record the count of path to construct bloom filter later
634633
pathCount++;
635634
}
636635
List<IChunkMetadata> iChunkMetadataList = pair.right;
637-
writeChunkMetadataToTempFile(iChunkMetadataList, seriesPath);
636+
writeChunkMetadataToTempFile(iChunkMetadataList, seriesPath, isNewPath);
638637
lastSerializePath = seriesPath;
639638
logger.debug("Flushing {}", seriesPath);
640639
}
@@ -646,7 +645,8 @@ protected void sortAndFlushChunkMetadata() throws IOException {
646645
}
647646

648647
private void writeChunkMetadataToTempFile(
649-
List<IChunkMetadata> iChunkMetadataList, Path seriesPath) throws IOException {
648+
List<IChunkMetadata> iChunkMetadataList, Path seriesPath, boolean isNewPath)
649+
throws IOException {
650650
// [DeviceId] measurementId datatype size chunkMetadataBuffer
651651
if (lastSerializePath == null
652652
|| !seriesPath.getDevice().equals(lastSerializePath.getDevice())) {
@@ -656,7 +656,7 @@ private void writeChunkMetadataToTempFile(
656656
// for each device, we only serialize it once, in order to save io
657657
ReadWriteIOUtils.write(seriesPath.getDevice(), tempOutput.wrapAsStream());
658658
}
659-
if (!seriesPath.equals(lastSerializePath) && iChunkMetadataList.size() > 0) {
659+
if (isNewPath && iChunkMetadataList.size() > 0) {
660660
// serialize the public info of this measurement
661661
ReadWriteIOUtils.writeVar(seriesPath.getMeasurement(), tempOutput.wrapAsStream());
662662
ReadWriteIOUtils.write(iChunkMetadataList.get(0).getDataType(), tempOutput.wrapAsStream());

tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/tsmiterator/DiskTSMIterator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ public class DiskTSMIterator extends TSMIterator {
4747

4848
private static final Logger LOG = LoggerFactory.getLogger(DiskTSMIterator.class);
4949

50-
LinkedList<Long> endPosForEachDevice;
51-
File cmtFile;
52-
LocalTsFileInput input;
53-
long fileLength = 0;
54-
long currentPos = 0;
55-
long nextEndPosForDevice = 0;
56-
String currentDevice;
57-
boolean remainsInFile = true;
50+
private LinkedList<Long> endPosForEachDevice;
51+
private File cmtFile;
52+
private LocalTsFileInput input;
53+
private long fileLength = 0;
54+
private long currentPos = 0;
55+
private long nextEndPosForDevice = 0;
56+
private String currentDevice;
57+
private boolean remainsInFile = true;
5858

5959
protected DiskTSMIterator(
6060
File cmtFile,

tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/tsmiterator/TSMIterator.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
* source from memory or disk. Static method getTSMIteratorInMemory returns a TSMIterator that reads
4646
* from memory, and static method getTSMIteratorInDisk returns a TSMIterator that reads from disk.
4747
*/
48-
public class TSMIterator implements Iterator<Pair<String, TimeseriesMetadata>> {
49-
private static Logger LOG = LoggerFactory.getLogger(TSMIterator.class);
48+
public class TSMIterator {
49+
private static final Logger LOG = LoggerFactory.getLogger(TSMIterator.class);
5050
protected List<Pair<Path, List<IChunkMetadata>>> sortedChunkMetadataList;
5151
protected Iterator<Pair<Path, List<IChunkMetadata>>> iterator;
5252

@@ -66,22 +66,15 @@ public static TSMIterator getTSMIteratorInDisk(
6666
return new DiskTSMIterator(cmtFile, chunkGroupMetadataList, serializePos);
6767
}
6868

69-
@Override
7069
public boolean hasNext() {
7170
return iterator.hasNext();
7271
}
7372

74-
@Override
75-
public Pair<String, TimeseriesMetadata> next() {
73+
public Pair<String, TimeseriesMetadata> next() throws IOException {
7674
Pair<Path, List<IChunkMetadata>> nextPair = iterator.next();
77-
try {
78-
return new Pair<>(
79-
nextPair.left.getFullPath(),
80-
constructOneTimeseriesMetadata(nextPair.left.getMeasurement(), nextPair.right));
81-
} catch (IOException e) {
82-
LOG.error("Meets IOException when getting next TimeseriesMetadata", e);
83-
return null;
84-
}
75+
return new Pair<>(
76+
nextPair.left.getFullPath(),
77+
constructOneTimeseriesMetadata(nextPair.left.getMeasurement(), nextPair.right));
8578
}
8679

8780
public static TimeseriesMetadata constructOneTimeseriesMetadata(

0 commit comments

Comments
 (0)