11
11
import org .apache .logging .log4j .Logger ;
12
12
import org .elasticsearch .Version ;
13
13
import org .elasticsearch .action .ActionListener ;
14
+ import org .elasticsearch .common .Strings ;
14
15
import org .elasticsearch .core .Nullable ;
15
16
import org .elasticsearch .index .shard .ShardId ;
17
+ import org .elasticsearch .index .snapshots .blobstore .BlobStoreIndexShardSnapshot ;
16
18
import org .elasticsearch .index .store .Store ;
17
19
import org .elasticsearch .index .store .StoreFileMetadata ;
18
20
import org .elasticsearch .indices .recovery .RecoverySettings ;
@@ -68,6 +70,7 @@ public void computeRecoveryPlan(
68
70
latestSnapshotOpt -> ActionListener .completeWith (
69
71
listener ,
70
72
() -> computeRecoveryPlanWithSnapshots (
73
+ shardId ,
71
74
shardStateIdentifier ,
72
75
sourceMetadata ,
73
76
targetMetadata ,
@@ -80,6 +83,7 @@ public void computeRecoveryPlan(
80
83
}
81
84
82
85
private ShardRecoveryPlan computeRecoveryPlanWithSnapshots (
86
+ ShardId shardId ,
83
87
@ Nullable String shardStateIdentifier ,
84
88
Store .MetadataSnapshot sourceMetadata ,
85
89
Store .MetadataSnapshot targetMetadata ,
@@ -91,6 +95,7 @@ private ShardRecoveryPlan computeRecoveryPlanWithSnapshots(
91
95
List <StoreFileMetadata > filesMissingInTarget = concatLists (sourceTargetDiff .missing , sourceTargetDiff .different );
92
96
93
97
if (latestSnapshotOpt .isEmpty ()) {
98
+ logger .debug ("{} no snapshot suitable for recovery found, falling back to recovery from the primary" , shardId );
94
99
// If we couldn't find any valid snapshots, fallback to the source
95
100
return getRecoveryPlanUsingSourceNode (sourceMetadata , sourceTargetDiff , filesMissingInTarget , startingSeqNo , translogOps );
96
101
}
@@ -102,6 +107,18 @@ private ShardRecoveryPlan computeRecoveryPlanWithSnapshots(
102
107
&& latestSnapshot .hasDifferentPhysicalFiles (sourceMetadata )
103
108
&& isSnapshotVersionCompatible (latestSnapshot )
104
109
&& sourceTargetDiff .identical .isEmpty ()) {
110
+
111
+ logger .debug (
112
+ () -> Strings .format (
113
+ "%s primary has changed since snapshot completed, but snapshot still looks ok for recovery: %s" ,
114
+ shardId ,
115
+ latestSnapshot .getSnapshotFiles ()
116
+ .stream ()
117
+ .map (BlobStoreIndexShardSnapshot .FileInfo ::physicalName )
118
+ .collect (Collectors .joining (", " , "[" , "]" ))
119
+ )
120
+ );
121
+
105
122
// Use the current primary as a fallback if the download fails half-way
106
123
ShardRecoveryPlan fallbackPlan = getRecoveryPlanUsingSourceNode (
107
124
sourceMetadata ,
@@ -141,6 +158,18 @@ && isSnapshotVersionCompatible(latestSnapshot)
141
158
);
142
159
}
143
160
161
+ logger .debug (
162
+ () -> Strings .format (
163
+ "%s attempting snapshot-based recovery of %s based on %s" ,
164
+ shardId ,
165
+ snapshotFilesToRecover .getSnapshotFiles ()
166
+ .stream ()
167
+ .map (BlobStoreIndexShardSnapshot .FileInfo ::physicalName )
168
+ .collect (Collectors .joining (", " , "[" , "]" )),
169
+ snapshotDiff
170
+ )
171
+ );
172
+
144
173
return new ShardRecoveryPlan (
145
174
snapshotFilesToRecover ,
146
175
concatLists (snapshotDiff .missing , snapshotDiff .different ),
@@ -183,6 +212,7 @@ private ShardRecoveryPlan getRecoveryPlanUsingSourceNode(
183
212
184
213
private void fetchLatestSnapshotsIgnoringErrors (ShardId shardId , boolean useSnapshots , Consumer <Optional <ShardSnapshot >> listener ) {
185
214
if (useSnapshots == false ) {
215
+ logger .debug ("{} recovery will not attempt to use snapshots" , shardId );
186
216
listener .accept (Optional .empty ());
187
217
return ;
188
218
}
0 commit comments