-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) This commit adds a warning if a fraction of a shards on undesired nodes has grown. This should allow us to proactively investigate those cases before they turn into nodes with hot spots. (cherry picked from commit 3808b53)
- Loading branch information
1 parent
2490de7
commit 8a16067
Showing
10 changed files
with
577 additions
and
377 deletions.
There are no files selected for viewing
740 changes: 402 additions & 338 deletions
740
...java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...in/java/org/elasticsearch/cluster/routing/allocation/allocator/FrequencyCappedAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.routing.allocation.allocator; | ||
|
||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
|
||
import java.util.function.LongSupplier; | ||
|
||
/** | ||
* Execute an action at most once per time interval | ||
*/ | ||
public class FrequencyCappedAction { | ||
|
||
private final LongSupplier currentTimeMillisSupplier; | ||
private TimeValue minInterval; | ||
|
||
private long next = -1; | ||
|
||
public FrequencyCappedAction(ThreadPool threadPool) { | ||
this(threadPool::relativeTimeInMillis); | ||
} | ||
|
||
public FrequencyCappedAction(LongSupplier currentTimeMillisSupplier) { | ||
this.currentTimeMillisSupplier = currentTimeMillisSupplier; | ||
this.minInterval = TimeValue.MAX_VALUE; | ||
} | ||
|
||
public void setMinInterval(TimeValue minInterval) { | ||
this.minInterval = minInterval; | ||
} | ||
|
||
public void maybeExecute(Runnable runnable) { | ||
var current = currentTimeMillisSupplier.getAsLong(); | ||
if (current >= next) { | ||
next = current + minInterval.millis(); | ||
runnable.run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...va/org/elasticsearch/cluster/routing/allocation/allocator/FrequencyCappedActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.routing.allocation.allocator; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import static org.elasticsearch.core.TimeValue.timeValueMillis; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class FrequencyCappedActionTests extends ESTestCase { | ||
|
||
public void testFrequencyCapExecution() { | ||
|
||
var executions = new AtomicLong(0); | ||
var currentTime = new AtomicLong(); | ||
var action = new FrequencyCappedAction(currentTime::get); | ||
|
||
var minInterval = timeValueMillis(randomNonNegativeInt()); | ||
action.setMinInterval(minInterval); | ||
|
||
// initial execution should happen | ||
action.maybeExecute(executions::incrementAndGet); | ||
assertThat(executions.get(), equalTo(1L)); | ||
|
||
// should not execute again too soon | ||
currentTime.set(randomLongBetween(0, minInterval.millis() - 1)); | ||
action.maybeExecute(executions::incrementAndGet); | ||
assertThat(executions.get(), equalTo(1L)); | ||
|
||
// should execute min interval elapsed | ||
currentTime.set(randomLongBetween(minInterval.millis(), Long.MAX_VALUE)); | ||
action.maybeExecute(executions::incrementAndGet); | ||
assertThat(executions.get(), equalTo(2L)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.