OneSizeFitsQuorum commented on code in PR #13050:
URL: https://github.com/apache/iotdb/pull/13050#discussion_r1695085446
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALByteBufReader.java:
##########
@@ -20,38 +20,46 @@
package org.apache.iotdb.db.storageengine.dataregion.wal.io;
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntry;
+import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALEntryPosition;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.file.StandardOpenOption;
import java.util.Iterator;
/**
* This reader returns {@link WALEntry} as {@link ByteBuffer}, the usage of
WALByteBufReader is like
* {@link Iterator}.
*/
public class WALByteBufReader implements Closeable {
- private final File logFile;
- private final FileChannel channel;
- private final WALMetaData metaData;
- private final DataInputStream logStream;
- private final Iterator<Integer> sizeIterator;
+ private WALMetaData metaData;
+ private DataInputStream logStream;
+ private Iterator<Integer> sizeIterator;
public WALByteBufReader(File logFile) throws IOException {
- this(logFile, FileChannel.open(logFile.toPath(), StandardOpenOption.READ));
+ WALInputStream walInputStream = new WALInputStream(logFile);
Review Comment:
try-with-resource?
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALByteBufReader.java:
##########
@@ -20,38 +20,46 @@
package org.apache.iotdb.db.storageengine.dataregion.wal.io;
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntry;
+import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALEntryPosition;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.file.StandardOpenOption;
import java.util.Iterator;
/**
* This reader returns {@link WALEntry} as {@link ByteBuffer}, the usage of
WALByteBufReader is like
* {@link Iterator}.
*/
public class WALByteBufReader implements Closeable {
- private final File logFile;
- private final FileChannel channel;
- private final WALMetaData metaData;
- private final DataInputStream logStream;
- private final Iterator<Integer> sizeIterator;
+ private WALMetaData metaData;
+ private DataInputStream logStream;
+ private Iterator<Integer> sizeIterator;
public WALByteBufReader(File logFile) throws IOException {
- this(logFile, FileChannel.open(logFile.toPath(), StandardOpenOption.READ));
+ WALInputStream walInputStream = new WALInputStream(logFile);
+ try {
+ this.logStream = new DataInputStream(walInputStream);
+ this.metaData = walInputStream.getWALMetaData();
+ this.sizeIterator = metaData.getBuffersSize().iterator();
+ } catch (Exception e) {
+ walInputStream.close();
+ throw e;
+ }
}
- public WALByteBufReader(File logFile, FileChannel channel) throws
IOException {
- this.logFile = logFile;
- this.channel = channel;
- this.logStream = new DataInputStream(new WALInputStream(logFile));
- this.metaData = WALMetaData.readFromWALFile(logFile, channel);
- this.sizeIterator = metaData.getBuffersSize().iterator();
- channel.position(0);
+ public WALByteBufReader(WALEntryPosition walEntryPosition) throws
IOException {
+ WALInputStream walInputStream = walEntryPosition.openReadFileStream();
Review Comment:
same as above
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALInputStream.java:
##########
@@ -60,10 +60,15 @@ public class WALInputStream extends InputStream implements
AutoCloseable {
public WALInputStream(File logFile) throws IOException {
channel = FileChannel.open(logFile.toPath());
- fileSize = channel.size();
this.logFile = logFile;
- analyzeFileVersion();
- getEndOffset();
+ try {
+ fileSize = channel.size();
+ analyzeFileVersion();
+ getEndOffset();
+ } catch (Exception e) {
+ channel.close();
Review Comment:
if we use try-with-resource for all it's caller or caller's caller, maybe we
do not need this ?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]