5
5
*/
6
6
package org .elasticsearch .xpack .core .ilm ;
7
7
8
- import org .apache .log4j .LogManager ;
9
- import org .apache .log4j .Logger ;
8
+ import org .apache .logging . log4j .LogManager ;
9
+ import org .apache .logging . log4j .Logger ;
10
10
import org .elasticsearch .action .ActionListener ;
11
11
import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsRequest ;
12
12
import org .elasticsearch .client .Client ;
13
+ import org .elasticsearch .client .transport .NoNodeAvailableException ;
13
14
import org .elasticsearch .cluster .ClusterState ;
14
15
import org .elasticsearch .cluster .ClusterStateObserver ;
15
16
import org .elasticsearch .cluster .metadata .IndexMetaData ;
@@ -54,18 +55,23 @@ public SetSingleNodeAllocateStep(StepKey key, StepKey nextStepKey, Client client
54
55
super (key , nextStepKey , client );
55
56
}
56
57
58
+ @ Override
59
+ public boolean isRetryable () {
60
+ return true ;
61
+ }
62
+
57
63
@ Override
58
64
public void performAction (IndexMetaData indexMetaData , ClusterState clusterState , ClusterStateObserver observer , Listener listener ) {
59
65
final RoutingNodes routingNodes = clusterState .getRoutingNodes ();
60
66
RoutingAllocation allocation = new RoutingAllocation (ALLOCATION_DECIDERS , routingNodes , clusterState , null ,
61
67
System .nanoTime ());
62
68
List <String > validNodeIds = new ArrayList <>();
69
+ String indexName = indexMetaData .getIndex ().getName ();
63
70
final Map <ShardId , List <ShardRouting >> routingsByShardId = clusterState .getRoutingTable ()
64
- .allShards (indexMetaData . getIndex (). getName () )
71
+ .allShards (indexName )
65
72
.stream ()
66
73
.collect (Collectors .groupingBy (ShardRouting ::shardId ));
67
74
68
-
69
75
if (routingsByShardId .isEmpty () == false ) {
70
76
for (RoutingNode node : routingNodes ) {
71
77
boolean canAllocateOneCopyOfEachShard = routingsByShardId .values ().stream () // For each shard
@@ -79,21 +85,24 @@ public void performAction(IndexMetaData indexMetaData, ClusterState clusterState
79
85
// Shuffle the list of nodes so the one we pick is random
80
86
Randomness .shuffle (validNodeIds );
81
87
Optional <String > nodeId = validNodeIds .stream ().findAny ();
88
+
82
89
if (nodeId .isPresent ()) {
83
90
Settings settings = Settings .builder ()
84
91
.put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + "_id" , nodeId .get ()).build ();
85
- UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest (indexMetaData . getIndex (). getName () )
92
+ UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest (indexName )
86
93
.masterNodeTimeout (getMasterTimeout (clusterState ))
87
94
.settings (settings );
88
95
getClient ().admin ().indices ().updateSettings (updateSettingsRequest ,
89
96
ActionListener .wrap (response -> listener .onResponse (true ), listener ::onFailure ));
90
97
} else {
91
- // No nodes currently match the allocation rules so just wait until there is one that does
92
- logger .debug ("could not find any nodes to allocate index [{}] onto prior to shrink" );
93
- listener .onResponse (false );
98
+ // No nodes currently match the allocation rules, so report this as an error and we'll retry
99
+ logger .debug ("could not find any nodes to allocate index [{}] onto prior to shrink" , indexName );
100
+ listener .onFailure (new NoNodeAvailableException ("could not find any nodes to allocate index [" + indexName + "] onto" +
101
+ " prior to shrink" ));
94
102
}
95
103
} else {
96
- // There are no shards for the index, the index might be gone
104
+ // There are no shards for the index, the index might be gone. Even though this is a retryable step ILM will not retry in
105
+ // this case as we're using the periodic loop to trigger the retries and that is run over *existing* indices.
97
106
listener .onFailure (new IndexNotFoundException (indexMetaData .getIndex ()));
98
107
}
99
108
}
0 commit comments