This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new a69f3fb9 RATIS-1627. InstallSnapshotRequests add properties : 
totalSize (#684)
a69f3fb9 is described below

commit a69f3fb9aca07264274f46d2b4986188b3f0fb1a
Author: jiangyuan <[email protected]>
AuthorDate: Tue Jul 19 13:07:38 2022 +0800

    RATIS-1627. InstallSnapshotRequests add properties : totalSize (#684)
---
 .../org/apache/ratis/server/leader/InstallSnapshotRequests.java     | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/leader/InstallSnapshotRequests.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/leader/InstallSnapshotRequests.java
index 3455862b..38d1f9a2 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/leader/InstallSnapshotRequests.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/leader/InstallSnapshotRequests.java
@@ -51,6 +51,8 @@ class InstallSnapshotRequests implements 
Iterable<InstallSnapshotRequestProto> {
 
   /** Maximum chunk size. */
   private final int snapshotChunkMaxSize;
+  /** The total size of snapshot files. */
+  private final long totalSize;
 
   /** The index of the current request. */
   private int requestIndex = 0;
@@ -67,6 +69,8 @@ class InstallSnapshotRequests implements 
Iterable<InstallSnapshotRequestProto> {
     this.requestId = requestId;
     this.snapshot = snapshot;
     this.snapshotChunkMaxSize = snapshotChunkMaxSize;
+    this.totalSize = 
snapshot.getFiles().stream().mapToLong(FileInfo::getFileSize).reduce(Long::sum).orElseThrow(
+            () -> new IllegalStateException("Failed to compute total size for 
snapshot " + snapshot));
   }
 
   @Override
@@ -117,8 +121,6 @@ class InstallSnapshotRequests implements 
Iterable<InstallSnapshotRequestProto> {
   }
 
   private InstallSnapshotRequestProto newInstallSnapshotRequest(FileChunkProto 
chunk, boolean done) {
-    final long totalSize = 
snapshot.getFiles().stream().mapToLong(FileInfo::getFileSize).reduce(Long::sum).orElseThrow(
-        () -> new IllegalStateException("Failed to compute total size for 
snapshot " + snapshot));
     synchronized (server) {
       final SnapshotChunkProto.Builder b = 
LeaderProtoUtils.toSnapshotChunkProtoBuilder(
           requestId, requestIndex++, snapshot.getTermIndex(), chunk, 
totalSize, done);

Reply via email to