Skip to content

Batch add index block cluster state updates#84374

Merged
joegallo merged 22 commits intoelastic:masterfrom
joegallo:batch-add-blocks
Mar 8, 2022
Merged

Batch add index block cluster state updates#84374
joegallo merged 22 commits intoelastic:masterfrom
joegallo:batch-add-blocks

Conversation

@joegallo
Copy link
Copy Markdown
Contributor

Related to #81627 and #83432, followup to #83760 and #84259.

@joegallo joegallo added >enhancement :Data Management/Indices APIs DO NOT USE. Use ":Distributed/Indices APIs" or ":StorageEngine/Templates" instead. v8.2.0 labels Feb 24, 2022
@elasticmachine elasticmachine added the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. label Feb 24, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @joegallo, I've created a changelog YAML for you.

Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except one slip that I think indicates a lack of test coverage (and a couple of tiny nits)

The rest of the various Executors here are not static, because they
use the clusterService or some other field of the enclosing
MetadataIndexStateService, but this one doesn't happen to do that, so
there's no harm in making it static.
@joegallo joegallo requested a review from DaveCTurner March 3, 2022 20:23
Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I had in mind, yes. Added some small suggestions. Also could we add a cluster state listener in each case so we can assert how many cluster states get published?

@joegallo
Copy link
Copy Markdown
Contributor Author

joegallo commented Mar 4, 2022

Also could we add a cluster state listener in each case so we can assert how many cluster states get published?

It looks to me like shard-started tasks end up making this a little harder than it might initially sound -- I think they're not consistently batching in a way that makes this amenable to the super simple "just count all changed states".

Let's catch up on Monday and see if there's something we can do to be more clever and get around that.

@DaveCTurner
Copy link
Copy Markdown
Member

Oh right yes that's not going to work. How about assertions that there are never any partially-completed states?

diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java
index b52eae61e5e..63c7188d7a3 100644
--- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java
+++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java
@@ -10,6 +10,7 @@ package org.elasticsearch.cluster.metadata;
 
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ClusterStateListener;
 import org.elasticsearch.cluster.ClusterStateTaskConfig;
 import org.elasticsearch.cluster.ClusterStateTaskListener;
 import org.elasticsearch.cluster.metadata.IndexMetadata.APIBlock;
@@ -30,6 +31,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
 import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.oneOf;
 
 public class MetadataIndexStateServiceBatchingTests extends ESSingleNodeTestCase {
 
@@ -60,6 +62,9 @@ public class MetadataIndexStateServiceBatchingTests extends ESSingleNodeTestCase
         assertAcked(client().admin().indices().prepareClose(closedIndices));
         ensureGreen("test-1", "test-2", "test-3");
 
+        final var assertingListener = closedIndexCountListener(closedIndices.length);
+        clusterService.addListener(assertingListener);
+
         final var block1 = blockMasterService(masterService);
         block1.run(); // wait for block
 
@@ -81,12 +86,17 @@ public class MetadataIndexStateServiceBatchingTests extends ESSingleNodeTestCase
             final var indexMetadata = clusterService.state().metadata().indices().get(index);
             assertThat(indexMetadata.getState(), is(State.OPEN));
         }
+
+        clusterService.removeListener(assertingListener);
     }
 
     public void testBatchCloseIndices() throws Exception {
         final var clusterService = getInstanceFromNode(ClusterService.class);
         final var masterService = clusterService.getMasterService();
 
+        final var assertingListener = closedIndexCountListener(3);
+        clusterService.addListener(assertingListener);
+
         // create some indices
         createIndex("test-1", client().admin().indices().prepareCreate("test-1"));
         createIndex("test-2", client().admin().indices().prepareCreate("test-2"));
@@ -130,12 +140,17 @@ public class MetadataIndexStateServiceBatchingTests extends ESSingleNodeTestCase
             final var indexMetadata = clusterService.state().metadata().indices().get(index);
             assertThat(indexMetadata.getState(), is(State.CLOSE));
         }
+
+        clusterService.removeListener(assertingListener);
     }
 
     public void testBatchBlockIndices() throws Exception {
         final var clusterService = getInstanceFromNode(ClusterService.class);
         final var masterService = clusterService.getMasterService();
 
+        final var assertingListener = blockedIndexCountListener();
+        clusterService.addListener(assertingListener);
+
         // create some indices
         createIndex("test-1", client().admin().indices().prepareCreate("test-1"));
         createIndex("test-2", client().admin().indices().prepareCreate("test-2"));
@@ -179,6 +194,8 @@ public class MetadataIndexStateServiceBatchingTests extends ESSingleNodeTestCase
             final var indexMetadata = clusterService.state().metadata().indices().get(index);
             assertThat(INDEX_BLOCKS_WRITE_SETTING.get(indexMetadata.getSettings()), is(true));
         }
+
+        clusterService.removeListener(assertingListener);
     }
 
     private static CheckedRunnable<Exception> blockMasterService(MasterService masterService) {
@@ -200,6 +217,17 @@ public class MetadataIndexStateServiceBatchingTests extends ESSingleNodeTestCase
         return () -> executionBarrier.await(10, TimeUnit.SECONDS);
     }
 
+    private static ClusterStateListener closedIndexCountListener(int closedIndices) {
+        return event -> assertThat(event.state().metadata().getConcreteAllClosedIndices().length, oneOf(0, closedIndices));
+    }
+
+    private static ClusterStateListener blockedIndexCountListener() {
+        return event -> assertThat(
+            event.state().metadata().stream().filter(indexMetadata -> INDEX_BLOCKS_WRITE_SETTING.get(indexMetadata.getSettings())).count(),
+            oneOf(0L, 3L)
+        );
+    }
+
     /**
      * Listener that asserts it does not fail.
      */

joegallo added 2 commits March 7, 2022 17:06
That is, this is checking that we're *actually* batching these
operations
@joegallo
Copy link
Copy Markdown
Contributor Author

joegallo commented Mar 7, 2022

👍, @DaveCTurner I like that approach. Added as a44f745.

@joegallo joegallo requested a review from DaveCTurner March 7, 2022 22:13
Copy link
Copy Markdown
Member

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joegallo joegallo merged commit f114cc9 into elastic:master Mar 8, 2022
@joegallo joegallo deleted the batch-add-blocks branch March 8, 2022 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Data Management/Indices APIs DO NOT USE. Use ":Distributed/Indices APIs" or ":StorageEngine/Templates" instead. >enhancement Team:Data Management (obsolete) DO NOT USE. This team no longer exists. v8.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants