Browse Source

Autoscaling after clone fix (#89768)

* Autoscaling after clone fix

Autoscaling could start failing after a clone, if the source of
the clone is deleted.

* Update docs/changelog/89768.yaml

* Update docs/changelog/89768.yaml
Henning Andersen 3 years ago
parent
commit
0302d2db2d

+ 6 - 0
docs/changelog/89768.yaml

@@ -0,0 +1,6 @@
+pr: 89768
+summary: Autoscaling after clone fix
+area: Autoscaling
+type: bug
+issues:
+ - 89758

+ 14 - 0
x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageIT.java

@@ -383,6 +383,13 @@ public class ReactiveStorageIT extends AutoscalingStorageIntegTestCase {
         setTotalSpace(dataNode1Name, tooLittleSpaceForShrink + 1);
         assertAcked(client().admin().cluster().prepareReroute());
         ensureGreen();
+
+        client().admin().indices().prepareDelete(indexName).get();
+        response = capacity();
+        assertThat(
+            response.results().get(policyName).requiredCapacity().total().storage(),
+            equalTo(response.results().get(policyName).currentCapacity().total().storage())
+        );
     }
 
     public void testScaleDuringSplitOrClone() throws Exception {
@@ -489,6 +496,13 @@ public class ReactiveStorageIT extends AutoscalingStorageIntegTestCase {
         setTotalSpace(dataNode1Name, requiredSpaceForClone);
         assertAcked(client().admin().cluster().prepareReroute());
         ensureGreen();
+
+        client().admin().indices().prepareDelete(indexName).get();
+        response = capacity();
+        assertThat(
+            response.results().get(policyName).requiredCapacity().total().storage().getBytes(),
+            equalTo(requiredSpaceForClone + enoughSpace)
+        );
     }
 
     /**

+ 15 - 13
x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java

@@ -487,20 +487,22 @@ public class ReactiveStorageDeciderService implements AutoscalingDeciderService
             } else {
                 Index resizeSourceIndex = indexMetadata.getResizeSourceIndex();
                 if (resizeSourceIndex != null) {
-                    IndexMetadata sourceIndexMetadata = metadata.getIndexSafe(resizeSourceIndex);
-                    // ResizeAllocationDecider only handles clone or split, do the same here.
-
-                    if (indexMetadata.getNumberOfShards() >= sourceIndexMetadata.getNumberOfShards()) {
-                        IndexRoutingTable indexRoutingTable = state.getRoutingTable().index(resizeSourceIndex);
-                        long max = 0;
-                        for (int s = 0; s < sourceIndexMetadata.getNumberOfShards(); ++s) {
-                            ShardRouting shard = indexRoutingTable.shard(s).primaryShard();
-                            long size = sizeOf(shard);
-                            max = Math.max(max, size);
+                    IndexMetadata sourceIndexMetadata = metadata.index(resizeSourceIndex);
+                    // source indicators stay on the index even after started and also after source is deleted.
+                    if (sourceIndexMetadata != null) {
+                        // ResizeAllocationDecider only handles clone or split, do the same here.
+                        if (indexMetadata.getNumberOfShards() >= sourceIndexMetadata.getNumberOfShards()) {
+                            IndexRoutingTable indexRoutingTable = state.getRoutingTable().index(resizeSourceIndex);
+                            long max = 0;
+                            for (int s = 0; s < sourceIndexMetadata.getNumberOfShards(); ++s) {
+                                ShardRouting shard = indexRoutingTable.shard(s).primaryShard();
+                                long size = sizeOf(shard);
+                                max = Math.max(max, size);
+                            }
+
+                            // 2x to account for the extra copy residing on the same node
+                            return max * 2;
                         }
-
-                        // 2x to account for the extra copy residing on the same node
-                        return max * 2;
                     }
                 }
             }