ソースを参照

Implement StartRecoveryRequest#getDescription (#95731)

Today the transport actions associated with recoveries appear in the
task list but there is nothing to identify which recovery is which. This
commit adds that identifying information.
David Turner 2 年 前
コミット
02b9075517

+ 5 - 0
docs/changelog/95731.yaml

@@ -0,0 +1,5 @@
+pr: 95731
+summary: Implement `StartRecoveryRequest#getDescription`
+area: Recovery
+type: enhancement
+issues: []

+ 17 - 0
server/src/main/java/org/elasticsearch/indices/recovery/StartRecoveryRequest.java

@@ -9,6 +9,7 @@
 package org.elasticsearch.indices.recovery;
 
 import org.elasticsearch.cluster.node.DiscoveryNode;
+import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.index.seqno.SequenceNumbers;
@@ -123,6 +124,22 @@ public class StartRecoveryRequest extends TransportRequest {
         return canDownloadSnapshotFiles;
     }
 
+    @Override
+    public String getDescription() {
+        return Strings.format(
+            """
+                recovery of %s to %s \
+                [recoveryId=%d, targetAllocationId=%s, startingSeqNo=%d, primaryRelocation=%s, canDownloadSnapshotFiles=%s]""",
+            shardId,
+            targetNode.descriptionWithoutAttributes(),
+            recoveryId,
+            targetAllocationId,
+            startingSeqNo,
+            primaryRelocation,
+            canDownloadSnapshotFiles
+        );
+    }
+
     @Override
     public void writeTo(StreamOutput out) throws IOException {
         super.writeTo(out);

+ 21 - 0
server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java

@@ -74,4 +74,25 @@ public class StartRecoveryRequestTests extends ESTestCase {
         assertThat(outRequest.startingSeqNo(), equalTo(inRequest.startingSeqNo()));
     }
 
+    public void testDescription() {
+        final var node = new DiscoveryNode("a", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
+        assertEquals(
+            "recovery of [index][0] to "
+                + node.descriptionWithoutAttributes()
+                + " [recoveryId=1, targetAllocationId=allocationId, startingSeqNo=-2, "
+                + "primaryRelocation=false, canDownloadSnapshotFiles=true]",
+            new StartRecoveryRequest(
+                new ShardId("index", "uuid", 0),
+                "allocationId",
+                null,
+                node,
+                Store.MetadataSnapshot.EMPTY,
+                false,
+                1,
+                SequenceNumbers.UNASSIGNED_SEQ_NO,
+                true
+            ).getDescription()
+        );
+    }
+
 }