-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into validate-index-name
- Loading branch information
Showing
28 changed files
with
247 additions
and
75 deletions.
There are no files selected for viewing
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,6 @@ | ||
pr: 109414 | ||
summary: Don't fail retention lease sync actions due to capacity constraints | ||
area: CRUD | ||
type: bug | ||
issues: | ||
- 105926 |
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
75 changes: 75 additions & 0 deletions
75
...lClusterTest/java/org/elasticsearch/index/seqno/BackgroundRetentionLeaseSyncActionIT.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,75 @@ | ||
/* | ||
* 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.index.seqno; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.breaker.CircuitBreaker; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class BackgroundRetentionLeaseSyncActionIT extends ESIntegTestCase { | ||
|
||
public void testActionCompletesWhenReplicaCircuitBreakersAreAtCapacity() throws Exception { | ||
internalCluster().startMasterOnlyNodes(1); | ||
String primary = internalCluster().startDataOnlyNode(); | ||
assertAcked( | ||
prepareCreate("test").setSettings( | ||
Settings.builder() | ||
.put(indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) | ||
) | ||
); | ||
|
||
String replica = internalCluster().startDataOnlyNode(); | ||
ensureGreen("test"); | ||
|
||
try (var ignored = fullyAllocateCircuitBreakerOnNode(replica, CircuitBreaker.IN_FLIGHT_REQUESTS)) { | ||
final ClusterState state = internalCluster().clusterService().state(); | ||
final Index testIndex = resolveIndex("test"); | ||
final ShardId testIndexShardZero = new ShardId(testIndex, 0); | ||
final String testLeaseId = "test-lease/123"; | ||
RetentionLeases newLeases = addTestLeaseToRetentionLeases(primary, testIndex, testLeaseId); | ||
internalCluster().getInstance(RetentionLeaseSyncer.class, primary) | ||
.backgroundSync( | ||
testIndexShardZero, | ||
state.routingTable().shardRoutingTable(testIndexShardZero).primaryShard().allocationId().getId(), | ||
state.term(), | ||
newLeases | ||
); | ||
|
||
// Wait for test lease to appear on replica | ||
IndicesService replicaIndicesService = internalCluster().getInstance(IndicesService.class, replica); | ||
assertBusy(() -> { | ||
RetentionLeases retentionLeases = replicaIndicesService.indexService(testIndex).getShard(0).getRetentionLeases(); | ||
assertTrue(retentionLeases.contains(testLeaseId)); | ||
}); | ||
} | ||
} | ||
|
||
private static RetentionLeases addTestLeaseToRetentionLeases(String primaryNodeName, Index index, String leaseId) { | ||
IndicesService primaryIndicesService = internalCluster().getInstance(IndicesService.class, primaryNodeName); | ||
RetentionLeases currentLeases = primaryIndicesService.indexService(index).getShard(0).getRetentionLeases(); | ||
RetentionLease newLease = new RetentionLease(leaseId, 0, System.currentTimeMillis(), "test source"); | ||
return new RetentionLeases( | ||
currentLeases.primaryTerm(), | ||
currentLeases.version() + 1, | ||
Stream.concat(currentLeases.leases().stream(), Stream.of(newLease)).toList() | ||
); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...rc/internalClusterTest/java/org/elasticsearch/index/seqno/RetentionLeaseSyncActionIT.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,98 @@ | ||
/* | ||
* 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.index.seqno; | ||
|
||
import org.elasticsearch.action.support.PlainActionFuture; | ||
import org.elasticsearch.action.support.replication.ReplicationResponse; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
import org.elasticsearch.common.breaker.CircuitBreaker; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.core.Releasable; | ||
import org.elasticsearch.index.IndexingPressure; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class RetentionLeaseSyncActionIT extends ESIntegTestCase { | ||
|
||
public void testActionCompletesWhenReplicaCircuitBreakersAreAtCapacity() { | ||
internalCluster().startMasterOnlyNodes(1); | ||
String primary = internalCluster().startDataOnlyNode(); | ||
assertAcked( | ||
prepareCreate("test").setSettings( | ||
Settings.builder() | ||
.put(indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) | ||
) | ||
); | ||
|
||
String replica = internalCluster().startDataOnlyNode(); | ||
ensureGreen("test"); | ||
|
||
try (var ignored = fullyAllocateCircuitBreakerOnNode(replica, CircuitBreaker.IN_FLIGHT_REQUESTS)) { | ||
assertThatRetentionLeaseSyncCompletesSuccessfully(primary); | ||
} | ||
} | ||
|
||
public void testActionCompletesWhenPrimaryIndexingPressureIsAtCapacity() { | ||
internalCluster().startMasterOnlyNodes(1); | ||
String primary = internalCluster().startDataOnlyNode(); | ||
assertAcked( | ||
prepareCreate("test").setSettings( | ||
Settings.builder() | ||
.put(indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) | ||
) | ||
); | ||
|
||
String replica = internalCluster().startDataOnlyNode(); | ||
ensureGreen("test"); | ||
|
||
try (Releasable ignored = fullyAllocatePrimaryIndexingCapacityOnNode(primary)) { | ||
assertThatRetentionLeaseSyncCompletesSuccessfully(primary); | ||
} | ||
} | ||
|
||
private static void assertThatRetentionLeaseSyncCompletesSuccessfully(String primaryNodeName) { | ||
RetentionLeaseSyncer instance = internalCluster().getInstance(RetentionLeaseSyncer.class, primaryNodeName); | ||
PlainActionFuture<ReplicationResponse> retentionLeaseSyncResult = new PlainActionFuture<>(); | ||
ClusterState state = internalCluster().clusterService().state(); | ||
ShardId testIndexShardZero = new ShardId(resolveIndex("test"), 0); | ||
ShardRouting primaryShard = state.routingTable().shardRoutingTable(testIndexShardZero).primaryShard(); | ||
instance.sync( | ||
testIndexShardZero, | ||
primaryShard.allocationId().getId(), | ||
state.term(), | ||
RetentionLeases.EMPTY, | ||
retentionLeaseSyncResult | ||
); | ||
safeGet(retentionLeaseSyncResult); | ||
} | ||
|
||
/** | ||
* Fully allocate primary indexing capacity on a node | ||
* | ||
* @param targetNode The name of the node on which to allocate | ||
* @return A {@link Releasable} which will release the capacity when closed | ||
*/ | ||
private static Releasable fullyAllocatePrimaryIndexingCapacityOnNode(String targetNode) { | ||
return internalCluster().getInstance(IndexingPressure.class, targetNode) | ||
.markPrimaryOperationStarted( | ||
1, | ||
IndexingPressure.MAX_INDEXING_BYTES.get(internalCluster().getInstance(Settings.class, targetNode)).getBytes() + 1, | ||
true | ||
); | ||
} | ||
} |
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
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
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
Oops, something went wrong.