Skip to content

Commit

Permalink
Autoscaling after clone fix (#89768) (#89786)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
henningandersen committed Sep 2, 2022
1 parent 1013932 commit 935d139
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/89768.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 89768
summary: Autoscaling after clone fix
area: Autoscaling
type: bug
issues:
- 89758
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ public void testScaleWhileShrinking() throws Exception {
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())
);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/88478")
Expand Down Expand Up @@ -481,6 +488,13 @@ public void testScaleDuringSplitOrClone() throws Exception {
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)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,20 +487,22 @@ private long nodeLockedSize(IndexMetadata indexMetadata, Metadata metadata) {
} 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;
}
}
}
Expand Down

0 comments on commit 935d139

Please sign in to comment.