You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2022/09/01 13:20:36 UTC
[iotdb] branch ml_add_peer updated: test SnapshotFragmentReader done
This is an automated email from the ASF dual-hosted git repository.
xingtanzjr pushed a commit to branch ml_add_peer
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ml_add_peer by this push:
new fd42c7c87a test SnapshotFragmentReader done
fd42c7c87a is described below
commit fd42c7c87a93c0c643a4d15a33dcd38017e4de08
Author: Jinrui.Zhang <xi...@gmail.com>
AuthorDate: Thu Sep 1 21:20:13 2022 +0800
test SnapshotFragmentReader done
---
.../multileader/snapshot/SnapshotFragment.java | 69 ++++++++++------------
.../snapshot/SnapshotFragmentReader.java | 17 ++----
2 files changed, 36 insertions(+), 50 deletions(-)
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragment.java b/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragment.java
index 581b56dd26..ea042966ad 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragment.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragment.java
@@ -24,67 +24,58 @@ import org.apache.iotdb.consensus.multileader.thrift.TSendSnapshotFragmentReq;
import java.nio.ByteBuffer;
public class SnapshotFragment {
- private String snapshotId;
- private String filePath;
- private long totalSize;
- private long startOffset;
- private long fragmentSize;
- private ByteBuffer fileChunk;
+ private final String snapshotId;
+ private final String filePath;
+ private final long totalSize;
+ private final long startOffset;
+ private final long fragmentSize;
+ private final ByteBuffer fileChunk;
+
+ public SnapshotFragment(
+ String snapshotId,
+ String filePath,
+ long totalSize,
+ long startOffset,
+ long fragmentSize,
+ ByteBuffer fileChunk) {
+ this.snapshotId = snapshotId;
+ this.filePath = filePath;
+ this.totalSize = totalSize;
+ this.startOffset = startOffset;
+ this.fragmentSize = fragmentSize;
+ this.fileChunk = fileChunk;
+ }
- public String getSnapshotId() {
- return snapshotId;
+ public TSendSnapshotFragmentReq toTSendSnapshotFragmentReq() {
+ TSendSnapshotFragmentReq req = new TSendSnapshotFragmentReq();
+ req.setSnapshotId(snapshotId);
+ req.setFilePath(filePath);
+ req.setChunkLength(fragmentSize);
+ req.setFileChunk(fileChunk);
+ return req;
}
- public void setSnapshotId(String snapshotId) {
- this.snapshotId = snapshotId;
+ public String getSnapshotId() {
+ return snapshotId;
}
public String getFilePath() {
return filePath;
}
- public void setFilePath(String filePath) {
- this.filePath = filePath;
- }
-
public long getTotalSize() {
return totalSize;
}
- public void setTotalSize(long totalSize) {
- this.totalSize = totalSize;
- }
-
public long getStartOffset() {
return startOffset;
}
- public void setStartOffset(long startOffset) {
- this.startOffset = startOffset;
- }
-
public long getFragmentSize() {
return fragmentSize;
}
- public void setFragmentSize(long fragmentSize) {
- this.fragmentSize = fragmentSize;
- }
-
public ByteBuffer getFileChunk() {
return fileChunk;
}
-
- public void setFileChunk(ByteBuffer fileChunk) {
- this.fileChunk = fileChunk;
- }
-
- public TSendSnapshotFragmentReq toTSendSnapshotFragmentReq() {
- TSendSnapshotFragmentReq req = new TSendSnapshotFragmentReq();
- req.setSnapshotId(snapshotId);
- req.setFilePath(filePath);
- req.setChunkLength(fragmentSize);
- req.setFileChunk(fileChunk);
- return req;
- }
}
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragmentReader.java b/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragmentReader.java
index 6dcddbf4b6..1509995aff 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragmentReader.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/multileader/snapshot/SnapshotFragmentReader.java
@@ -31,15 +31,15 @@ public class SnapshotFragmentReader {
private final String snapshotId;
private final String filePath;
private final SeekableByteChannel fileChannel;
- private final long totalSize;
+ private final long fileSize;
private final ByteBuffer buf;
- private long readSize;
+ private long totalReadSize;
private SnapshotFragment cachedSnapshotFragment;
public SnapshotFragmentReader(String snapshotId, Path path) throws IOException {
this.snapshotId = snapshotId;
this.filePath = path.toAbsolutePath().toString();
- this.totalSize = Files.size(path);
+ this.fileSize = Files.size(path);
this.fileChannel = Files.newByteChannel(path);
this.buf = ByteBuffer.allocate(DEFAULT_FILE_FRAGMENT_SIZE);
}
@@ -49,14 +49,9 @@ public class SnapshotFragmentReader {
int actualReadSize = fileChannel.read(buf);
buf.flip();
if (actualReadSize > 0) {
- cachedSnapshotFragment = new SnapshotFragment();
- cachedSnapshotFragment.setSnapshotId(snapshotId);
- cachedSnapshotFragment.setFilePath(filePath);
- cachedSnapshotFragment.setTotalSize(totalSize);
- cachedSnapshotFragment.setFragmentSize(actualReadSize);
- cachedSnapshotFragment.setStartOffset(readSize);
- cachedSnapshotFragment.setFileChunk(buf);
- readSize += actualReadSize;
+ cachedSnapshotFragment =
+ new SnapshotFragment(snapshotId, filePath, fileSize, totalReadSize, actualReadSize, buf);
+ totalReadSize += actualReadSize;
return true;
}
return false;