From 6aa6fce81e3dff0ae60735a2d842f39ae3087053 Mon Sep 17 00:00:00 2001 From: Nikolaj Volgushev Date: Thu, 12 Sep 2024 14:57:03 +0200 Subject: [PATCH] More --- .../security/authz/store/NativePrivilegeStore.java | 2 +- .../xpack/security/support/SecurityIndexManager.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStore.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStore.java index 4cd79f7da86e1..f167027762771 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStore.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/NativePrivilegeStore.java @@ -208,7 +208,7 @@ private void innerGetPrivileges( if (frozenSecurityIndex.indexExists() == false) { listener.onResponse(Collections.emptyList()); } else if (frozenSecurityIndex.isAvailable(SEARCH_SHARDS) == false) { - if (false == waitOnUnavailable || false == frozenSecurityIndex.isCreating()) { + if (false == waitOnUnavailable || false == frozenSecurityIndex.indexIsCreating()) { listener.onFailure(frozenSecurityIndex.getUnavailableReason(SEARCH_SHARDS)); return; } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java index 8a13b22518d6e..5d02a6f0487a5 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java @@ -184,9 +184,9 @@ public boolean isAvailable(Availability availability) { throw new IllegalStateException("Unexpected availability enumeration. This is bug, please contact support."); } - public boolean isCreating() { + public boolean indexIsCreating() { // TODO this is not accurate - return this.state.indexAvailableForWrite && this.state.indexAvailableForSearch == false; + return this.state.indexCreating; } public boolean isMappingUpToDate() { @@ -375,21 +375,21 @@ public void onIndexAvailableAfterCreation(ActionListener listener) { } return; } - final BiConsumer indexAvailableForSearchListener = new BiConsumer<>() { + final BiConsumer indexAvailableListener = new BiConsumer<>() { @Override public void accept(SecurityIndexManager.State previousState, SecurityIndexManager.State nextState) { - if (nextState.indexAvailableForSearch) { + if (nextState.indexAvailableForWrite && nextState.indexAvailableForSearch) { if (removeStateListener(this)) { listener.onResponse(null); } } } }; - addStateListener(indexAvailableForSearchListener); + addStateListener(indexAvailableListener); // TODO cleaner cancellation handling -- also, if we complete without cancelling, we should cancel the cancellation... final ThreadPool threadPool = client.threadPool(); threadPool.schedule(() -> { - if (removeStateListener(indexAvailableForSearchListener)) { + if (removeStateListener(indexAvailableListener)) { listener.onFailure(new IllegalStateException("timed out waiting for index")); } }, TimeValue.timeValueSeconds(5), threadPool.generic());