Skip to content

Commit

Permalink
Set replica_unassigned_buffer_time default value (elastic#112612)
Browse files Browse the repository at this point in the history
The default value of replica_unassigned_buffer_time was set
incorrectly to 0s and was never updated to the correct default
value. Instead it should be set in the constructor from the settings.
  • Loading branch information
parkertimmins authored Sep 6, 2024
1 parent bd28e77 commit 7a328ba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/112612.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 112612
summary: Set `replica_unassigned_buffer_time` in constructor
area: Health
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class ShardsAvailabilityHealthIndicatorService implements HealthIndicator

private final SystemIndices systemIndices;

private volatile TimeValue replicaUnassignedBufferTime = TimeValue.timeValueSeconds(0);
private volatile TimeValue replicaUnassignedBufferTime;

public ShardsAvailabilityHealthIndicatorService(
ClusterService clusterService,
Expand All @@ -142,6 +142,7 @@ public ShardsAvailabilityHealthIndicatorService(
this.clusterService = clusterService;
this.allocationService = allocationService;
this.systemIndices = systemIndices;
this.replicaUnassignedBufferTime = REPLICA_UNASSIGNED_BUFFER_TIME.get(clusterService.getSettings());
clusterService.getClusterSettings().addSettingsUpdateConsumer(REPLICA_UNASSIGNED_BUFFER_TIME, this::setReplicaUnassignedBufferTime);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.cluster.routing.allocation.shards.ShardsAvailabilityHealthIndicatorService;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.test.ESTestCase;

Expand Down Expand Up @@ -43,6 +44,7 @@ public class ShardsAvailabilityActionGuideTests extends ESTestCase {
public ShardsAvailabilityActionGuideTests() {
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.getClusterSettings()).thenReturn(ClusterSettings.createBuiltInClusterSettings());
when(clusterService.getSettings()).thenReturn(Settings.EMPTY);
service = new ShardsAvailabilityHealthIndicatorService(clusterService, mock(AllocationService.class), mock(SystemIndices.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,7 @@ public void testMappedFieldsForTelemetry() {
);
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.getClusterSettings()).thenReturn(ClusterSettings.createBuiltInClusterSettings());
when(clusterService.getSettings()).thenReturn(Settings.EMPTY);
var service = new ShardsAvailabilityHealthIndicatorService(
clusterService,
mock(AllocationService.class),
Expand Down Expand Up @@ -2557,6 +2558,7 @@ private static ShardsAvailabilityHealthIndicatorService createAllocationHealthIn
when(clusterService.state()).thenReturn(clusterState);
var clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
when(clusterService.getSettings()).thenReturn(Settings.EMPTY);
var allocationService = mock(AllocationService.class);
when(allocationService.explainShardAllocation(any(), any())).thenAnswer((Answer<ShardAllocationDecision>) invocation -> {
ShardRouting shardRouting = invocation.getArgument(0);
Expand Down

0 comments on commit 7a328ba

Please sign in to comment.