-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add memory tracking to queued write operations #57573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Tim-Brooks
merged 64 commits into
elastic:master
from
Tim-Brooks:indexing_memory_queue2_only_stats
Jun 25, 2020
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
d7265e6
Add post indexing hooks
Tim-Brooks 0a782cd
Add post indexing hooks
Tim-Brooks 84279ee
Changes
Tim-Brooks 9ba9a1a
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks c9ad59c
Changes
Tim-Brooks d0e1081
Add tests
Tim-Brooks 8a0a560
Changes
Tim-Brooks 08810d6
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks b0a6568
Changes
Tim-Brooks dcfb545
Changes
Tim-Brooks bdf3bd6
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 755a6cb
Move
Tim-Brooks a6bf50e
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks c54ba33
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 2ccb5b6
Changes
Tim-Brooks 524b965
Remove
Tim-Brooks de3bed7
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks a9afc77
WIP
Tim-Brooks 832dec0
Changes
Tim-Brooks 275df87
WIP
Tim-Brooks 87af556
Changes
Tim-Brooks a15fcec
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 185c24c
Changes
Tim-Brooks f9723be
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 7160c1e
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks eaa6eaa
Change
Tim-Brooks 718e343
Changes
Tim-Brooks 668715e
WIP
Tim-Brooks fa52955
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks bc76b9a
Changes
Tim-Brooks 9615713
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 2b581b5
Changes
Tim-Brooks d5aaf0e
Delete
Tim-Brooks 777569a
Move
Tim-Brooks 31459dc
Change
Tim-Brooks 903ed49
Change
Tim-Brooks 18a62cb
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks dfe5e8e
Changes
Tim-Brooks 7708977
Tests
Tim-Brooks 26dcf33
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 5295df9
Changes
Tim-Brooks 2227059
Mute tests
Tim-Brooks 1e421f0
Changes
Tim-Brooks 4455203
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks d461c36
WIP
Tim-Brooks 0cbd78a
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks f069856
Changes
Tim-Brooks da15409
Changes
Tim-Brooks 90eee72
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks ded75bb
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks bda0bc6
Changes
Tim-Brooks 3733dfc
Compile
Tim-Brooks e147024
Runbefore
Tim-Brooks 05d2f1f
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 7267ba9
Changes
Tim-Brooks 36d7cc0
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks f34aac6
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks eb8fd42
Changes
Tim-Brooks ab2f9c2
NPE
Tim-Brooks 6fd1cfa
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 7f6c033
Changes
Tim-Brooks 7dc01ea
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks 6294455
Merge remote-tracking branch 'upstream/master' into indexing_memory_q…
Tim-Brooks f2a6c77
Changes
Tim-Brooks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
server/src/internalClusterTest/java/org/elasticsearch/action/bulk/WriteMemoryLimitsIT.java
This file contains hidden or 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,206 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.elasticsearch.action.bulk; | ||
|
|
||
| import org.elasticsearch.action.ActionFuture; | ||
| import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; | ||
| import org.elasticsearch.action.admin.indices.stats.ShardStats; | ||
| import org.elasticsearch.action.index.IndexRequest; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.routing.ShardRouting; | ||
| import org.elasticsearch.common.UUIDs; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
| import org.elasticsearch.test.InternalSettingsPlugin; | ||
| import org.elasticsearch.test.transport.MockTransportService; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.transport.TransportService; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.greaterThan; | ||
|
|
||
| @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 2) | ||
| public class WriteMemoryLimitsIT extends ESIntegTestCase { | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal) { | ||
| return Settings.builder() | ||
| .put(super.nodeSettings(nodeOrdinal)) | ||
| // Need at least two threads because we are going to block one | ||
| .put("thread_pool.write.size", 2) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| return Arrays.asList(MockTransportService.TestPlugin.class, InternalSettingsPlugin.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected int numberOfReplicas() { | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| protected int numberOfShards() { | ||
| return 1; | ||
| } | ||
|
|
||
| public void testWriteBytesAreIncremented() throws Exception { | ||
| final String index = "test"; | ||
| assertAcked(prepareCreate(index, Settings.builder() | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1))); | ||
| ensureGreen(index); | ||
|
|
||
| IndicesStatsResponse response = client().admin().indices().prepareStats(index).get(); | ||
| String primaryId = Stream.of(response.getShards()) | ||
| .map(ShardStats::getShardRouting) | ||
| .filter(ShardRouting::primary) | ||
| .findAny() | ||
| .get() | ||
| .currentNodeId(); | ||
| String replicaId = Stream.of(response.getShards()) | ||
| .map(ShardStats::getShardRouting) | ||
| .filter(sr -> sr.primary() == false) | ||
| .findAny() | ||
| .get() | ||
| .currentNodeId(); | ||
| String primaryName = client().admin().cluster().prepareState().get().getState().nodes().get(primaryId).getName(); | ||
| String replicaName = client().admin().cluster().prepareState().get().getState().nodes().get(replicaId).getName(); | ||
|
|
||
| final CountDownLatch replicationSendPointReached = new CountDownLatch(1); | ||
| final CountDownLatch latchBlockingReplicationSend = new CountDownLatch(1); | ||
| final CountDownLatch newActionsSendPointReached = new CountDownLatch(2); | ||
| final CountDownLatch latchBlockingReplication = new CountDownLatch(1); | ||
|
|
||
| TransportService primaryService = internalCluster().getInstance(TransportService.class, primaryName); | ||
| final MockTransportService primaryTransportService = (MockTransportService) primaryService; | ||
| TransportService replicaService = internalCluster().getInstance(TransportService.class, replicaName); | ||
| final MockTransportService replicaTransportService = (MockTransportService) replicaService; | ||
|
|
||
| primaryTransportService.addSendBehavior((connection, requestId, action, request, options) -> { | ||
| if (action.equals(TransportShardBulkAction.ACTION_NAME + "[r]")) { | ||
| try { | ||
| replicationSendPointReached.countDown(); | ||
| latchBlockingReplicationSend.await(); | ||
| } catch (InterruptedException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| } | ||
| connection.sendRequest(requestId, action, request, options); | ||
| }); | ||
|
|
||
| final BulkRequest bulkRequest = new BulkRequest(); | ||
| int totalRequestSize = 0; | ||
| for (int i = 0; i < 80; ++i) { | ||
| IndexRequest request = new IndexRequest(index).id(UUIDs.base64UUID()) | ||
| .source(Collections.singletonMap("key", randomAlphaOfLength(50))); | ||
| totalRequestSize += request.ramBytesUsed(); | ||
| assertTrue(request.ramBytesUsed() > request.source().length()); | ||
| bulkRequest.add(request); | ||
| } | ||
|
|
||
| final long bulkRequestSize = bulkRequest.ramBytesUsed(); | ||
| final long bulkShardRequestSize = totalRequestSize; | ||
|
|
||
| try { | ||
| final ActionFuture<BulkResponse> successFuture = client(replicaName).bulk(bulkRequest); | ||
| replicationSendPointReached.await(); | ||
|
|
||
| WriteMemoryLimits primaryWriteLimits = internalCluster().getInstance(WriteMemoryLimits.class, primaryName); | ||
| WriteMemoryLimits replicaWriteLimits = internalCluster().getInstance(WriteMemoryLimits.class, replicaName); | ||
|
|
||
| assertThat(primaryWriteLimits.getCoordinatingBytes(), greaterThan(bulkShardRequestSize)); | ||
| assertThat(primaryWriteLimits.getPrimaryBytes(), greaterThan(bulkShardRequestSize)); | ||
| assertEquals(0, primaryWriteLimits.getReplicaBytes()); | ||
| assertEquals(bulkRequestSize, replicaWriteLimits.getCoordinatingBytes()); | ||
| assertEquals(0, replicaWriteLimits.getPrimaryBytes()); | ||
| assertEquals(0, replicaWriteLimits.getReplicaBytes()); | ||
|
|
||
| ThreadPool replicaThreadPool = replicaTransportService.getThreadPool(); | ||
| // Block the replica Write thread pool | ||
| replicaThreadPool.executor(ThreadPool.Names.WRITE).execute(() -> { | ||
| try { | ||
| newActionsSendPointReached.countDown(); | ||
| latchBlockingReplication.await(); | ||
| } catch (InterruptedException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| }); | ||
| replicaThreadPool.executor(ThreadPool.Names.WRITE).execute(() -> { | ||
| try { | ||
| newActionsSendPointReached.countDown(); | ||
| latchBlockingReplication.await(); | ||
| } catch (InterruptedException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| }); | ||
| newActionsSendPointReached.await(); | ||
| latchBlockingReplicationSend.countDown(); | ||
|
|
||
| IndexRequest request = new IndexRequest(index).id(UUIDs.base64UUID()) | ||
| .source(Collections.singletonMap("key", randomAlphaOfLength(50))); | ||
| final BulkRequest secondBulkRequest = new BulkRequest(); | ||
| secondBulkRequest.add(request); | ||
|
|
||
| ActionFuture<BulkResponse> secondFuture = client(replicaName).bulk(secondBulkRequest); | ||
|
|
||
| final long secondBulkRequestSize = secondBulkRequest.ramBytesUsed(); | ||
| final long secondBulkShardRequestSize = request.ramBytesUsed(); | ||
|
|
||
| assertEquals(bulkRequestSize + secondBulkRequestSize, replicaWriteLimits.getCoordinatingBytes()); | ||
| assertBusy(() -> assertThat(replicaWriteLimits.getReplicaBytes(), | ||
| greaterThan(bulkShardRequestSize + secondBulkShardRequestSize))); | ||
|
|
||
| latchBlockingReplication.countDown(); | ||
|
|
||
| successFuture.actionGet(); | ||
| secondFuture.actionGet(); | ||
|
|
||
| assertEquals(0, primaryWriteLimits.getCoordinatingBytes()); | ||
| assertEquals(0, primaryWriteLimits.getPrimaryBytes()); | ||
| assertEquals(0, primaryWriteLimits.getReplicaBytes()); | ||
| assertEquals(0, replicaWriteLimits.getCoordinatingBytes()); | ||
| assertEquals(0, replicaWriteLimits.getPrimaryBytes()); | ||
| assertEquals(0, replicaWriteLimits.getReplicaBytes()); | ||
| } finally { | ||
| if (replicationSendPointReached.getCount() > 0) { | ||
| replicationSendPointReached.countDown(); | ||
| } | ||
| while (newActionsSendPointReached.getCount() > 0) { | ||
| newActionsSendPointReached.countDown(); | ||
| } | ||
| if (latchBlockingReplicationSend.getCount() > 0) { | ||
| latchBlockingReplicationSend.countDown(); | ||
| } | ||
| if (latchBlockingReplication.getCount() > 0) { | ||
| latchBlockingReplication.countDown(); | ||
| } | ||
| primaryTransportService.clearAllRules(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.