You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2022/07/21 19:35:29 UTC

[ratis] 04/10: RATIS-1627. InstallSnapshotRequests add properties : totalSize (#684)

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

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

commit 080bb8e487c74215a445ebd16754591893db7812
Author: jiangyuan <46...@qq.com>
AuthorDate: Tue Jul 19 13:07:38 2022 +0800

    RATIS-1627. InstallSnapshotRequests add properties : totalSize (#684)
    
    (cherry picked from commit a69f3fb9aca07264274f46d2b4986188b3f0fb1a)
---
 .../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);