19
19
20
20
package org .elasticsearch .cluster .routing .allocation ;
21
21
22
- import java .util .HashMap ;
22
+ import java .util .Arrays ;
23
23
import java .util .HashSet ;
24
- import java .util .Map ;
25
24
import java .util .Set ;
26
25
import java .util .function .Supplier ;
27
26
import java .util .stream .Collectors ;
@@ -116,20 +115,18 @@ public void onNewInfo(ClusterInfo info) {
116
115
ClusterState state = clusterStateSupplier .get ();
117
116
Set <String > indicesToMarkReadOnly = new HashSet <>();
118
117
RoutingNodes routingNodes = state .getRoutingNodes ();
119
- Map <String , Boolean > indexAutoReleaseEligibility = new HashMap <>();
120
- // Ensure we release indices on nodes that have a usage response from node stats
121
- markNodesMissingUsageIneligibleForRelease (routingNodes , usages , indexAutoReleaseEligibility );
118
+ Set <String > indicesToMarkIneligibleForAutoRelease = new HashSet <>();
119
+ //Ensure we release indices on nodes that have a usage response from node stats
120
+ markNodesMissingUsageIneligibleForRelease (routingNodes , usages , indicesToMarkIneligibleForAutoRelease );
122
121
for (ObjectObjectCursor <String , DiskUsage > entry : usages ) {
123
122
String node = entry .key ;
124
123
DiskUsage usage = entry .value ;
125
124
warnAboutDiskIfNeeded (usage );
126
- RoutingNode routingNode = state . getRoutingNodes () .node (node );
125
+ RoutingNode routingNode = routingNodes .node (node );
127
126
// Only unblock index if all nodes that contain shards of it are below the high disk watermark
128
127
if (usage .getFreeBytes () < diskThresholdSettings .getFreeBytesThresholdHigh ().getBytes ()
129
128
|| usage .getFreeDiskAsPercentage () < diskThresholdSettings .getFreeDiskThresholdHigh ()) {
130
- markEligiblityForAutoRelease (routingNode , indexAutoReleaseEligibility , false );
131
- } else {
132
- markEligiblityForAutoRelease (routingNode , indexAutoReleaseEligibility , true );
129
+ markIneligiblityForAutoRelease (routingNode , indicesToMarkIneligibleForAutoRelease );
133
130
}
134
131
if (usage .getFreeBytes () < diskThresholdSettings .getFreeBytesThresholdFloodStage ().getBytes () ||
135
132
usage .getFreeDiskAsPercentage () < diskThresholdSettings .getFreeDiskThresholdFloodStage ()) {
@@ -179,9 +176,9 @@ public void onNewInfo(ClusterInfo info) {
179
176
180
177
// Get set of indices that are eligible to be automatically unblocked
181
178
// Only collect indices that are currently blocked
182
- Set < String > indicesToAutoRelease = indexAutoReleaseEligibility . entrySet ().stream ()
183
- . filter ( Map . Entry :: getValue )
184
- .map ( Map . Entry :: getKey )
179
+ final String [] indices = state . routingTable ().indicesRouting (). keys (). toArray ( String . class );
180
+ Set < String > indicesToAutoRelease = Arrays . stream ( indices )
181
+ .filter ( index -> indicesToMarkIneligibleForAutoRelease . contains ( index ) == false )
185
182
.filter (index -> state .getBlocks ().hasIndexBlock (index , IndexMetaData .INDEX_READ_ONLY_ALLOW_DELETE_BLOCK ))
186
183
.collect (Collectors .toCollection (HashSet ::new ));
187
184
@@ -190,7 +187,7 @@ public void onNewInfo(ClusterInfo info) {
190
187
logger .info ("Releasing read-only allow delete block on indices: [{}]" , indicesToAutoRelease );
191
188
updateIndicesReadOnly (indicesToAutoRelease , false );
192
189
} else {
193
- deprecationLogger .deprecated ("es.disk.auto_release_flood_stage_block will be removed in 8.0.0" );
190
+ deprecationLogger .deprecated ("[{}] will be removed in 8.0.0" , DiskThresholdSettings . AUTO_RELEASE_INDEX_ENABLED_KEY );
194
191
}
195
192
}
196
193
indicesToMarkReadOnly .removeIf (index -> state .getBlocks ().indexBlocked (ClusterBlockLevel .WRITE , index ));
@@ -202,24 +199,20 @@ public void onNewInfo(ClusterInfo info) {
202
199
203
200
204
201
private void markNodesMissingUsageIneligibleForRelease (RoutingNodes routingNodes , ImmutableOpenMap <String , DiskUsage > usages ,
205
- Map <String , Boolean > indexAutoReleaseEligibility ) {
206
- if (routingNodes .size () != usages .size ()) {
207
- for (RoutingNode routingNode : routingNodes ) {
208
- if (!usages .keys ().contains (routingNode .nodeId ())) {
209
- markEligiblityForAutoRelease (routingNode , indexAutoReleaseEligibility , false );
210
- }
202
+ Set <String > indicesToMarkIneligibleForAutoRelease ) {
203
+ for (RoutingNode routingNode : routingNodes ) {
204
+ if (usages .containsKey (routingNode .nodeId ()) == false ) {
205
+ markIneligiblityForAutoRelease (routingNode , indicesToMarkIneligibleForAutoRelease );
211
206
}
212
207
}
213
208
214
209
}
215
210
216
- private void markEligiblityForAutoRelease (RoutingNode routingNode , Map <String , Boolean > indexAutoReleaseEligibility ,
217
- boolean eligible ) {
211
+ private void markIneligiblityForAutoRelease (RoutingNode routingNode , Set <String > indicesToMarkIneligibleForAutoRelease ) {
218
212
if (routingNode != null ) {
219
213
for (ShardRouting routing : routingNode ) {
220
214
String indexName = routing .index ().getName ();
221
- boolean value = indexAutoReleaseEligibility .getOrDefault (indexName , true );
222
- indexAutoReleaseEligibility .put (indexName , value && eligible );
215
+ indicesToMarkIneligibleForAutoRelease .add (indexName );
223
216
}
224
217
}
225
218
}
0 commit comments