Skip to content

Commit 935d139

Browse files
Autoscaling after clone fix (#89768) (#89786)
* 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
1 parent 1013932 commit 935d139

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

docs/changelog/89768.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 89768
2+
summary: Autoscaling after clone fix
3+
area: Autoscaling
4+
type: bug
5+
issues:
6+
- 89758

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ public void testScaleWhileShrinking() throws Exception {
382382
setTotalSpace(dataNode1Name, tooLittleSpaceForShrink + 1);
383383
assertAcked(client().admin().cluster().prepareReroute());
384384
ensureGreen();
385+
386+
client().admin().indices().prepareDelete(indexName).get();
387+
response = capacity();
388+
assertThat(
389+
response.results().get(policyName).requiredCapacity().total().storage(),
390+
equalTo(response.results().get(policyName).currentCapacity().total().storage())
391+
);
385392
}
386393

387394
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/88478")
@@ -481,6 +488,13 @@ public void testScaleDuringSplitOrClone() throws Exception {
481488
setTotalSpace(dataNode1Name, requiredSpaceForClone);
482489
assertAcked(client().admin().cluster().prepareReroute());
483490
ensureGreen();
491+
492+
client().admin().indices().prepareDelete(indexName).get();
493+
response = capacity();
494+
assertThat(
495+
response.results().get(policyName).requiredCapacity().total().storage().getBytes(),
496+
equalTo(requiredSpaceForClone + enoughSpace)
497+
);
484498
}
485499

486500
/**

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,20 +487,22 @@ private long nodeLockedSize(IndexMetadata indexMetadata, Metadata metadata) {
487487
} else {
488488
Index resizeSourceIndex = indexMetadata.getResizeSourceIndex();
489489
if (resizeSourceIndex != null) {
490-
IndexMetadata sourceIndexMetadata = metadata.getIndexSafe(resizeSourceIndex);
491-
// ResizeAllocationDecider only handles clone or split, do the same here.
492-
493-
if (indexMetadata.getNumberOfShards() >= sourceIndexMetadata.getNumberOfShards()) {
494-
IndexRoutingTable indexRoutingTable = state.getRoutingTable().index(resizeSourceIndex);
495-
long max = 0;
496-
for (int s = 0; s < sourceIndexMetadata.getNumberOfShards(); ++s) {
497-
ShardRouting shard = indexRoutingTable.shard(s).primaryShard();
498-
long size = sizeOf(shard);
499-
max = Math.max(max, size);
490+
IndexMetadata sourceIndexMetadata = metadata.index(resizeSourceIndex);
491+
// source indicators stay on the index even after started and also after source is deleted.
492+
if (sourceIndexMetadata != null) {
493+
// ResizeAllocationDecider only handles clone or split, do the same here.
494+
if (indexMetadata.getNumberOfShards() >= sourceIndexMetadata.getNumberOfShards()) {
495+
IndexRoutingTable indexRoutingTable = state.getRoutingTable().index(resizeSourceIndex);
496+
long max = 0;
497+
for (int s = 0; s < sourceIndexMetadata.getNumberOfShards(); ++s) {
498+
ShardRouting shard = indexRoutingTable.shard(s).primaryShard();
499+
long size = sizeOf(shard);
500+
max = Math.max(max, size);
501+
}
502+
503+
// 2x to account for the extra copy residing on the same node
504+
return max * 2;
500505
}
501-
502-
// 2x to account for the extra copy residing on the same node
503-
return max * 2;
504506
}
505507
}
506508
}

0 commit comments

Comments
 (0)