diff --git a/.ci/bwcVersions b/.ci/bwcVersions index 0600d2f3537c7..aa12cf1020510 100644 --- a/.ci/bwcVersions +++ b/.ci/bwcVersions @@ -13,4 +13,5 @@ BWC_VERSION: - "2.4.1" - "2.4.2" - "2.5.0" + - "2.5.1" - "2.6.0" diff --git a/.github/ISSUE_TEMPLATE/failed_check.md b/.github/ISSUE_TEMPLATE/failed_check.md new file mode 100644 index 0000000000000..86d90c2fd0efd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/failed_check.md @@ -0,0 +1,9 @@ +--- +title: Gradle Check Failure. +labels: >test-failure bug +--- + +A gradle check workflow has failed after merge. + +PR: {{ env.workflow_url }} +CommitId: {{ env.pr_from_sha }} diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 5a75d2c877992..2b95fb2510bdd 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -7,12 +7,22 @@ on: jobs: backport: - if: ${{ contains(github.event.label.name, 'backport') }} + name: Backport runs-on: ubuntu-latest + # Only react to merged PRs for security reasons. + # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. + if: > + github.event.pull_request.merged + && ( + github.event.action == 'closed' + || ( + github.event.action == 'labeled' + && contains(github.event.label.name, 'backport') + ) + ) permissions: contents: write pull-requests: write - name: Backport steps: - name: GitHub App token id: github_app_token diff --git a/.github/workflows/dependabot_pr.yml b/.github/workflows/dependabot_pr.yml index ed98bae8978ed..a2ad70709f51a 100644 --- a/.github/workflows/dependabot_pr.yml +++ b/.github/workflows/dependabot_pr.yml @@ -51,7 +51,7 @@ jobs: - name: Update the changelog uses: dangoslen/dependabot-changelog-helper@v1 with: - version: 'Unreleased' + version: 'Unreleased 3.0' - name: Commit the changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/.github/workflows/gradle-check.yml b/.github/workflows/gradle-check.yml index 9567bcd63bc2e..2cfcfa8d9d1f9 100644 --- a/.github/workflows/gradle-check.yml +++ b/.github/workflows/gradle-check.yml @@ -16,6 +16,7 @@ jobs: permissions: contents: read # to fetch code (actions/checkout) pull-requests: write # to create or update comment (peter-evans/create-or-update-comment) + issues: write # To create an issue if check fails on push. runs-on: ubuntu-latest timeout-minutes: 130 @@ -123,3 +124,12 @@ jobs: * **CommitID:** ${{ env.pr_from_sha }} Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure [a flaky test](https://github.com/opensearch-project/OpenSearch/blob/main/DEVELOPER_GUIDE.md#flaky-tests) unrelated to your change? + + - name: Create Issue On Push Failure + if: ${{ github.event_name == 'push' && failure() }} + uses: dblock/create-a-github-issue@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + assignees: ${{ github.event.head_commit.author.username }}, ${{ github.triggering_actor }} + filename: .github/ISSUE_TEMPLATE/failed_check.md diff --git a/.gitignore b/.gitignore index a0dabfb8798f9..9ab7de894636a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,10 @@ out/ !.idea/vcs.xml !.idea/icon.svg -# These files are generated in the main tree by IntelliJ +# These files are generated in the main tree by annotation processors benchmarks/src/main/generated/* +benchmarks/bin/* +benchmarks/build-eclipse-default/* # eclipse files .project diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f9075b6a4ed3..2add4f68b884a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,46 +1,27 @@ - # CHANGELOG -## [Unreleased] -### Dependencies -- Bumps `azure-core-http-netty` from 1.12.7 to 1.12.8 -- Bumps `reactor-netty` from 1.1.1 to 1.1.2 - - All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See the [CONTRIBUTING guide](./CONTRIBUTING.md#Changelog) for instructions on how to add changelog entries. ## [Unreleased 3.0] ### Added -- Add support of default replica count cluster setting ([#5610](https://github.com/opensearch-project/OpenSearch/pull/5610)) - Hardened token permissions in GitHub workflows ([#4587](https://github.com/opensearch-project/OpenSearch/pull/4587)) - Support for HTTP/2 (server-side) ([#3847](https://github.com/opensearch-project/OpenSearch/pull/3847)) - Add getter for path field in NestedQueryBuilder ([#4636](https://github.com/opensearch-project/OpenSearch/pull/4636)) -- Apply reproducible builds configuration for OpenSearch plugins through gradle plugin ([#4746](https://github.com/opensearch-project/OpenSearch/pull/4746)) -- Add project health badges to the README.md ([#4843](https://github.com/opensearch-project/OpenSearch/pull/4843)) -- [Test] Add IAE test for deprecated edgeNGram analyzer name ([#5040](https://github.com/opensearch-project/OpenSearch/pull/5040)) - Allow mmap to use new JDK-19 preview APIs in Apache Lucene 9.4+ ([#5151](https://github.com/opensearch-project/OpenSearch/pull/5151)) -- Add feature flag for extensions ([#5211](https://github.com/opensearch-project/OpenSearch/pull/5211)) -- Support to fail open requests on search shard failures with weighted traffic routing ([#5072](https://github.com/opensearch-project/OpenSearch/pull/5072)) -- Added jackson dependency to server ([#5366] (https://github.com/opensearch-project/OpenSearch/pull/5366)) -- Adding support to register settings dynamically ([#5495](https://github.com/opensearch-project/OpenSearch/pull/5495)) -- Added experimental support for extensions ([#5347](https://github.com/opensearch-project/OpenSearch/pull/5347)), ([#5518](https://github.com/opensearch-project/OpenSearch/pull/5518), ([#5597](https://github.com/opensearch-project/OpenSearch/pull/5597)), ([#5615](https://github.com/opensearch-project/OpenSearch/pull/5615))) -- Add CI bundle pattern to distribution download ([#5348](https://github.com/opensearch-project/OpenSearch/pull/5348)) - Add support for ppc64le architecture ([#5459](https://github.com/opensearch-project/OpenSearch/pull/5459)) -- Support versioning for Weighted routing apis([#5255](https://github.com/opensearch-project/OpenSearch/pull/5255)) -- Added @gbbafna as an OpenSearch maintainer ([#5668](https://github.com/opensearch-project/OpenSearch/pull/5668)) -- Add support for discovered cluster manager and remove local weights ([#5680](https://github.com/opensearch-project/OpenSearch/pull/5680)) -- Added support for feature flags in opensearch.yml ([#4959](https://github.com/opensearch-project/OpenSearch/pull/4959)) -- Add query for initialized extensions ([#5658](https://github.com/opensearch-project/OpenSearch/pull/5658)) -- Revert 'Added jackson dependency to server' and change extension reading ([#5768](https://github.com/opensearch-project/OpenSearch/pull/5768)) - Add support to disallow search request with preference parameter with strict weighted shard routing([#5874](https://github.com/opensearch-project/OpenSearch/pull/5874)) +- Replace latches with CompletableFutures for extensions ([#5646](https://github.com/opensearch-project/OpenSearch/pull/5646)) +### Dependencies +- Bumps `wiremock-jre8-standalone` from 2.33.2 to 2.35.0 +- Bumps `gson` from 2.10 to 2.10.1 +- Bumps `json-schema-validator` from 1.0.73 to 1.0.76 ### Dependencies - Bumps `log4j-core` from 2.18.0 to 2.19.0 - Bumps `reactor-netty-http` from 1.0.18 to 1.0.23 - Bumps `jettison` from 1.5.0 to 1.5.3 - Bumps `forbiddenapis` from 3.3 to 3.4 -- Bumps `gson` from 2.9.0 to 2.10 - Bumps `avro` from 1.11.0 to 1.11.1 - Bumps `woodstox-core` from 6.3.0 to 6.3.1 - Bumps `xmlbeans` from 5.1.0 to 5.1.1 ([#4354](https://github.com/opensearch-project/OpenSearch/pull/4354)) @@ -51,32 +32,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Bumps `com.diffplug.spotless` from 6.10.0 to 6.11.0 ([#4547](https://github.com/opensearch-project/OpenSearch/pull/4547)) - Bumps `reactor-core` from 3.4.23 to 3.5.1 ([#5604](https://github.com/opensearch-project/OpenSearch/pull/5604)) - Bumps `jempbox` from 1.8.16 to 1.8.17 ([#4550](https://github.com/opensearch-project/OpenSearch/pull/4550)) -- Bumps `commons-compress` from 1.21 to 1.22 -- Bumps `jcodings` from 1.0.57 to 1.0.58 ([#5233](https://github.com/opensearch-project/OpenSearch/pull/5233)) -- Bumps `google-http-client-jackson2` from 1.35.0 to 1.42.3 ([#5234](https://github.com/opensearch-project/OpenSearch/pull/5234)) -- Bumps `azure-core` from 1.33.0 to 1.34.0 ([#5235](https://github.com/opensearch-project/OpenSearch/pull/5235)) -- Bumps `azure-core-http-netty` from 1.12.4 to 1.12.7 ([#5235](https://github.com/opensearch-project/OpenSearch/pull/5235)) - Bumps `spock-core` from 2.1-groovy-3.0 to 2.3-groovy-3.0 ([#5315](https://github.com/opensearch-project/OpenSearch/pull/5315)) -- Bumps `json-schema-validator` from 1.0.69 to 1.0.73 ([#5316](https://github.com/opensearch-project/OpenSearch/pull/5316)) -- Bumps `proto-google-common-protos` from 2.8.0 to 2.10.0 ([#5318](https://github.com/opensearch-project/OpenSearch/pull/5318)) - Update to Gradle 7.6 and JDK-19 ([#4973](https://github.com/opensearch-project/OpenSearch/pull/4973)) - Update Apache Lucene to 9.5.0-snapshot-d5cef1c ([#5570](https://github.com/opensearch-project/OpenSearch/pull/5570)) - Bump antlr4 from 4.9.3 to 4.11.1 ([#4546](https://github.com/opensearch-project/OpenSearch/pull/4546)) - Bumps `maven-model` from 3.6.2 to 3.8.6 ([#5599](https://github.com/opensearch-project/OpenSearch/pull/5599)) - Bumps `maxmind-db` from 2.1.0 to 3.0.0 ([#5601](https://github.com/opensearch-project/OpenSearch/pull/5601)) - Bumps `protobuf-java` from 3.21.11 to 3.21.12 ([#5603](https://github.com/opensearch-project/OpenSearch/pull/5603)) -- Update nebula-publishing-plugin to 19.2.0 ([#5704](https://github.com/opensearch-project/OpenSearch/pull/5704)) +- Bumps `azure-core-http-netty` from 1.12.7 to 1.12.8 ### Changed - [CCR] Add getHistoryOperationsFromTranslog method to fetch the history snapshot from translogs ([#3948](https://github.com/opensearch-project/OpenSearch/pull/3948)) - Relax visibility of the HTTP_CHANNEL_KEY and HTTP_SERVER_CHANNEL_KEY to make it possible for the plugins to access associated Netty4HttpChannel / Netty4HttpServerChannel instance ([#4638](https://github.com/opensearch-project/OpenSearch/pull/4638)) -- Use ReplicationFailedException instead of OpensearchException in ReplicationTarget ([#4725](https://github.com/opensearch-project/OpenSearch/pull/4725)) - Migrate client transports to Apache HttpClient / Core 5.x ([#4459](https://github.com/opensearch-project/OpenSearch/pull/4459)) -- Support remote translog transfer for request level durability([#4480](https://github.com/opensearch-project/OpenSearch/pull/4480)) - Changed http code on create index API with bad input raising NotXContentException from 500 to 400 ([#4773](https://github.com/opensearch-project/OpenSearch/pull/4773)) - Change http code for DecommissioningFailedException from 500 to 400 ([#5283](https://github.com/opensearch-project/OpenSearch/pull/5283)) -- Pre conditions check before updating weighted routing metadata ([#4955](https://github.com/opensearch-project/OpenSearch/pull/4955)) -- Gracefully handle concurrent zone decommission action ([#5542](https://github.com/opensearch-project/OpenSearch/pull/5542)) ### Deprecated @@ -98,29 +68,34 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - Fix 'org.apache.hc.core5.http.ParseException: Invalid protocol version' under JDK 16+ ([#4827](https://github.com/opensearch-project/OpenSearch/pull/4827)) - Fixed compression support for h2c protocol ([#4944](https://github.com/opensearch-project/OpenSearch/pull/4944)) -- Reject bulk requests with invalid actions ([#5299](https://github.com/opensearch-project/OpenSearch/issues/5299)) - Support OpenSSL Provider with default Netty allocator ([#5460](https://github.com/opensearch-project/OpenSearch/pull/5460)) -- Increasing timeout of testQuorumRecovery to 90 seconds from 30 ([#5651](https://github.com/opensearch-project/OpenSearch/pull/5651)) -- [Segment Replication] Fix for peer recovery ([#5344](https://github.com/opensearch-project/OpenSearch/pull/5344)) -- [Test] Renaming PIT tests to IT to fix intermittent test failures ([#5750](https://github.com/opensearch-project/OpenSearch/pull/5750)) ### Security ## [Unreleased 2.x] ### Added +- Adding index create block when all nodes have breached high disk watermark ([#5852](https://github.com/opensearch-project/OpenSearch/pull/5852)) - Added cluster manager throttling stats in nodes/stats API ([#5790](https://github.com/opensearch-project/OpenSearch/pull/5790)) +- Added support for feature flags in opensearch.yml ([#4959](https://github.com/opensearch-project/OpenSearch/pull/4959)) +- Add query for initialized extensions ([#5658](https://github.com/opensearch-project/OpenSearch/pull/5658)) +- Add update-index-settings allowlist for searchable snapshot ([#5907](https://github.com/opensearch-project/OpenSearch/pull/5907)) ### Dependencies +- Update nebula-publishing-plugin to 19.2.0 ([#5704](https://github.com/opensearch-project/OpenSearch/pull/5704)) +- Bumps `reactor-netty` from 1.1.1 to 1.1.2 ### Changed +- Use ReplicationFailedException instead of OpensearchException in ReplicationTarget ([#4725](https://github.com/opensearch-project/OpenSearch/pull/4725)) +- [Refactor] Use local opensearch.common.SetOnce instead of lucene's utility class ([#5947](https://github.com/opensearch-project/OpenSearch/pull/5947)) ### Deprecated ### Removed ### Fixed +- [Segment Replication] Fix for peer recovery ([#5344](https://github.com/opensearch-project/OpenSearch/pull/5344)) ### Security -[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.4...HEAD -[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.4...2.x +[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD +[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x \ No newline at end of file diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 129f60378b47e..58849bb637429 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -118,14 +118,14 @@ dependencies { api 'com.avast.gradle:gradle-docker-compose-plugin:0.15.2' api "org.yaml:snakeyaml:${props.getProperty('snakeyaml')}" api 'org.apache.maven:maven-model:3.8.6' - api 'com.networknt:json-schema-validator:1.0.73' + api 'com.networknt:json-schema-validator:1.0.76' api "com.fasterxml.jackson.core:jackson-databind:${props.getProperty('jackson_databind')}" testFixturesApi "junit:junit:${props.getProperty('junit')}" testFixturesApi "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}" testFixturesApi gradleApi() testFixturesApi gradleTestKit() - testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.33.2' + testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.35.0' testImplementation "org.mockito:mockito-core:${props.getProperty('mockito')}" integTestImplementation('org.spockframework:spock-core:2.3-groovy-3.0') { exclude module: "groovy" diff --git a/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt b/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt index 1e4e669e4722f..f9f24fd1e2367 100644 --- a/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt +++ b/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt @@ -50,6 +50,7 @@ java.nio.channels.SocketChannel#connect(java.net.SocketAddress) java.lang.Boolean#getBoolean(java.lang.String) org.apache.lucene.util.IOUtils @ use @org.opensearch.core.internal.io instead +org.apache.lucene.util.SetOnce @ use @org.opensearch.common.SetOnce instead @defaultMessage use executors from org.opensearch.common.util.concurrent.OpenSearchExecutors instead which will properly bubble up Errors java.util.concurrent.AbstractExecutorService#() diff --git a/libs/core/src/main/java/org/opensearch/common/SetOnce.java b/libs/core/src/main/java/org/opensearch/common/SetOnce.java new file mode 100644 index 0000000000000..a596b5fcdb61d --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/common/SetOnce.java @@ -0,0 +1,104 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ +package org.opensearch.common; + +import java.util.concurrent.atomic.AtomicReference; + +/** + * A convenient class which offers a semi-immutable object wrapper implementation which allows one + * to set the value of an object exactly once, and retrieve it many times. If {@link #set(Object)} + * is called more than once, {@link AlreadySetException} is thrown and the operation will fail. + * + * This is borrowed from lucene's experimental API. It is not reused to eliminate the dependency + * on lucene core for such a simple (standalone) utility class that may change beyond OpenSearch needs. + * + * @opensearch.api + */ +public final class SetOnce implements Cloneable { + + /** Thrown when {@link SetOnce#set(Object)} is called more than once. */ + public static final class AlreadySetException extends IllegalStateException { + public AlreadySetException() { + super("The object cannot be set twice!"); + } + } + + /** Holding object and marking that it was already set */ + private static final class Wrapper { + private T object; + + private Wrapper(T object) { + this.object = object; + } + } + + private final AtomicReference> set; + + /** + * A default constructor which does not set the internal object, and allows setting it by calling + * {@link #set(Object)}. + */ + public SetOnce() { + set = new AtomicReference<>(); + } + + /** + * Creates a new instance with the internal object set to the given object. Note that any calls to + * {@link #set(Object)} afterwards will result in {@link AlreadySetException} + * + * @throws AlreadySetException if called more than once + * @see #set(Object) + */ + public SetOnce(T obj) { + set = new AtomicReference<>(new Wrapper<>(obj)); + } + + /** Sets the given object. If the object has already been set, an exception is thrown. */ + public final void set(T obj) { + if (!trySet(obj)) { + throw new AlreadySetException(); + } + } + + /** + * Sets the given object if none was set before. + * + * @return true if object was set successfully, false otherwise + */ + public final boolean trySet(T obj) { + return set.compareAndSet(null, new Wrapper<>(obj)); + } + + /** Returns the object set by {@link #set(Object)}. */ + public final T get() { + Wrapper wrapper = set.get(); + return wrapper == null ? null : wrapper.object; + } +} diff --git a/libs/core/src/test/java/org/opensearch/common/SetOnceTests.java b/libs/core/src/test/java/org/opensearch/common/SetOnceTests.java new file mode 100644 index 0000000000000..0392ff62dd115 --- /dev/null +++ b/libs/core/src/test/java/org/opensearch/common/SetOnceTests.java @@ -0,0 +1,120 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +package org.opensearch.common; + +import org.opensearch.common.SetOnce.AlreadySetException; +import org.opensearch.test.OpenSearchTestCase; + +import java.util.Random; + +import static org.hamcrest.CoreMatchers.containsString; + +public class SetOnceTests extends OpenSearchTestCase { + private static final class SetOnceThread extends Thread { + SetOnce set; + boolean success = false; + final Random RAND; + + public SetOnceThread(Random random) { + RAND = new Random(random.nextLong()); + } + + @Override + public void run() { + try { + sleep(RAND.nextInt(10)); // sleep for a short time + set.set(Integer.valueOf(getName().substring(2))); + success = true; + } catch (@SuppressWarnings("unused") InterruptedException e) { + // ignore + } catch (@SuppressWarnings("unused") RuntimeException e) { + // TODO: change exception type + // expected. + success = false; + } + } + } + + public void testEmptyCtor() { + SetOnce set = new SetOnce<>(); + assertNull(set.get()); + } + + public void testSettingCtor() { + SetOnce set = new SetOnce<>(5); + assertEquals(5, set.get().intValue()); + + AlreadySetException alreadySetException = expectThrows(AlreadySetException.class, () -> set.set(7)); + assertThat(alreadySetException.getMessage(), containsString("The object cannot be set twice!")); + } + + public void testSetOnce() { + SetOnce set = new SetOnce<>(); + set.set(5); + assertEquals(5, set.get().intValue()); + + AlreadySetException alreadySetException = expectThrows(AlreadySetException.class, () -> set.set(7)); + assertThat(alreadySetException.getMessage(), containsString("The object cannot be set twice!")); + } + + public void testTrySet() { + SetOnce set = new SetOnce<>(); + assertTrue(set.trySet(5)); + assertEquals(5, set.get().intValue()); + assertFalse(set.trySet(7)); + assertEquals(5, set.get().intValue()); + } + + public void testSetMultiThreaded() throws Exception { + final SetOnce set = new SetOnce<>(); + SetOnceThread[] threads = new SetOnceThread[10]; + for (int i = 0; i < threads.length; i++) { + threads[i] = new SetOnceThread(random()); + threads[i].setName("t-" + (i + 1)); + threads[i].set = set; + } + + for (Thread t : threads) { + t.start(); + } + + for (Thread t : threads) { + t.join(); + } + + for (SetOnceThread t : threads) { + if (t.success) { + int expectedVal = Integer.parseInt(t.getName().substring(2)); + assertEquals("thread " + t.getName(), expectedVal, t.set.get().intValue()); + } + } + } +} diff --git a/modules/analysis-common/src/main/java/org/opensearch/analysis/common/CommonAnalysisModulePlugin.java b/modules/analysis-common/src/main/java/org/opensearch/analysis/common/CommonAnalysisModulePlugin.java index a26912733a9c6..67a0c3b13f8fb 100644 --- a/modules/analysis-common/src/main/java/org/opensearch/analysis/common/CommonAnalysisModulePlugin.java +++ b/modules/analysis-common/src/main/java/org/opensearch/analysis/common/CommonAnalysisModulePlugin.java @@ -123,11 +123,11 @@ import org.apache.lucene.analysis.tr.ApostropheFilter; import org.apache.lucene.analysis.tr.TurkishAnalyzer; import org.apache.lucene.analysis.util.ElisionFilter; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.regex.Regex; diff --git a/modules/ingest-geoip/src/main/java/org/opensearch/ingest/geoip/DatabaseReaderLazyLoader.java b/modules/ingest-geoip/src/main/java/org/opensearch/ingest/geoip/DatabaseReaderLazyLoader.java index 70feb44f0f385..44b03744b6685 100644 --- a/modules/ingest-geoip/src/main/java/org/opensearch/ingest/geoip/DatabaseReaderLazyLoader.java +++ b/modules/ingest-geoip/src/main/java/org/opensearch/ingest/geoip/DatabaseReaderLazyLoader.java @@ -35,8 +35,8 @@ import com.maxmind.geoip2.DatabaseReader; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.CheckedSupplier; +import org.opensearch.common.SetOnce; import org.opensearch.core.internal.io.IOUtils; import java.io.Closeable; diff --git a/modules/lang-painless/src/main/java/org/opensearch/painless/PainlessModulePlugin.java b/modules/lang-painless/src/main/java/org/opensearch/painless/PainlessModulePlugin.java index 4a432b8f17b25..144f02ee7d74e 100644 --- a/modules/lang-painless/src/main/java/org/opensearch/painless/PainlessModulePlugin.java +++ b/modules/lang-painless/src/main/java/org/opensearch/painless/PainlessModulePlugin.java @@ -32,13 +32,13 @@ package org.opensearch.painless; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionRequest; import org.opensearch.action.ActionResponse; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.IndexScopedSettings; diff --git a/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java index 4f4665c434c67..11d9d274e1e9b 100644 --- a/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/opensearch/percolator/PercolateQueryBuilder.java @@ -54,13 +54,13 @@ import org.apache.lucene.util.BitDocIdSet; import org.apache.lucene.util.BitSet; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchException; import org.opensearch.ResourceNotFoundException; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.get.GetRequest; import org.opensearch.common.ParseField; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.InputStreamStreamInput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexFromRemoteWithAuthTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexFromRemoteWithAuthTests.java index dd7eb977bbe48..a5de8e56c8d6f 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexFromRemoteWithAuthTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/ReindexFromRemoteWithAuthTests.java @@ -32,7 +32,6 @@ package org.opensearch.index.reindex; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchSecurityException; import org.opensearch.OpenSearchStatusException; import org.opensearch.action.ActionListener; @@ -46,6 +45,7 @@ import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.network.NetworkModule; diff --git a/modules/systemd/src/main/java/org/opensearch/systemd/SystemdModulePlugin.java b/modules/systemd/src/main/java/org/opensearch/systemd/SystemdModulePlugin.java index a22b3f862e017..a2966c059d4d2 100644 --- a/modules/systemd/src/main/java/org/opensearch/systemd/SystemdModulePlugin.java +++ b/modules/systemd/src/main/java/org/opensearch/systemd/SystemdModulePlugin.java @@ -34,10 +34,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.NamedXContentRegistry; diff --git a/modules/transport-netty4/src/main/java/org/opensearch/transport/Netty4ModulePlugin.java b/modules/transport-netty4/src/main/java/org/opensearch/transport/Netty4ModulePlugin.java index 8a18210fd963e..5ad8b11f9fe6e 100644 --- a/modules/transport-netty4/src/main/java/org/opensearch/transport/Netty4ModulePlugin.java +++ b/modules/transport-netty4/src/main/java/org/opensearch/transport/Netty4ModulePlugin.java @@ -32,8 +32,8 @@ package org.opensearch.transport; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.network.NetworkModule; import org.opensearch.common.network.NetworkService; diff --git a/plugins/discovery-gce/src/main/java/org/opensearch/plugin/discovery/gce/GceDiscoveryPlugin.java b/plugins/discovery-gce/src/main/java/org/opensearch/plugin/discovery/gce/GceDiscoveryPlugin.java index 6d015f54ffb29..282361c893689 100644 --- a/plugins/discovery-gce/src/main/java/org/opensearch/plugin/discovery/gce/GceDiscoveryPlugin.java +++ b/plugins/discovery-gce/src/main/java/org/opensearch/plugin/discovery/gce/GceDiscoveryPlugin.java @@ -36,13 +36,13 @@ import com.google.api.client.util.ClassInfo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; import org.opensearch.cloud.gce.GceInstancesService; import org.opensearch.cloud.gce.GceInstancesServiceImpl; import org.opensearch.cloud.gce.GceMetadataService; import org.opensearch.cloud.gce.network.GceNameResolver; import org.opensearch.cloud.gce.util.Access; import org.opensearch.common.Booleans; +import org.opensearch.common.SetOnce; import org.opensearch.common.network.NetworkService; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; diff --git a/plugins/repository-hdfs/build.gradle b/plugins/repository-hdfs/build.gradle index 0259be3428a82..481548e9a3252 100644 --- a/plugins/repository-hdfs/build.gradle +++ b/plugins/repository-hdfs/build.gradle @@ -66,7 +66,7 @@ dependencies { api 'org.apache.htrace:htrace-core4:4.2.0-incubating' api "org.apache.logging.log4j:log4j-core:${versions.log4j}" api 'org.apache.avro:avro:1.11.1' - api 'com.google.code.gson:gson:2.10' + api 'com.google.code.gson:gson:2.10.1' runtimeOnly 'com.google.guava:guava:31.1-jre' api 'com.google.protobuf:protobuf-java:3.21.12' api "commons-logging:commons-logging:${versions.commonslogging}" diff --git a/plugins/repository-hdfs/licenses/gson-2.10.1.jar.sha1 b/plugins/repository-hdfs/licenses/gson-2.10.1.jar.sha1 new file mode 100644 index 0000000000000..9810309d1013a --- /dev/null +++ b/plugins/repository-hdfs/licenses/gson-2.10.1.jar.sha1 @@ -0,0 +1 @@ +b3add478d4382b78ea20b1671390a858002feb6c \ No newline at end of file diff --git a/plugins/repository-hdfs/licenses/gson-2.10.jar.sha1 b/plugins/repository-hdfs/licenses/gson-2.10.jar.sha1 deleted file mode 100644 index 64f28f71ab421..0000000000000 --- a/plugins/repository-hdfs/licenses/gson-2.10.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -dd9b193aef96e973d5a11ab13cd17430c2e4306b \ No newline at end of file diff --git a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3BlobContainer.java b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3BlobContainer.java index 678be7c6f13f2..c2c272b2527a2 100644 --- a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3BlobContainer.java +++ b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3BlobContainer.java @@ -48,9 +48,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.lucene.util.SetOnce; import org.opensearch.ExceptionsHelper; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.blobstore.BlobContainer; import org.opensearch.common.blobstore.BlobMetadata; diff --git a/plugins/transport-nio/src/main/java/org/opensearch/transport/nio/NioTransportPlugin.java b/plugins/transport-nio/src/main/java/org/opensearch/transport/nio/NioTransportPlugin.java index f8816e0686e9d..88e99b232d2da 100644 --- a/plugins/transport-nio/src/main/java/org/opensearch/transport/nio/NioTransportPlugin.java +++ b/plugins/transport-nio/src/main/java/org/opensearch/transport/nio/NioTransportPlugin.java @@ -34,8 +34,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.network.NetworkService; import org.opensearch.common.settings.ClusterSettings; diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java index 42c7357de3f07..c15678a3f2f38 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/SearchRestCancellationIT.java @@ -34,7 +34,6 @@ import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.io.entity.ByteArrayEntity; import org.apache.logging.log4j.LogManager; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.admin.cluster.node.info.NodeInfo; import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse; import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse; @@ -48,6 +47,7 @@ import org.opensearch.client.Request; import org.opensearch.client.Response; import org.opensearch.client.ResponseListener; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.xcontent.XContentType; import org.opensearch.plugins.Plugin; diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/CancellableTasksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/CancellableTasksIT.java index 6c507171091e7..6743efda8e5e3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/CancellableTasksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/node/tasks/CancellableTasksIT.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.cluster.node.tasks; -import org.apache.lucene.util.SetOnce; import org.opensearch.ExceptionsHelper; import org.opensearch.ResourceNotFoundException; import org.opensearch.action.ActionFuture; @@ -50,6 +49,7 @@ import org.opensearch.action.support.PlainActionFuture; import org.opensearch.client.node.NodeClient; import org.opensearch.cluster.node.DiscoveryNode; +import org.opensearch.common.SetOnce; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java index 4664648c03ccc..561e4349a4890 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java @@ -39,11 +39,14 @@ import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; +import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; import org.opensearch.action.admin.indices.stats.ShardStats; import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.cluster.ClusterInfoService; +import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.InternalClusterInfoService; import org.opensearch.cluster.metadata.IndexMetadata; +import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.routing.IndexShardRoutingTable; import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; @@ -82,12 +85,15 @@ import java.nio.file.NotDirectoryException; import java.nio.file.Path; import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -126,7 +132,9 @@ public void removeFilesystemProvider() { defaultFileSystem = null; } - private static final long WATERMARK_BYTES = new ByteSizeValue(10, ByteSizeUnit.KB).getBytes(); + // Increasing watermark limit to avoid flaky test case failures. + private static final long WATERMARK_BYTES = new ByteSizeValue(1, ByteSizeUnit.MB).getBytes(); + private static final String INDEX_ROUTING_ALLOCATION_NODE_SETTING = "index.routing.allocation.include._name"; @Override protected Settings nodeSettings(int nodeOrdinal) { @@ -167,16 +175,7 @@ public void testHighWatermarkNotExceeded() throws Exception { final Path dataNode0Path = internalCluster().getInstance(Environment.class, dataNodeName).dataFiles()[0]; final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createIndex( - indexName, - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 6) - .put(INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), "0ms") - .put(IndexSettings.INDEX_MERGE_ON_FLUSH_ENABLED.getKey(), false) - .build() - ); - final long minShardSize = createReasonableSizedShards(indexName); + final long minShardSize = createAndPopulateIndex(indexName, null); // reduce disk size of node 0 so that no shards fit below the high watermark, forcing all shards onto the other data node // (subtract the translog size since the disk threshold decider ignores this and may therefore move the shard back again) @@ -188,6 +187,124 @@ public void testHighWatermarkNotExceeded() throws Exception { assertBusyWithDiskUsageRefresh(dataNode0Id, indexName, hasSize(1)); } + public void testIndexCreateBlockWhenAllNodesExceededHighWatermark() throws Exception { + internalCluster().startClusterManagerOnlyNode(); + final List dataNodeNames = internalCluster().startDataOnlyNodes(2); + ensureStableCluster(3); + + final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) internalCluster() + .getCurrentClusterManagerNodeInstance(ClusterInfoService.class); + internalCluster().getCurrentClusterManagerNodeInstance(ClusterService.class).addListener(event -> clusterInfoService.refresh()); + + // Reduce disk space of all node until all of them is breaching high disk watermark. + for (final String dataNodeName : dataNodeNames) { + populateNode(dataNodeName); + } + + // Wait for all nodes to breach high disk watermark. + assertBusy(() -> { + refreshDiskUsage(); + assertTrue( + StreamSupport.stream(clusterInfoService.getClusterInfo().getNodeLeastAvailableDiskUsages().values().spliterator(), false) + .allMatch(cur -> cur.value.getFreeBytes() < WATERMARK_BYTES) + ); + }, 30L, TimeUnit.SECONDS); + + // Validate if cluster block is applied on the cluster + ClusterState state = client().admin().cluster().prepareState().setLocal(true).get().getState(); + assertTrue(state.blocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())); + } + + public void testIndexCreateBlockNotAppliedWhenAnyNodesBelowHighWatermark() throws Exception { + internalCluster().startClusterManagerOnlyNode(); + final List dataNodeNames = internalCluster().startDataOnlyNodes(2); + ensureStableCluster(3); + + final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) internalCluster() + .getCurrentClusterManagerNodeInstance(ClusterInfoService.class); + internalCluster().getCurrentClusterManagerNodeInstance(ClusterService.class).addListener(event -> clusterInfoService.refresh()); + + // Validate cluster block is not applied on the cluster + ClusterState state = client().admin().cluster().prepareState().setLocal(true).get().getState(); + assertFalse(state.blocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())); + } + + public void testIndexCreateBlockIsRemovedWhenAnyNodesNotExceedHighWatermark() throws Exception { + internalCluster().startClusterManagerOnlyNode(); + final List dataNodeNames = internalCluster().startDataOnlyNodes(2); + final List indexNames = new ArrayList<>(); + ensureStableCluster(3); + + final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) internalCluster() + .getCurrentClusterManagerNodeInstance(ClusterInfoService.class); + internalCluster().getCurrentClusterManagerNodeInstance(ClusterService.class).addListener(event -> clusterInfoService.refresh()); + + // Reduce disk space of all node until all of them is breaching high disk watermark. + for (final String dataNodeName : dataNodeNames) { + final String indexName = populateNode(dataNodeName); + indexNames.add(indexName); + } + + // Wait for all the node to breach high disk watermark. + assertBusy(() -> { + refreshDiskUsage(); + assertTrue( + StreamSupport.stream(clusterInfoService.getClusterInfo().getNodeLeastAvailableDiskUsages().values().spliterator(), false) + .allMatch(cur -> cur.value.getFreeBytes() < WATERMARK_BYTES) + ); + }, 30L, TimeUnit.SECONDS); + + // Validate if index create block is applied on the cluster + ClusterState state = client().admin().cluster().prepareState().setLocal(true).get().getState(); + assertTrue(state.blocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())); + + // Delete indices to free space + deleteIndices(indexNames); + + // Validate if index create block is removed on the cluster + assertBusy(() -> { + refreshDiskUsage(); + ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).get().getState(); + assertFalse(state1.blocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())); + }, 30L, TimeUnit.SECONDS); + } + + public void testIndexCreateBlockWithAReadOnlyBlock() throws Exception { + internalCluster().startClusterManagerOnlyNode(); + final List dataNodeNames = internalCluster().startDataOnlyNodes(2); + ensureStableCluster(3); + final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) internalCluster() + .getCurrentClusterManagerNodeInstance(ClusterInfoService.class); + internalCluster().getCurrentClusterManagerNodeInstance(ClusterService.class).addListener(event -> clusterInfoService.refresh()); + + // Create one of the index. + final String indexName = populateNode(dataNodeNames.get(0)); + + // Reduce disk space of all other node until all of them is breaching high disk watermark. + for (int i = 1; i < dataNodeNames.size(); i++) { + populateNode(dataNodeNames.get(i)); + } + + // Apply a read_only_allow_delete_block on one of the index + // (can happen if the corresponding node has breached flood stage watermark). + final Settings readOnlySettings = Settings.builder() + .put(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, Boolean.TRUE.toString()) + .build(); + client().admin().indices().prepareUpdateSettings(indexName).setSettings(readOnlySettings).get(); + + assertBusy(() -> { + refreshDiskUsage(); + assertTrue( + StreamSupport.stream(clusterInfoService.getClusterInfo().getNodeLeastAvailableDiskUsages().values().spliterator(), false) + .allMatch(cur -> cur.value.getFreeBytes() < WATERMARK_BYTES) + ); + }, 30L, TimeUnit.SECONDS); + + // Validate index create block is applied on the cluster. + ClusterState state = client().admin().cluster().prepareState().setLocal(true).get().getState(); + assertTrue(state.blocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())); + } + public void testRestoreSnapshotAllocationDoesNotExceedWatermark() throws Exception { internalCluster().startClusterManagerOnlyNode(); internalCluster().startDataOnlyNode(); @@ -210,16 +327,7 @@ public void testRestoreSnapshotAllocationDoesNotExceedWatermark() throws Excepti final Path dataNode0Path = internalCluster().getInstance(Environment.class, dataNodeName).dataFiles()[0]; final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); - createIndex( - indexName, - Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 6) - .put(INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), "0ms") - .put(IndexSettings.INDEX_MERGE_ON_FLUSH_ENABLED.getKey(), false) - .build() - ); - final long minShardSize = createReasonableSizedShards(indexName); + final long minShardSize = createAndPopulateIndex(indexName, null); final CreateSnapshotResponse createSnapshotResponse = client().admin() .cluster() @@ -274,6 +382,40 @@ public void testRestoreSnapshotAllocationDoesNotExceedWatermark() throws Excepti assertBusyWithDiskUsageRefresh(dataNode0Id, indexName, hasSize(1)); } + private void deleteIndices(final List indexNames) throws ExecutionException, InterruptedException { + for (String indexName : indexNames) { + assertAcked(client().admin().indices().delete(new DeleteIndexRequest(indexName)).get()); + assertFalse("index [" + indexName + "] should have been deleted", indexExists(indexName)); + } + } + + private String populateNode(final String dataNodeName) throws Exception { + final Path dataNodePath = internalCluster().getInstance(Environment.class, dataNodeName).dataFiles()[0]; + final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); + long minShardSize = createAndPopulateIndex(indexName, dataNodeName); + fileSystemProvider.getTestFileStore(dataNodePath).setTotalSpace(minShardSize + WATERMARK_BYTES - 1L); + refreshDiskUsage(); + return indexName; + } + + private long createAndPopulateIndex(final String indexName, final String nodeName) throws Exception { + + final Settings.Builder indexSettingBuilder = Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) + .put(INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), "0ms") + .put(IndexSettings.INDEX_MERGE_ON_FLUSH_ENABLED.getKey(), false); + + // Depending on node name specified or not, we determine whether to enable node name based shard routing for index. + if (nodeName != null) { + indexSettingBuilder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(INDEX_ROUTING_ALLOCATION_NODE_SETTING, nodeName); + } else { + indexSettingBuilder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 6); + } + + createIndex(indexName, indexSettingBuilder.build()); + return createReasonableSizedShards(indexName); + } + private Set getShardRoutings(final String nodeId, final String indexName) { final Set shardRoutings = new HashSet<>(); for (IndexShardRoutingTable indexShardRoutingTable : client().admin() diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java index bb1456c8b5d4f..a7ab1dc7c7d39 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java @@ -34,7 +34,6 @@ import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.index.IndexCommit; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; @@ -72,6 +71,7 @@ import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Priority; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.breaker.CircuitBreaker; import org.opensearch.common.breaker.CircuitBreakingException; diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java index 93cb721226673..bc5c5abb5386d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java @@ -116,10 +116,10 @@ public void ingestDocs(int docCount) throws Exception { @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testPrimaryStopped_ReplicaPromoted() throws Exception { - final String primary = internalCluster().startNode(featureFlagSettings()); + final String primary = internalCluster().startNode(); createIndex(INDEX_NAME); ensureYellowAndNoInitializingShards(INDEX_NAME); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); ensureGreen(INDEX_NAME); client().prepareIndex(INDEX_NAME).setId("1").setSource("foo", "bar").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); @@ -146,7 +146,7 @@ public void testPrimaryStopped_ReplicaPromoted() throws Exception { assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), 3); // start another node, index another doc and replicate. - String nodeC = internalCluster().startNode(featureFlagSettings()); + String nodeC = internalCluster().startNode(); ensureGreen(INDEX_NAME); client().prepareIndex(INDEX_NAME).setId("4").setSource("baz", "baz").get(); refresh(INDEX_NAME); @@ -158,10 +158,10 @@ public void testPrimaryStopped_ReplicaPromoted() throws Exception { @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testRestartPrimary() throws Exception { - final String primary = internalCluster().startNode(featureFlagSettings()); + final String primary = internalCluster().startNode(); createIndex(INDEX_NAME); ensureYellowAndNoInitializingShards(INDEX_NAME); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); ensureGreen(INDEX_NAME); assertEquals(getNodeContainingPrimaryShard().getName(), primary); @@ -188,10 +188,10 @@ public void testRestartPrimary() throws Exception { @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testCancelPrimaryAllocation() throws Exception { // this test cancels allocation on the primary - promoting the new replica and recreating the former primary as a replica. - final String primary = internalCluster().startNode(featureFlagSettings()); + final String primary = internalCluster().startNode(); createIndex(INDEX_NAME); ensureYellowAndNoInitializingShards(INDEX_NAME); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); ensureGreen(INDEX_NAME); final int initialDocCount = 1; @@ -228,7 +228,7 @@ public void testCancelPrimaryAllocation() throws Exception { @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testAddNewReplicaFailure() throws Exception { logger.info("--> starting [Primary Node] ..."); - final String primaryNode = internalCluster().startNode(featureFlagSettings()); + final String primaryNode = internalCluster().startNode(); logger.info("--> creating test index ..."); prepareCreate( @@ -251,7 +251,7 @@ public void testAddNewReplicaFailure() throws Exception { assertThat(client().prepareSearch(INDEX_NAME).setSize(0).execute().actionGet().getHits().getTotalHits().value, equalTo(20L)); logger.info("--> start empty node to add replica shard"); - final String replicaNode = internalCluster().startNode(featureFlagSettings()); + final String replicaNode = internalCluster().startNode(); // Mock transport service to add behaviour of throwing corruption exception during segment replication process. MockTransportService mockTransportService = ((MockTransportService) internalCluster().getInstance( @@ -294,8 +294,8 @@ public void testAddNewReplicaFailure() throws Exception { @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testReplicationAfterPrimaryRefreshAndFlush() throws Exception { - final String nodeA = internalCluster().startNode(featureFlagSettings()); - final String nodeB = internalCluster().startNode(featureFlagSettings()); + final String nodeA = internalCluster().startNode(); + final String nodeB = internalCluster().startNode(); createIndex(INDEX_NAME); ensureGreen(INDEX_NAME); @@ -335,8 +335,8 @@ public void testReplicationAfterPrimaryRefreshAndFlush() throws Exception { } public void testIndexReopenClose() throws Exception { - final String primary = internalCluster().startNode(featureFlagSettings()); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String primary = internalCluster().startNode(); + final String replica = internalCluster().startNode(); createIndex(INDEX_NAME); ensureGreen(INDEX_NAME); @@ -380,8 +380,8 @@ public void testMultipleShards() throws Exception { .put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false) .put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) .build(); - final String nodeA = internalCluster().startNode(featureFlagSettings()); - final String nodeB = internalCluster().startNode(featureFlagSettings()); + final String nodeA = internalCluster().startNode(); + final String nodeB = internalCluster().startNode(); createIndex(INDEX_NAME, indexSettings); ensureGreen(INDEX_NAME); @@ -421,8 +421,8 @@ public void testMultipleShards() throws Exception { } public void testReplicationAfterForceMerge() throws Exception { - final String nodeA = internalCluster().startNode(featureFlagSettings()); - final String nodeB = internalCluster().startNode(featureFlagSettings()); + final String nodeA = internalCluster().startNode(); + final String nodeB = internalCluster().startNode(); createIndex(INDEX_NAME); ensureGreen(INDEX_NAME); @@ -466,11 +466,11 @@ public void testReplicationAfterForceMerge() throws Exception { } public void testCancellation() throws Exception { - final String primaryNode = internalCluster().startNode(featureFlagSettings()); + final String primaryNode = internalCluster().startNode(); createIndex(INDEX_NAME, Settings.builder().put(indexSettings()).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).build()); ensureYellow(INDEX_NAME); - final String replicaNode = internalCluster().startNode(featureFlagSettings()); + final String replicaNode = internalCluster().startNode(); final SegmentReplicationSourceService segmentReplicationSourceService = internalCluster().getInstance( SegmentReplicationSourceService.class, @@ -525,7 +525,7 @@ public void testCancellation() throws Exception { } public void testStartReplicaAfterPrimaryIndexesDocs() throws Exception { - final String primaryNode = internalCluster().startNode(featureFlagSettings()); + final String primaryNode = internalCluster().startNode(); createIndex(INDEX_NAME, Settings.builder().put(indexSettings()).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()); ensureGreen(INDEX_NAME); @@ -548,7 +548,7 @@ public void testStartReplicaAfterPrimaryIndexesDocs() throws Exception { .prepareUpdateSettings(INDEX_NAME) .setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)) ); - final String replicaNode = internalCluster().startNode(featureFlagSettings()); + final String replicaNode = internalCluster().startNode(); ensureGreen(INDEX_NAME); assertHitCount(client(primaryNode).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), 2); @@ -563,8 +563,8 @@ public void testStartReplicaAfterPrimaryIndexesDocs() throws Exception { } public void testDeleteOperations() throws Exception { - final String nodeA = internalCluster().startNode(featureFlagSettings()); - final String nodeB = internalCluster().startNode(featureFlagSettings()); + final String nodeA = internalCluster().startNode(); + final String nodeB = internalCluster().startNode(); createIndex(INDEX_NAME); ensureGreen(INDEX_NAME); @@ -627,10 +627,10 @@ public void testDeleteOperations() throws Exception { @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testUpdateOperations() throws Exception { - final String primary = internalCluster().startNode(featureFlagSettings()); + final String primary = internalCluster().startNode(); createIndex(INDEX_NAME); ensureYellow(INDEX_NAME); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); final int initialDocCount = scaledRandomIntBetween(0, 200); try ( @@ -731,10 +731,10 @@ public void testDropPrimaryDuringReplication() throws Exception { .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 6) .put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) .build(); - final String clusterManagerNode = internalCluster().startClusterManagerOnlyNode(featureFlagSettings()); - final String primaryNode = internalCluster().startDataOnlyNode(featureFlagSettings()); + final String clusterManagerNode = internalCluster().startClusterManagerOnlyNode(); + final String primaryNode = internalCluster().startDataOnlyNode(); createIndex(INDEX_NAME, settings); - internalCluster().startDataOnlyNodes(6, featureFlagSettings()); + internalCluster().startDataOnlyNodes(6); ensureGreen(INDEX_NAME); int initialDocCount = scaledRandomIntBetween(100, 200); @@ -757,7 +757,7 @@ public void testDropPrimaryDuringReplication() throws Exception { ensureYellow(INDEX_NAME); // start another replica. - internalCluster().startDataOnlyNode(featureFlagSettings()); + internalCluster().startDataOnlyNode(); ensureGreen(INDEX_NAME); // index another doc and refresh - without this the new replica won't catch up. diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationRelocationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationRelocationIT.java index 19cd296e30eac..fb8b6a7150b9a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationRelocationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationRelocationIT.java @@ -57,9 +57,9 @@ private void createIndex() { */ @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testPrimaryRelocation() throws Exception { - final String oldPrimary = internalCluster().startNode(featureFlagSettings()); + final String oldPrimary = internalCluster().startNode(); createIndex(); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); ensureGreen(INDEX_NAME); final int initialDocCount = scaledRandomIntBetween(0, 200); ingestDocs(initialDocCount); @@ -69,7 +69,7 @@ public void testPrimaryRelocation() throws Exception { assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); logger.info("--> start another node"); - final String newPrimary = internalCluster().startNode(featureFlagSettings()); + final String newPrimary = internalCluster().startNode(); ClusterHealthResponse clusterHealthResponse = client().admin() .cluster() .prepareHealth() @@ -129,9 +129,9 @@ public void testPrimaryRelocation() throws Exception { */ @AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/5669") public void testPrimaryRelocationWithSegRepFailure() throws Exception { - final String oldPrimary = internalCluster().startNode(featureFlagSettings()); + final String oldPrimary = internalCluster().startNode(); createIndex(); - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); ensureGreen(INDEX_NAME); final int initialDocCount = scaledRandomIntBetween(1, 100); ingestDocs(initialDocCount); @@ -141,7 +141,7 @@ public void testPrimaryRelocationWithSegRepFailure() throws Exception { assertHitCount(client(replica).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); logger.info("--> start another node"); - final String newPrimary = internalCluster().startNode(featureFlagSettings()); + final String newPrimary = internalCluster().startNode(); ClusterHealthResponse clusterHealthResponse = client().admin() .cluster() .prepareHealth() @@ -204,7 +204,7 @@ public void testPrimaryRelocationWithSegRepFailure() throws Exception { * */ public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() throws Exception { - final String primary = internalCluster().startNode(featureFlagSettings()); + final String primary = internalCluster().startNode(); prepareCreate( INDEX_NAME, Settings.builder() @@ -233,7 +233,7 @@ public void testRelocateWhileContinuouslyIndexingAndWaitingForRefresh() throws E ); } - final String replica = internalCluster().startNode(featureFlagSettings()); + final String replica = internalCluster().startNode(); ClusterHealthResponse clusterHealthResponse = client().admin() .cluster() .prepareHealth() diff --git a/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java index 4c32929a85373..279b07344b3f9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java @@ -851,7 +851,7 @@ public void testPreferenceSearchWithWeightedRouting() throws Exception { Map> nodeMap = setupCluster(nodeCountPerAZ, commonSettings); int numShards = 10; - int numReplicas = 1; + int numReplicas = 2; setUpIndexing(numShards, numReplicas); logger.info("--> setting shard routing weights for weighted round robin"); diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java index 53b70aa915a37..e06c220e2caf9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java @@ -6,13 +6,13 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.hamcrest.MatcherAssert; -import org.junit.BeforeClass; import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; import org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder; import org.opensearch.action.index.IndexRequestBuilder; +import org.opensearch.action.support.master.AcknowledgedResponse; import org.opensearch.client.Client; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; @@ -38,24 +38,22 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.notNullValue; import static org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS; import static org.opensearch.common.util.CollectionUtils.iterableAsArrayList; public final class SearchableSnapshotIT extends AbstractSnapshotIntegTestCase { - @BeforeClass - public static void assumeFeatureFlag() { - assumeTrue( - "Searchable snapshot feature flag is enabled", - Boolean.parseBoolean(System.getProperty(FeatureFlags.SEARCHABLE_SNAPSHOT)) - ); - } - @Override protected boolean addMockInternalEngine() { return false; } + @Override + protected Settings featureFlagSettings() { + return Settings.builder().put(FeatureFlags.SEARCHABLE_SNAPSHOT, "true").build(); + } + @Override protected Settings.Builder randomRepositorySettings() { final Settings.Builder settings = Settings.builder(); @@ -214,7 +212,6 @@ public void testSearchableSnapshotIndexIsReadOnly() throws Exception { restoreSnapshotAndEnsureGreen(client, snapshotName, repoName); assertIndexingBlocked(restoredIndexName); - assertIndexSettingChangeBlocked(restoredIndexName); assertTrue(client.admin().indices().prepareDelete(restoredIndexName).get().isAcknowledged()); assertThrows( "Expect index to not exist", @@ -325,7 +322,27 @@ private void assertIndexingBlocked(String index) { } } - private void assertIndexSettingChangeBlocked(String index) { + public void testUpdateIndexSettings() throws InterruptedException { + final String indexName = "test-index"; + final String restoredIndexName = indexName + "-copy"; + final String repoName = "test-repo"; + final String snapshotName = "test-snap"; + final Client client = client(); + + createIndexWithDocsAndEnsureGreen(0, 100, indexName); + createRepositoryWithSettings(null, repoName); + takeSnapshot(client, snapshotName, repoName, indexName); + deleteIndicesAndEnsureGreen(client, indexName); + + internalCluster().ensureAtLeastNumSearchNodes(1); + restoreSnapshotAndEnsureGreen(client, snapshotName, repoName); + + testUpdateIndexSettingsOnlyNotAllowedSettings(restoredIndexName); + testUpdateIndexSettingsOnlyAllowedSettings(restoredIndexName); + testUpdateIndexSettingsAtLeastOneNotAllowedSettings(restoredIndexName); + } + + private void testUpdateIndexSettingsOnlyNotAllowedSettings(String index) { try { final UpdateSettingsRequestBuilder builder = client().admin().indices().prepareUpdateSettings(index); builder.setSettings(Map.of("index.refresh_interval", 10)); @@ -336,6 +353,26 @@ private void assertIndexSettingChangeBlocked(String index) { } } + private void testUpdateIndexSettingsOnlyAllowedSettings(String index) { + final UpdateSettingsRequestBuilder builder = client().admin().indices().prepareUpdateSettings(index); + builder.setSettings(Map.of("index.max_result_window", 1000, "index.search.slowlog.threshold.query.warn", "10s")); + AcknowledgedResponse settingsResponse = builder.execute().actionGet(); + assertThat(settingsResponse, notNullValue()); + } + + private void testUpdateIndexSettingsAtLeastOneNotAllowedSettings(String index) { + try { + final UpdateSettingsRequestBuilder builder = client().admin().indices().prepareUpdateSettings(index); + builder.setSettings( + Map.of("index.max_result_window", 5000, "index.search.slowlog.threshold.query.warn", "15s", "index.refresh_interval", 10) + ); + builder.execute().actionGet(); + fail("Expected operation to throw an exception"); + } catch (ClusterBlockException e) { + MatcherAssert.assertThat(e.blocks(), contains(IndexMetadata.REMOTE_READ_ONLY_ALLOW_DELETE)); + } + } + /** * Picks a shard out of the cluster state for each given index and asserts * that the 'index' directory does not exist in the node's file system. diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SegmentReplicationSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SegmentReplicationSnapshotIT.java index a741797012602..2b44a20406b05 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SegmentReplicationSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SegmentReplicationSnapshotIT.java @@ -99,11 +99,11 @@ public void ingestData(int docCount, String indexName) throws Exception { // Start cluster with provided settings and return the node names as list public List startClusterWithSettings(Settings indexSettings, int replicaCount) throws Exception { // Start primary - final String primaryNode = internalCluster().startNode(featureFlagSettings()); + final String primaryNode = internalCluster().startNode(); List nodeNames = new ArrayList<>(); nodeNames.add(primaryNode); for (int i = 0; i < replicaCount; i++) { - nodeNames.add(internalCluster().startNode(featureFlagSettings())); + nodeNames.add(internalCluster().startNode()); } createIndex(INDEX_NAME, indexSettings); ensureGreen(INDEX_NAME); @@ -266,7 +266,7 @@ public void testRestoreOnReplicaNode() throws Exception { // Assertions assertThat(restoreSnapshotResponse.status(), equalTo(RestStatus.ACCEPTED)); - internalCluster().startNode(featureFlagSettings()); + internalCluster().startNode(); ensureGreen(RESTORED_INDEX_NAME); GetSettingsResponse settingsResponse = client().admin() .indices() diff --git a/server/src/main/java/org/opensearch/Version.java b/server/src/main/java/org/opensearch/Version.java index 77286c42dc4c2..0ddfd8c21b085 100644 --- a/server/src/main/java/org/opensearch/Version.java +++ b/server/src/main/java/org/opensearch/Version.java @@ -85,6 +85,7 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_2_4_0 = new Version(2040099, org.apache.lucene.util.Version.LUCENE_9_4_1); public static final Version V_2_4_1 = new Version(2040199, org.apache.lucene.util.Version.LUCENE_9_4_2); public static final Version V_2_5_0 = new Version(2050099, org.apache.lucene.util.Version.LUCENE_9_4_2); + public static final Version V_2_5_1 = new Version(2050199, org.apache.lucene.util.Version.LUCENE_9_4_2); // UNRELEASED public static final Version V_2_4_2 = new Version(2040299, org.apache.lucene.util.Version.LUCENE_9_4_2); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java index a959fb043e4c6..a1c3b9341fd40 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java @@ -49,11 +49,17 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.util.FeatureFlags; import org.opensearch.index.Index; +import org.opensearch.index.IndexModule; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; import java.io.IOException; +import java.util.stream.Stream; +import java.util.Set; + +import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING; /** * Transport action for updating index settings @@ -64,6 +70,19 @@ public class TransportUpdateSettingsAction extends TransportClusterManagerNodeAc private static final Logger logger = LogManager.getLogger(TransportUpdateSettingsAction.class); + private final static Set ALLOWLIST_REMOTE_SNAPSHOT_SETTINGS = Set.of( + "index.max_result_window", + "index.max_inner_result_window", + "index.max_rescore_window", + "index.max_docvalue_fields_search", + "index.max_script_fields", + "index.max_terms_count", + "index.max_regex_length", + "index.highlight.max_analyzed_offset" + ); + + private final static String[] ALLOWLIST_REMOTE_SNAPSHOT_SETTINGS_PREFIXES = { "index.search.slowlog" }; + private final MetadataUpdateSettingsService updateSettingsService; @Inject @@ -106,6 +125,37 @@ protected ClusterBlockException checkBlock(UpdateSettingsRequest request, Cluste || IndexMetadata.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.settings())) { return null; } + + if (FeatureFlags.isEnabled(FeatureFlags.SEARCHABLE_SNAPSHOT)) { + final Index[] requestIndices = indexNameExpressionResolver.concreteIndices(state, request); + boolean allowSearchableSnapshotSettingsUpdate = true; + // check if all indices in the request are remote snapshot + for (Index index : requestIndices) { + if (state.blocks().indexBlocked(ClusterBlockLevel.METADATA_WRITE, index.getName())) { + allowSearchableSnapshotSettingsUpdate = allowSearchableSnapshotSettingsUpdate + && IndexModule.Type.REMOTE_SNAPSHOT.match( + state.getMetadata().getIndexSafe(index).getSettings().get(INDEX_STORE_TYPE_SETTING.getKey()) + ); + } + } + // check if all settings in the request are in the allow list + if (allowSearchableSnapshotSettingsUpdate) { + for (String setting : request.settings().keySet()) { + allowSearchableSnapshotSettingsUpdate = allowSearchableSnapshotSettingsUpdate + && (ALLOWLIST_REMOTE_SNAPSHOT_SETTINGS.contains(setting) + || Stream.of(ALLOWLIST_REMOTE_SNAPSHOT_SETTINGS_PREFIXES).anyMatch(setting::startsWith)); + } + } + + return allowSearchableSnapshotSettingsUpdate + ? null + : state.blocks() + .indicesBlockedException( + ClusterBlockLevel.METADATA_WRITE, + indexNameExpressionResolver.concreteIndexNames(state, request) + ); + } + return state.blocks() .indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request)); } diff --git a/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java b/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java index 1a37406e19f14..6b6678361b2b5 100644 --- a/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java +++ b/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java @@ -34,7 +34,6 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.lucene.util.SetOnce; import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.Version; @@ -46,6 +45,7 @@ import org.opensearch.cluster.routing.FailAwareWeightedRouting; import org.opensearch.cluster.routing.GroupShardsIterator; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.lease.Releasable; import org.opensearch.common.lease.Releasables; import org.opensearch.common.util.concurrent.AbstractRunnable; diff --git a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java index fd52f48c7b5f8..eb069dc1f7698 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java @@ -35,7 +35,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.cluster.ClusterChangedEvent; import org.opensearch.cluster.ClusterName; @@ -61,6 +60,7 @@ import org.opensearch.common.Booleans; import org.opensearch.common.Nullable; import org.opensearch.common.Priority; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.component.AbstractLifecycleComponent; import org.opensearch.common.io.stream.NamedWriteableRegistry; diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstraction.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstraction.java index 975c71ab75110..f9328d5b61183 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstraction.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexAbstraction.java @@ -31,8 +31,8 @@ package org.opensearch.cluster.metadata; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.collect.Tuple; diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java index 0a6cfd8c04977..4eb39caa2fdcf 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitor.java @@ -45,6 +45,7 @@ import org.opensearch.cluster.DiskUsage; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.metadata.IndexMetadata; +import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.routing.RerouteService; import org.opensearch.cluster.routing.RoutingNode; import org.opensearch.cluster.routing.RoutingNodes; @@ -78,7 +79,6 @@ public class DiskThresholdMonitor { private static final Logger logger = LogManager.getLogger(DiskThresholdMonitor.class); - private final DiskThresholdSettings diskThresholdSettings; private final Client client; private final Supplier clusterStateSupplier; @@ -286,7 +286,7 @@ public void onNewInfo(ClusterInfo info) { } } - final ActionListener listener = new GroupedActionListener<>(ActionListener.wrap(this::checkFinished), 3); + final ActionListener listener = new GroupedActionListener<>(ActionListener.wrap(this::checkFinished), 4); if (reroute) { logger.debug("rerouting shards: [{}]", explanation); @@ -373,6 +373,15 @@ public void onNewInfo(ClusterInfo info) { } else { listener.onResponse(null); } + + // If all the nodes are breaching high disk watermark, we apply index create block to avoid red clusters. + if (nodesOverHighThreshold.size() == nodes.size()) { + setIndexCreateBlock(listener, true); + } else if (state.getBlocks().hasGlobalBlockWithId(Metadata.CLUSTER_CREATE_INDEX_BLOCK.id())) { + setIndexCreateBlock(listener, false); + } else { + listener.onResponse(null); + } } // exposed for tests to override @@ -406,6 +415,27 @@ private void setLastRunTimeMillis() { lastRunTimeMillis.getAndUpdate(l -> Math.max(l, currentTimeMillisSupplier.getAsLong())); } + protected void setIndexCreateBlock(final ActionListener listener, boolean indexCreateBlock) { + final ActionListener wrappedListener = ActionListener.wrap(r -> { + setLastRunTimeMillis(); + listener.onResponse(r); + }, e -> { + logger.debug("setting index create block failed", e); + setLastRunTimeMillis(); + listener.onFailure(e); + }); + + final Settings indexCreateBlockSetting = indexCreateBlock + ? Settings.builder().put(Metadata.SETTING_CREATE_INDEX_BLOCK_SETTING.getKey(), Boolean.TRUE.toString()).build() + : Settings.builder().putNull(Metadata.SETTING_CREATE_INDEX_BLOCK_SETTING.getKey()).build(); + + client.admin() + .cluster() + .prepareUpdateSettings() + .setPersistentSettings(indexCreateBlockSetting) + .execute(ActionListener.map(wrappedListener, r -> null)); + } + protected void updateIndicesReadOnly(Set indicesToUpdate, ActionListener listener, boolean readOnly) { // set read-only block but don't block on the response ActionListener wrappedListener = ActionListener.wrap(r -> { diff --git a/server/src/main/java/org/opensearch/common/logging/NodeAndClusterIdConverter.java b/server/src/main/java/org/opensearch/common/logging/NodeAndClusterIdConverter.java index a3062bca90158..7bbb83e311adc 100644 --- a/server/src/main/java/org/opensearch/common/logging/NodeAndClusterIdConverter.java +++ b/server/src/main/java/org/opensearch/common/logging/NodeAndClusterIdConverter.java @@ -37,7 +37,7 @@ import org.apache.logging.log4j.core.pattern.ConverterKeys; import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; import org.apache.logging.log4j.core.pattern.PatternConverter; -import org.apache.lucene.util.SetOnce; +import org.opensearch.common.SetOnce; import java.util.Locale; diff --git a/server/src/main/java/org/opensearch/common/logging/NodeNamePatternConverter.java b/server/src/main/java/org/opensearch/common/logging/NodeNamePatternConverter.java index bc25f690d4a64..b0ecbb6f9407f 100644 --- a/server/src/main/java/org/opensearch/common/logging/NodeNamePatternConverter.java +++ b/server/src/main/java/org/opensearch/common/logging/NodeNamePatternConverter.java @@ -39,7 +39,7 @@ import org.apache.logging.log4j.core.pattern.ConverterKeys; import org.apache.logging.log4j.core.pattern.LogEventPatternConverter; import org.apache.logging.log4j.core.pattern.PatternConverter; -import org.apache.lucene.util.SetOnce; +import org.opensearch.common.SetOnce; /** * Converts {@code %node_name} in log4j patterns into the current node name. diff --git a/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java b/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java index 508e1bc38ea8a..ffd980f8f0da6 100644 --- a/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java +++ b/server/src/main/java/org/opensearch/common/settings/KeyStoreWrapper.java @@ -40,10 +40,10 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.NIOFSDirectory; -import org.apache.lucene.util.SetOnce; import org.opensearch.cli.ExitCodes; import org.opensearch.cli.UserException; import org.opensearch.common.Randomness; +import org.opensearch.common.SetOnce; import org.opensearch.common.hash.MessageDigests; import javax.crypto.AEADBadTagException; diff --git a/server/src/main/java/org/opensearch/common/settings/Settings.java b/server/src/main/java/org/opensearch/common/settings/Settings.java index 5e15e1693c017..d5ec0e514ac67 100644 --- a/server/src/main/java/org/opensearch/common/settings/Settings.java +++ b/server/src/main/java/org/opensearch/common/settings/Settings.java @@ -33,11 +33,11 @@ package org.opensearch.common.settings; import org.apache.logging.log4j.Level; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchGenerationException; import org.opensearch.OpenSearchParseException; import org.opensearch.Version; import org.opensearch.common.Booleans; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/main/java/org/opensearch/common/util/CancellableThreads.java b/server/src/main/java/org/opensearch/common/util/CancellableThreads.java index bb9ae9502f746..ad7ceff90c55d 100644 --- a/server/src/main/java/org/opensearch/common/util/CancellableThreads.java +++ b/server/src/main/java/org/opensearch/common/util/CancellableThreads.java @@ -31,10 +31,10 @@ package org.opensearch.common.util; -import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.ThreadInterruptedException; import org.opensearch.OpenSearchException; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.StreamInput; import java.io.IOException; diff --git a/server/src/main/java/org/opensearch/discovery/PeerFinder.java b/server/src/main/java/org/opensearch/discovery/PeerFinder.java index e8b6c72c512a2..467ed7ed80ea7 100644 --- a/server/src/main/java/org/opensearch/discovery/PeerFinder.java +++ b/server/src/main/java/org/opensearch/discovery/PeerFinder.java @@ -36,12 +36,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.cluster.coordination.PeersResponse; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; diff --git a/server/src/main/java/org/opensearch/discovery/SeedHostsResolver.java b/server/src/main/java/org/opensearch/discovery/SeedHostsResolver.java index 94e51fe5804ca..14805648c6771 100644 --- a/server/src/main/java/org/opensearch/discovery/SeedHostsResolver.java +++ b/server/src/main/java/org/opensearch/discovery/SeedHostsResolver.java @@ -34,7 +34,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; +import org.opensearch.common.SetOnce; import org.opensearch.common.component.AbstractLifecycleComponent; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java index 885e4b0e35ee6..ca65215599891 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsManager.java @@ -20,7 +20,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; @@ -198,7 +200,7 @@ public void initializeServicesAndRestHandler( * * @param request which was sent by an extension. */ - public ExtensionActionResponse handleTransportRequest(ExtensionActionRequest request) throws InterruptedException { + public ExtensionActionResponse handleTransportRequest(ExtensionActionRequest request) throws Exception { return extensionTransportActionsHandler.sendTransportRequestToExtension(request); } @@ -401,13 +403,17 @@ public String executor() { new InitializeExtensionRequest(transportService.getLocalNode(), extension), initializeExtensionResponseHandler ); - // TODO: make asynchronous - inProgressFuture.get(EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS); - } catch (Exception e) { - try { - throw e; - } catch (Exception e1) { - logger.error(e.toString()); + inProgressFuture.orTimeout(EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS).join(); + } catch (CompletionException e) { + if (e.getCause() instanceof TimeoutException) { + logger.info("No response from extension to request."); + } + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); + } else { + throw new RuntimeException(e.getCause()); } } } @@ -462,7 +468,7 @@ public void handleResponse(AcknowledgedResponse response) { @Override public void handleException(TransportException exp) { - + inProgressIndexNameFuture.completeExceptionally(exp); } @Override @@ -506,20 +512,21 @@ public void beforeIndexRemoved( new IndicesModuleRequest(indexModule), acknowledgedResponseHandler ); - // TODO: make asynchronous - inProgressIndexNameFuture.get(EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS); - logger.info("Received ack response from Extension"); - } catch (Exception e) { - try { - throw e; - } catch (Exception e1) { - logger.error(e.toString()); - } + inProgressIndexNameFuture.whenComplete((r, e) -> { + if (e != null) { + inProgressFuture.complete(response); + } else if (e == null) { + inProgressFuture.completeExceptionally(e); + } + }); + } catch (Exception ex) { + inProgressFuture.completeExceptionally(ex); } } }); + } else { + inProgressFuture.complete(response); } - inProgressFuture.complete(response); } @Override @@ -542,14 +549,18 @@ public String executor() { new IndicesModuleRequest(indexModule), indicesModuleResponseHandler ); - // TODO: make asynchronous - inProgressFuture.get(EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS); + inProgressFuture.orTimeout(EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS).join(); logger.info("Received response from Extension"); - } catch (Exception e) { - try { - throw e; - } catch (Exception e1) { - logger.error(e.toString()); + } catch (CompletionException e) { + if (e.getCause() instanceof TimeoutException) { + logger.info("No response from extension to request."); + } + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); + } else { + throw new RuntimeException(e.getCause()); } } } diff --git a/server/src/main/java/org/opensearch/extensions/action/ExtensionTransportActionsHandler.java b/server/src/main/java/org/opensearch/extensions/action/ExtensionTransportActionsHandler.java index ac3ec6630634a..f76fe794b2f84 100644 --- a/server/src/main/java/org/opensearch/extensions/action/ExtensionTransportActionsHandler.java +++ b/server/src/main/java/org/opensearch/extensions/action/ExtensionTransportActionsHandler.java @@ -28,8 +28,10 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; /** * This class manages TransportActions for extensions @@ -108,10 +110,9 @@ public TransportResponse handleRegisterTransportActionsRequest(RegisterTransport * @return {@link TransportResponse} which is sent back to the transport action invoker. * @throws InterruptedException when message transport fails. */ - public TransportResponse handleTransportActionRequestFromExtension(TransportActionRequestFromExtension request) - throws InterruptedException { + public TransportResponse handleTransportActionRequestFromExtension(TransportActionRequestFromExtension request) throws Exception { DiscoveryExtensionNode extension = extensionIdMap.get(request.getUniqueId()); - final CountDownLatch inProgressLatch = new CountDownLatch(1); + final CompletableFuture inProgressFuture = new CompletableFuture<>(); final TransportActionResponseToExtension response = new TransportActionResponseToExtension(new byte[0]); client.execute( ExtensionProxyAction.INSTANCE, @@ -120,7 +121,7 @@ public TransportResponse handleTransportActionRequestFromExtension(TransportActi @Override public void onResponse(ExtensionActionResponse actionResponse) { response.setResponseBytes(actionResponse.getResponseBytes()); - inProgressLatch.countDown(); + inProgressFuture.complete(actionResponse); } @Override @@ -128,11 +129,24 @@ public void onFailure(Exception exp) { logger.debug("Transport request failed", exp); byte[] responseBytes = ("Request failed: " + exp.getMessage()).getBytes(StandardCharsets.UTF_8); response.setResponseBytes(responseBytes); - inProgressLatch.countDown(); + inProgressFuture.completeExceptionally(exp); } } ); - inProgressLatch.await(ExtensionsManager.EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS); + try { + inProgressFuture.orTimeout(ExtensionsManager.EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS).join(); + } catch (CompletionException e) { + if (e.getCause() instanceof TimeoutException) { + logger.info("No response from extension to request."); + } + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); + } else { + throw new RuntimeException(e.getCause()); + } + } return response; } @@ -143,12 +157,12 @@ public void onFailure(Exception exp) { * @return {@link ExtensionActionResponse} which encapsulates the transport response from the extension. * @throws InterruptedException when message transport fails. */ - public ExtensionActionResponse sendTransportRequestToExtension(ExtensionActionRequest request) throws InterruptedException { + public ExtensionActionResponse sendTransportRequestToExtension(ExtensionActionRequest request) throws Exception { DiscoveryExtensionNode extension = actionsMap.get(request.getAction()); if (extension == null) { throw new ActionNotFoundTransportException(request.getAction()); } - final CountDownLatch inProgressLatch = new CountDownLatch(1); + final CompletableFuture inProgressFuture = new CompletableFuture<>(); final ExtensionActionResponse extensionActionResponse = new ExtensionActionResponse(new byte[0]); final TransportResponseHandler extensionActionResponseTransportResponseHandler = new TransportResponseHandler() { @@ -161,7 +175,7 @@ public ExtensionActionResponse read(StreamInput in) throws IOException { @Override public void handleResponse(ExtensionActionResponse response) { extensionActionResponse.setResponseBytes(response.getResponseBytes()); - inProgressLatch.countDown(); + inProgressFuture.complete(response); } @Override @@ -169,7 +183,7 @@ public void handleException(TransportException exp) { logger.debug("Transport request failed", exp); byte[] responseBytes = ("Request failed: " + exp.getMessage()).getBytes(StandardCharsets.UTF_8); extensionActionResponse.setResponseBytes(responseBytes); - inProgressLatch.countDown(); + inProgressFuture.completeExceptionally(exp); } @Override @@ -187,7 +201,20 @@ public String executor() { } catch (Exception e) { logger.info("Failed to send transport action to extension " + extension.getName(), e); } - inProgressLatch.await(ExtensionsManager.EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS); + try { + inProgressFuture.orTimeout(ExtensionsManager.EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS).join(); + } catch (CompletionException e) { + if (e.getCause() instanceof TimeoutException) { + logger.info("No response from extension to request."); + } + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); + } else { + throw new RuntimeException(e.getCause()); + } + } return extensionActionResponse; } } diff --git a/server/src/main/java/org/opensearch/extensions/rest/RestSendToExtensionAction.java b/server/src/main/java/org/opensearch/extensions/rest/RestSendToExtensionAction.java index 38e92ed604a09..357be3a9fc2fe 100644 --- a/server/src/main/java/org/opensearch/extensions/rest/RestSendToExtensionAction.java +++ b/server/src/main/java/org/opensearch/extensions/rest/RestSendToExtensionAction.java @@ -32,8 +32,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableList; @@ -122,7 +125,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC emptyList(), false ); - final CountDownLatch inProgressLatch = new CountDownLatch(1); + final CompletableFuture inProgressFuture = new CompletableFuture<>(); final TransportResponseHandler restExecuteOnExtensionResponseHandler = new TransportResponseHandler< RestExecuteOnExtensionResponse>() { @@ -143,15 +146,13 @@ public void handleResponse(RestExecuteOnExtensionResponse response) { if (response.isContentConsumed()) { request.content(); } + inProgressFuture.complete(response); } @Override public void handleException(TransportException exp) { logger.debug("REST request failed", exp); - // Status is already defaulted to 500 (INTERNAL_SERVER_ERROR) - byte[] responseBytes = ("Request failed: " + exp.getMessage()).getBytes(StandardCharsets.UTF_8); - restExecuteOnExtensionResponse.setContent(responseBytes); - inProgressLatch.countDown(); + inProgressFuture.completeExceptionally(exp); } @Override @@ -172,15 +173,24 @@ public String executor() { new ExtensionRestRequest(method, path, params, contentType, content, requestIssuerIdentity), restExecuteOnExtensionResponseHandler ); - try { - inProgressLatch.await(5, TimeUnit.SECONDS); - } catch (InterruptedException e) { + inProgressFuture.orTimeout(ExtensionsManager.EXTENSION_REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS).join(); + } catch (CompletionException e) { + Throwable cause = e.getCause(); + if (cause instanceof TimeoutException) { return channel -> channel.sendResponse( new BytesRestResponse(RestStatus.REQUEST_TIMEOUT, "No response from extension to request.") ); } - } catch (Exception e) { - logger.info("Failed to send REST Actions to extension " + discoveryExtensionNode.getName(), e); + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); + } else { + throw new RuntimeException(e.getCause()); + } + } catch (Exception ex) { + logger.info("Failed to send REST Actions to extension " + discoveryExtensionNode.getName(), ex); + return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, ex.getMessage())); } BytesRestResponse restResponse = new BytesRestResponse( restExecuteOnExtensionResponse.getStatus(), diff --git a/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java b/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java index 48dd0ddf90413..ea550fc6ac3e8 100644 --- a/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java +++ b/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java @@ -36,7 +36,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.store.AlreadyClosedException; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchException; import org.opensearch.ExceptionsHelper; import org.opensearch.Version; @@ -54,6 +53,7 @@ import org.opensearch.cluster.metadata.MetadataIndexUpgradeService; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; diff --git a/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java b/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java index ea77e4ae5f13b..30af9aaa91765 100644 --- a/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java +++ b/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java @@ -60,13 +60,13 @@ import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefIterator; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.bytes.RecyclingBytesStreamOutput; import org.opensearch.common.io.Streams; diff --git a/server/src/main/java/org/opensearch/index/IndexModule.java b/server/src/main/java/org/opensearch/index/IndexModule.java index 5b9b051af8e8b..f2675f018d0e6 100644 --- a/server/src/main/java/org/opensearch/index/IndexModule.java +++ b/server/src/main/java/org/opensearch/index/IndexModule.java @@ -40,13 +40,13 @@ import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.store.MMapDirectory; import org.apache.lucene.util.Constants; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.CheckedFunction; +import org.opensearch.common.SetOnce; import org.opensearch.common.TriFunction; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.logging.DeprecationLogger; diff --git a/server/src/main/java/org/opensearch/index/engine/Engine.java b/server/src/main/java/org/opensearch/index/engine/Engine.java index 95d671ee7adc2..604fa7a53e65c 100644 --- a/server/src/main/java/org/opensearch/index/engine/Engine.java +++ b/server/src/main/java/org/opensearch/index/engine/Engine.java @@ -51,10 +51,10 @@ import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; -import org.apache.lucene.util.SetOnce; import org.opensearch.ExceptionsHelper; import org.opensearch.action.index.IndexRequest; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.concurrent.GatedCloseable; diff --git a/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java index 4f0a873ac7bdb..dfffafa7cf114 100644 --- a/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/AbstractGeometryQueryBuilder.java @@ -34,7 +34,6 @@ import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.get.GetRequest; @@ -42,6 +41,7 @@ import org.opensearch.client.Client; import org.opensearch.common.ParseField; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.geo.GeoJson; import org.opensearch.common.geo.GeometryIO; import org.opensearch.common.geo.GeometryParser; diff --git a/server/src/main/java/org/opensearch/index/query/QueryShardContext.java b/server/src/main/java/org/opensearch/index/query/QueryShardContext.java index fe2ed23b2b279..9338b28e5f68d 100644 --- a/server/src/main/java/org/opensearch/index/query/QueryShardContext.java +++ b/server/src/main/java/org/opensearch/index/query/QueryShardContext.java @@ -38,12 +38,12 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.join.BitSetProducer; import org.apache.lucene.search.similarities.Similarity; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.client.Client; import org.opensearch.common.CheckedFunction; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.TriFunction; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.lucene.search.Queries; diff --git a/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java index 28f98f7060395..a1529889e0d05 100644 --- a/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java @@ -37,11 +37,11 @@ import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.action.get.GetRequest; import org.opensearch.client.Client; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; diff --git a/server/src/main/java/org/opensearch/index/shard/IndexShard.java b/server/src/main/java/org/opensearch/index/shard/IndexShard.java index 26abe80d2bff2..96a54ab65d268 100644 --- a/server/src/main/java/org/opensearch/index/shard/IndexShard.java +++ b/server/src/main/java/org/opensearch/index/shard/IndexShard.java @@ -55,7 +55,6 @@ import org.apache.lucene.store.FilterDirectory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; -import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.ThreadInterruptedException; import org.opensearch.Assertions; import org.opensearch.ExceptionsHelper; @@ -80,6 +79,7 @@ import org.opensearch.common.CheckedFunction; import org.opensearch.common.CheckedRunnable; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.collect.Tuple; import org.opensearch.common.concurrent.GatedCloseable; import org.opensearch.common.io.stream.BytesStreamOutput; diff --git a/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferMetadata.java b/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferMetadata.java index 243294d85c97d..3b2884dca9a3f 100644 --- a/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferMetadata.java +++ b/server/src/main/java/org/opensearch/index/translog/transfer/TranslogTransferMetadata.java @@ -12,7 +12,7 @@ import org.apache.lucene.store.DataOutput; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.OutputStreamIndexOutput; -import org.apache.lucene.util.SetOnce; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; diff --git a/server/src/main/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandler.java b/server/src/main/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandler.java index 4bb6fc1d23b9f..c8d3b2d09ad28 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandler.java +++ b/server/src/main/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandler.java @@ -9,13 +9,13 @@ package org.opensearch.indices.recovery; import org.apache.lucene.index.IndexCommit; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; import org.opensearch.action.support.ThreadedActionListener; import org.opensearch.action.support.replication.ReplicationResponse; import org.opensearch.cluster.routing.IndexShardRoutingTable; import org.opensearch.cluster.routing.ShardRouting; +import org.opensearch.common.SetOnce; import org.opensearch.common.concurrent.GatedCloseable; import org.opensearch.common.lease.Releasable; import org.opensearch.common.unit.TimeValue; diff --git a/server/src/main/java/org/opensearch/node/Node.java b/server/src/main/java/org/opensearch/node/Node.java index ab39a7bf71ff6..662a44a81ef85 100644 --- a/server/src/main/java/org/opensearch/node/Node.java +++ b/server/src/main/java/org/opensearch/node/Node.java @@ -35,7 +35,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.Constants; -import org.apache.lucene.util.SetOnce; +import org.opensearch.common.SetOnce; import org.opensearch.common.util.FeatureFlags; import org.opensearch.cluster.routing.allocation.AwarenessReplicaBalance; import org.opensearch.index.IndexModule; diff --git a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java index d2a70e88d6eee..9113c5531b1e3 100644 --- a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java @@ -45,7 +45,6 @@ import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.RateLimiter; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.SetOnce; import org.opensearch.ExceptionsHelper; import org.opensearch.Version; import org.opensearch.action.ActionListener; @@ -67,6 +66,7 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Nullable; import org.opensearch.common.Numbers; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; import org.opensearch.common.blobstore.BlobContainer; diff --git a/server/src/main/java/org/opensearch/rest/RestRequest.java b/server/src/main/java/org/opensearch/rest/RestRequest.java index d44a4e3039543..1e0a2b1827e10 100644 --- a/server/src/main/java/org/opensearch/rest/RestRequest.java +++ b/server/src/main/java/org/opensearch/rest/RestRequest.java @@ -32,11 +32,11 @@ package org.opensearch.rest; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchParseException; import org.opensearch.common.Booleans; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; diff --git a/server/src/main/java/org/opensearch/search/aggregations/Aggregations.java b/server/src/main/java/org/opensearch/search/aggregations/Aggregations.java index 4049d96d68817..b59eaa46f0bd1 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/Aggregations.java +++ b/server/src/main/java/org/opensearch/search/aggregations/Aggregations.java @@ -31,8 +31,8 @@ package org.opensearch.search.aggregations; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; diff --git a/server/src/main/java/org/opensearch/search/internal/PitReaderContext.java b/server/src/main/java/org/opensearch/search/internal/PitReaderContext.java index b24a8a4172e29..5c2a9f82f98e4 100644 --- a/server/src/main/java/org/opensearch/search/internal/PitReaderContext.java +++ b/server/src/main/java/org/opensearch/search/internal/PitReaderContext.java @@ -8,8 +8,8 @@ package org.opensearch.search.internal; -import org.apache.lucene.util.SetOnce; import org.opensearch.cluster.routing.ShardRouting; +import org.opensearch.common.SetOnce; import org.opensearch.common.lease.Releasable; import org.opensearch.common.lease.Releasables; import org.opensearch.index.IndexService; diff --git a/server/src/main/java/org/opensearch/search/suggest/Suggest.java b/server/src/main/java/org/opensearch/search/suggest/Suggest.java index 0aa881e2a3c9e..7943892b2af89 100644 --- a/server/src/main/java/org/opensearch/search/suggest/Suggest.java +++ b/server/src/main/java/org/opensearch/search/suggest/Suggest.java @@ -32,10 +32,10 @@ package org.opensearch.search.suggest; import org.apache.lucene.util.CollectionUtil; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.CheckedFunction; import org.opensearch.common.ParseField; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.io.stream.NamedWriteable; import org.opensearch.common.io.stream.StreamInput; diff --git a/server/src/main/java/org/opensearch/tasks/TaskManager.java b/server/src/main/java/org/opensearch/tasks/TaskManager.java index 334cde81dfb6a..ff760219716e6 100644 --- a/server/src/main/java/org/opensearch/tasks/TaskManager.java +++ b/server/src/main/java/org/opensearch/tasks/TaskManager.java @@ -37,7 +37,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.lucene.util.SetOnce; import org.opensearch.Assertions; import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; @@ -49,6 +48,7 @@ import org.opensearch.cluster.ClusterStateApplier; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; +import org.opensearch.common.SetOnce; import org.opensearch.common.lease.Releasable; import org.opensearch.common.lease.Releasables; import org.opensearch.common.settings.ClusterSettings; diff --git a/server/src/main/java/org/opensearch/transport/SniffConnectionStrategy.java b/server/src/main/java/org/opensearch/transport/SniffConnectionStrategy.java index 47fd5fc2c9489..d465f05cd6a6f 100644 --- a/server/src/main/java/org/opensearch/transport/SniffConnectionStrategy.java +++ b/server/src/main/java/org/opensearch/transport/SniffConnectionStrategy.java @@ -33,7 +33,6 @@ package org.opensearch.transport; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; @@ -44,6 +43,7 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodeRole; import org.opensearch.common.Booleans; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; import org.opensearch.common.io.stream.StreamInput; diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java index 69570fa7b4640..03c6b5ab822c1 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.cluster.configuration; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.Version; import org.opensearch.action.support.ActionFilters; @@ -49,6 +48,7 @@ import org.opensearch.cluster.node.DiscoveryNodeRole; import org.opensearch.cluster.node.DiscoveryNodes.Builder; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.ClusterSettings; diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java index b3620bf757256..37ead5d588f84 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.cluster.configuration; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.Version; import org.opensearch.action.support.ActionFilters; @@ -45,6 +44,7 @@ import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.node.DiscoveryNodes.Builder; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java index 8b0c2187d05af..4eba00e95b77c 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/TaskManagerTestCase.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.cluster.node.tasks; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.FailedNodeException; import org.opensearch.action.admin.cluster.node.tasks.cancel.TransportCancelTasksAction; @@ -46,6 +45,7 @@ import org.opensearch.cluster.ClusterName; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/test/java/org/opensearch/action/admin/indices/close/TransportVerifyShardBeforeCloseActionTests.java b/server/src/test/java/org/opensearch/action/admin/indices/close/TransportVerifyShardBeforeCloseActionTests.java index 000dac92506f6..f617585894766 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/close/TransportVerifyShardBeforeCloseActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/close/TransportVerifyShardBeforeCloseActionTests.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.indices.close; -import org.apache.lucene.util.SetOnce; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -59,6 +58,7 @@ import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.index.shard.IndexShard; diff --git a/server/src/test/java/org/opensearch/action/search/TransportSearchActionTests.java b/server/src/test/java/org/opensearch/action/search/TransportSearchActionTests.java index d1f2304365d59..136e1879881f8 100644 --- a/server/src/test/java/org/opensearch/action/search/TransportSearchActionTests.java +++ b/server/src/test/java/org/opensearch/action/search/TransportSearchActionTests.java @@ -33,7 +33,6 @@ package org.opensearch.action.search; import org.apache.lucene.search.TotalHits; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.LatchedActionListener; @@ -52,6 +51,7 @@ import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.routing.TestShardRouting; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java b/server/src/test/java/org/opensearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java index 98972d4063a97..013be1f2ebd42 100644 --- a/server/src/test/java/org/opensearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java +++ b/server/src/test/java/org/opensearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java @@ -31,7 +31,6 @@ package org.opensearch.action.support.replication; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; @@ -54,6 +53,7 @@ import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.lease.Releasable; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/cluster/action/shard/ShardStateActionTests.java b/server/src/test/java/org/opensearch/cluster/action/shard/ShardStateActionTests.java index 2138f28f7b8c2..95ef12f0224fd 100644 --- a/server/src/test/java/org/opensearch/cluster/action/shard/ShardStateActionTests.java +++ b/server/src/test/java/org/opensearch/cluster/action/shard/ShardStateActionTests.java @@ -33,7 +33,6 @@ package org.opensearch.cluster.action.shard; import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.support.replication.ClusterStateCreationUtils; @@ -51,6 +50,7 @@ import org.opensearch.cluster.routing.ShardsIterator; import org.opensearch.cluster.routing.allocation.AllocationService; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java index 9f3f603e8edf3..4c4b362ef7c56 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/DiskThresholdMonitorTests.java @@ -129,6 +129,11 @@ protected void updateIndicesReadOnly(Set indicesToMarkReadOnly, ActionLi assertTrue(readOnly); listener.onResponse(null); } + + @Override + protected void setIndexCreateBlock(ActionListener listener, boolean indexCreateBlock) { + listener.onResponse(null); + } }; ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(); @@ -185,6 +190,11 @@ protected void updateIndicesReadOnly(Set indicesToMarkReadOnly, ActionLi assertTrue(readOnly); listener.onResponse(null); } + + @Override + protected void setIndexCreateBlock(ActionListener listener, boolean indexCreateBlock) { + listener.onResponse(null); + } }; indices.set(null); @@ -372,6 +382,12 @@ protected void updateIndicesReadOnly(Set indicesToUpdate, ActionListener } listener.onResponse(null); } + + @Override + protected void setIndexCreateBlock(ActionListener listener, boolean indexCreateBlock) { + listener.onResponse(null); + } + }; indicesToMarkReadOnly.set(null); indicesToRelease.set(null); @@ -428,6 +444,11 @@ protected void updateIndicesReadOnly(Set indicesToUpdate, ActionListener } listener.onResponse(null); } + + @Override + protected void setIndexCreateBlock(ActionListener listener, boolean indexCreateBlock) { + listener.onResponse(null); + } }; // When free disk on any of node1 or node2 goes below 5% flood watermark, then apply index block on indices not having the block indicesToMarkReadOnly.set(null); @@ -536,6 +557,11 @@ protected void updateIndicesReadOnly(Set indicesToMarkReadOnly, ActionLi long sizeOfRelocatingShards(RoutingNode routingNode, DiskUsage diskUsage, ClusterInfo info, ClusterState reroutedClusterState) { return relocatingShardSizeRef.get(); } + + @Override + protected void setIndexCreateBlock(ActionListener listener, boolean indexCreateBlock) { + listener.onResponse(null); + } }; final ImmutableOpenMap.Builder allDisksOkBuilder; diff --git a/server/src/test/java/org/opensearch/common/xcontent/XContentParserUtilsTests.java b/server/src/test/java/org/opensearch/common/xcontent/XContentParserUtilsTests.java index aafe77a895dbc..36c08d11d424f 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/XContentParserUtilsTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/XContentParserUtilsTests.java @@ -32,11 +32,11 @@ package org.opensearch.common.xcontent; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.CheckedBiConsumer; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.ParseField; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.json.JsonXContent; diff --git a/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java b/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java index 3a1c24806e266..5d252168c7b28 100644 --- a/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java +++ b/server/src/test/java/org/opensearch/discovery/HandshakingTransportAddressConnectorTests.java @@ -35,13 +35,13 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.cluster.ClusterName; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.test.OpenSearchTestCase; diff --git a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java index 44cf3a38f01d1..5de2113672ca5 100644 --- a/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java +++ b/server/src/test/java/org/opensearch/extensions/ExtensionsManagerTests.java @@ -84,6 +84,8 @@ import org.opensearch.test.transport.MockTransportService; import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; +import org.opensearch.transport.ConnectTransportException; +import org.opensearch.transport.NodeNotConnectedException; import org.opensearch.transport.Transport; import org.opensearch.transport.TransportResponse; import org.opensearch.transport.TransportService; @@ -427,23 +429,23 @@ public void testInitialize() throws Exception { mockLogAppender.addExpectation( new MockLogAppender.SeenEventExpectation( - "Connect Transport Exception 1", + "Node Not Connected Exception 1", "org.opensearch.extensions.ExtensionsManager", Level.ERROR, - "ConnectTransportException[[firstExtension][127.0.0.0:9300] connect_timeout[30s]]" + "[secondExtension][127.0.0.1:9301] Node not connected" ) ); mockLogAppender.addExpectation( new MockLogAppender.SeenEventExpectation( - "Connect Transport Exception 2", + "Node Not Connected Exception 2", "org.opensearch.extensions.ExtensionsManager", Level.ERROR, - "ConnectTransportException[[secondExtension][127.0.0.1:9301] connect_exception]; nested: ConnectException[Connection refused];" + "[firstExtension][127.0.0.0:9300] Node not connected" ) ); - extensionsManager.initialize(); + expectThrows(ConnectTransportException.class, () -> extensionsManager.initialize()); // Test needs to be changed to mock the connection between the local node and an extension. Assert statment is commented out for // now. @@ -831,21 +833,8 @@ public void testOnIndexModule() throws Exception { new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), Collections.emptyMap() ); + expectThrows(NodeNotConnectedException.class, () -> extensionsManager.onIndexModule(indexModule)); - try (MockLogAppender mockLogAppender = MockLogAppender.createForLoggers(LogManager.getLogger(ExtensionsManager.class))) { - - mockLogAppender.addExpectation( - new MockLogAppender.SeenEventExpectation( - "IndicesModuleRequest Failure", - "org.opensearch.extensions.ExtensionsManager", - Level.ERROR, - "IndicesModuleRequest failed" - ) - ); - - extensionsManager.onIndexModule(indexModule); - mockLogAppender.assertAllExpectationsMatched(); - } } private void initialize(ExtensionsManager extensionsManager) { diff --git a/server/src/test/java/org/opensearch/extensions/action/ExtensionTransportActionsHandlerTests.java b/server/src/test/java/org/opensearch/extensions/action/ExtensionTransportActionsHandlerTests.java index c3d6372a4f6b8..276e47d7f55a8 100644 --- a/server/src/test/java/org/opensearch/extensions/action/ExtensionTransportActionsHandlerTests.java +++ b/server/src/test/java/org/opensearch/extensions/action/ExtensionTransportActionsHandlerTests.java @@ -31,6 +31,7 @@ import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.ActionNotFoundTransportException; +import org.opensearch.transport.NodeNotConnectedException; import org.opensearch.transport.TransportService; import org.opensearch.transport.nio.MockNioTransport; @@ -172,10 +173,6 @@ public void testSendTransportRequestToExtension() throws InterruptedException { ); assertTrue(response.getStatus()); - ExtensionActionResponse extensionResponse = extensionTransportActionsHandler.sendTransportRequestToExtension(request); - assertEquals( - "Request failed: [firstExtension][127.0.0.0:9300] Node not connected", - new String(extensionResponse.getResponseBytes(), StandardCharsets.UTF_8) - ); + expectThrows(NodeNotConnectedException.class, () -> extensionTransportActionsHandler.sendTransportRequestToExtension(request)); } } diff --git a/server/src/test/java/org/opensearch/index/IndexModuleTests.java b/server/src/test/java/org/opensearch/index/IndexModuleTests.java index d2374e767639c..565ae5a16a384 100644 --- a/server/src/test/java/org/opensearch/index/IndexModuleTests.java +++ b/server/src/test/java/org/opensearch/index/IndexModuleTests.java @@ -44,8 +44,6 @@ import org.apache.lucene.search.similarities.BM25Similarity; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.store.Directory; -import org.apache.lucene.util.SetOnce; -import org.apache.lucene.util.SetOnce.AlreadySetException; import org.opensearch.Version; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; @@ -55,6 +53,8 @@ import org.opensearch.cluster.routing.UnassignedInfo; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.CheckedFunction; +import org.opensearch.common.SetOnce; +import org.opensearch.common.SetOnce.AlreadySetException; import org.opensearch.common.UUIDs; import org.opensearch.common.breaker.CircuitBreaker; import org.opensearch.common.settings.Setting; diff --git a/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java index 878e01c4130bf..c635c708e3b52 100644 --- a/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java @@ -80,7 +80,6 @@ import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; -import org.apache.lucene.util.SetOnce; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.opensearch.OpenSearchException; @@ -96,6 +95,7 @@ import org.opensearch.common.CheckedBiConsumer; import org.opensearch.common.CheckedRunnable; import org.opensearch.common.Randomness; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.TriFunction; import org.opensearch.common.UUIDs; diff --git a/server/src/test/java/org/opensearch/index/fielddata/IndexFieldDataServiceTests.java b/server/src/test/java/org/opensearch/index/fielddata/IndexFieldDataServiceTests.java index d2f9125be996a..d6fd079ac59e8 100644 --- a/server/src/test/java/org/opensearch/index/fielddata/IndexFieldDataServiceTests.java +++ b/server/src/test/java/org/opensearch/index/fielddata/IndexFieldDataServiceTests.java @@ -43,7 +43,7 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.store.ByteBuffersDirectory; import org.apache.lucene.util.Accountable; -import org.apache.lucene.util.SetOnce; +import org.opensearch.common.SetOnce; import org.opensearch.common.lucene.index.OpenSearchDirectoryReader; import org.opensearch.common.settings.Settings; import org.opensearch.index.IndexService; diff --git a/server/src/test/java/org/opensearch/index/query/RewriteableTests.java b/server/src/test/java/org/opensearch/index/query/RewriteableTests.java index eba4e11881aee..6385a57f9f370 100644 --- a/server/src/test/java/org/opensearch/index/query/RewriteableTests.java +++ b/server/src/test/java/org/opensearch/index/query/RewriteableTests.java @@ -31,8 +31,8 @@ package org.opensearch.index.query; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.support.PlainActionFuture; +import org.opensearch.common.SetOnce; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; diff --git a/server/src/test/java/org/opensearch/indices/IndexingMemoryControllerTests.java b/server/src/test/java/org/opensearch/indices/IndexingMemoryControllerTests.java index be9a3b094ad7c..7a362ce8ded74 100644 --- a/server/src/test/java/org/opensearch/indices/IndexingMemoryControllerTests.java +++ b/server/src/test/java/org/opensearch/indices/IndexingMemoryControllerTests.java @@ -32,9 +32,9 @@ package org.opensearch.indices; import org.apache.lucene.search.ReferenceManager; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.cluster.node.DiscoveryNode; +import org.opensearch.common.SetOnce; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; diff --git a/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java b/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java index 0f5bba4f0c332..ba54d3eb3dba8 100644 --- a/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java +++ b/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java @@ -45,7 +45,6 @@ import org.apache.lucene.tests.store.BaseDirectoryWrapper; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; -import org.apache.lucene.util.SetOnce; import org.junit.After; import org.junit.Before; import org.opensearch.ExceptionsHelper; @@ -58,6 +57,7 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.common.Numbers; import org.opensearch.common.Randomness; +import org.opensearch.common.SetOnce; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; diff --git a/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java b/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java index fcd15e85979f7..323f108d18a64 100644 --- a/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java +++ b/server/src/test/java/org/opensearch/ingest/IngestServiceTests.java @@ -34,7 +34,6 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; -import org.apache.lucene.util.SetOnce; import org.opensearch.OpenSearchParseException; import org.opensearch.ResourceNotFoundException; import org.opensearch.Version; @@ -57,6 +56,7 @@ import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.OpenSearchExecutors; diff --git a/server/src/test/java/org/opensearch/node/NodeTests.java b/server/src/test/java/org/opensearch/node/NodeTests.java index 783fe1abdca17..d775a6f645e61 100644 --- a/server/src/test/java/org/opensearch/node/NodeTests.java +++ b/server/src/test/java/org/opensearch/node/NodeTests.java @@ -32,10 +32,10 @@ package org.opensearch.node; import org.apache.lucene.tests.util.LuceneTestCase; -import org.apache.lucene.util.SetOnce; import org.opensearch.bootstrap.BootstrapCheck; import org.opensearch.bootstrap.BootstrapContext; import org.opensearch.cluster.ClusterName; +import org.opensearch.common.SetOnce; import org.opensearch.common.breaker.CircuitBreaker; import org.opensearch.common.network.NetworkModule; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/rest/action/document/RestBulkActionTests.java b/server/src/test/java/org/opensearch/rest/action/document/RestBulkActionTests.java index 19fd74aa30c07..1e13b365c82e3 100644 --- a/server/src/test/java/org/opensearch/rest/action/document/RestBulkActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/document/RestBulkActionTests.java @@ -32,13 +32,13 @@ package org.opensearch.rest.action.document; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.bulk.BulkRequest; import org.opensearch.action.bulk.BulkResponse; import org.opensearch.action.update.UpdateRequest; import org.opensearch.client.node.NodeClient; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestChannel; diff --git a/server/src/test/java/org/opensearch/rest/action/document/RestIndexActionTests.java b/server/src/test/java/org/opensearch/rest/action/document/RestIndexActionTests.java index 85e5497975888..fac1b2c75c9b7 100644 --- a/server/src/test/java/org/opensearch/rest/action/document/RestIndexActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/document/RestIndexActionTests.java @@ -32,7 +32,6 @@ package org.opensearch.rest.action.document; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.DocWriteRequest; import org.opensearch.action.index.IndexRequest; @@ -40,6 +39,7 @@ import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestRequest; diff --git a/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java b/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java index 17abfbf489916..30db12f858c53 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/AggregatorFactoriesTests.java @@ -31,9 +31,9 @@ package org.opensearch.search.aggregations; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.common.ParsingException; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java b/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java index 5ca384daedbff..2ddd6eda122b4 100644 --- a/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java +++ b/server/src/test/java/org/opensearch/search/pit/RestCreatePitActionTests.java @@ -8,11 +8,11 @@ package org.opensearch.search.pit; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.action.search.CreatePitRequest; import org.opensearch.action.search.CreatePitResponse; import org.opensearch.client.node.NodeClient; +import org.opensearch.common.SetOnce; import org.opensearch.rest.RestRequest; import org.opensearch.rest.action.search.RestCreatePitAction; import org.opensearch.test.OpenSearchTestCase; diff --git a/server/src/test/java/org/opensearch/search/pit/RestDeletePitActionTests.java b/server/src/test/java/org/opensearch/search/pit/RestDeletePitActionTests.java index 0bfa16aafe1e3..c54cf5b5395ce 100644 --- a/server/src/test/java/org/opensearch/search/pit/RestDeletePitActionTests.java +++ b/server/src/test/java/org/opensearch/search/pit/RestDeletePitActionTests.java @@ -8,11 +8,11 @@ package org.opensearch.search.pit; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.action.search.DeletePitRequest; import org.opensearch.action.search.DeletePitResponse; import org.opensearch.client.node.NodeClient; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestRequest; diff --git a/server/src/test/java/org/opensearch/search/scroll/RestClearScrollActionTests.java b/server/src/test/java/org/opensearch/search/scroll/RestClearScrollActionTests.java index 065635eff672d..a4605521634fc 100644 --- a/server/src/test/java/org/opensearch/search/scroll/RestClearScrollActionTests.java +++ b/server/src/test/java/org/opensearch/search/scroll/RestClearScrollActionTests.java @@ -32,11 +32,11 @@ package org.opensearch.search.scroll; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.action.search.ClearScrollRequest; import org.opensearch.action.search.ClearScrollResponse; import org.opensearch.client.node.NodeClient; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestRequest; diff --git a/server/src/test/java/org/opensearch/search/scroll/RestSearchScrollActionTests.java b/server/src/test/java/org/opensearch/search/scroll/RestSearchScrollActionTests.java index 9e5c74be47525..7db3714769bcc 100644 --- a/server/src/test/java/org/opensearch/search/scroll/RestSearchScrollActionTests.java +++ b/server/src/test/java/org/opensearch/search/scroll/RestSearchScrollActionTests.java @@ -32,11 +32,11 @@ package org.opensearch.search.scroll; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; import org.opensearch.action.search.SearchResponse; import org.opensearch.action.search.SearchScrollRequest; import org.opensearch.client.node.NodeClient; +import org.opensearch.common.SetOnce; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.xcontent.XContentType; import org.opensearch.rest.RestRequest; diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java index 415a3d487b790..a6677fbc0c99b 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java @@ -34,7 +34,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.util.SetOnce; import org.opensearch.ExceptionsHelper; import org.opensearch.Version; import org.opensearch.action.ActionListener; @@ -149,6 +148,7 @@ import org.opensearch.cluster.service.FakeThreadPoolClusterManagerService; import org.opensearch.common.CheckedConsumer; import org.opensearch.common.Nullable; +import org.opensearch.common.SetOnce; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.network.NetworkModule; import org.opensearch.common.settings.ClusterSettings; diff --git a/server/src/test/java/org/opensearch/transport/TransportRequestDeduplicatorTests.java b/server/src/test/java/org/opensearch/transport/TransportRequestDeduplicatorTests.java index 755459ca96d90..8b4a75a37317b 100644 --- a/server/src/test/java/org/opensearch/transport/TransportRequestDeduplicatorTests.java +++ b/server/src/test/java/org/opensearch/transport/TransportRequestDeduplicatorTests.java @@ -31,8 +31,8 @@ package org.opensearch.transport; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionListener; +import org.opensearch.common.SetOnce; import org.opensearch.tasks.TaskId; import org.opensearch.test.OpenSearchTestCase; diff --git a/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java b/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java index a64193e55836d..c00a3831c0d8d 100644 --- a/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java +++ b/test/framework/src/main/java/org/opensearch/index/mapper/MapperTestCase.java @@ -42,8 +42,8 @@ import org.apache.lucene.search.NormsFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.CheckedConsumer; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.ToXContent; diff --git a/test/framework/src/main/java/org/opensearch/repositories/blobstore/OpenSearchBlobStoreRepositoryIntegTestCase.java b/test/framework/src/main/java/org/opensearch/repositories/blobstore/OpenSearchBlobStoreRepositoryIntegTestCase.java index c5f4e171e0cf2..4fe9f354d8d10 100644 --- a/test/framework/src/main/java/org/opensearch/repositories/blobstore/OpenSearchBlobStoreRepositoryIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/repositories/blobstore/OpenSearchBlobStoreRepositoryIntegTestCase.java @@ -33,7 +33,6 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.SetOnce; import org.opensearch.action.ActionRunnable; import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; @@ -42,6 +41,7 @@ import org.opensearch.action.index.IndexRequestBuilder; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.client.Client; +import org.opensearch.common.SetOnce; import org.opensearch.common.blobstore.BlobContainer; import org.opensearch.common.blobstore.BlobMetadata; import org.opensearch.common.blobstore.BlobPath; diff --git a/test/framework/src/main/java/org/opensearch/test/InternalAggregationTestCase.java b/test/framework/src/main/java/org/opensearch/test/InternalAggregationTestCase.java index 2cba15f2e2039..921fd64d3acb6 100644 --- a/test/framework/src/main/java/org/opensearch/test/InternalAggregationTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/InternalAggregationTestCase.java @@ -32,8 +32,8 @@ package org.opensearch.test; -import org.apache.lucene.util.SetOnce; import org.opensearch.common.ParseField; +import org.opensearch.common.SetOnce; import org.opensearch.common.breaker.CircuitBreaker; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.NamedWriteableRegistry; diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java index ee6b6ab37423e..86123012fee5d 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java @@ -1882,7 +1882,8 @@ protected Settings nodeSettings(int nodeOrdinal) { // randomly enable low-level search cancellation to make sure it does not alter results .put(SearchService.LOW_LEVEL_CANCELLATION_SETTING.getKey(), randomBoolean()) .putList(DISCOVERY_SEED_HOSTS_SETTING.getKey()) // empty list disables a port scan for other nodes - .putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file"); + .putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file") + .put(featureFlagSettings()); return builder.build(); } diff --git a/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java b/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java index a353f53ab1bb3..4fbf56babea29 100644 --- a/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/rest/OpenSearchRestTestCase.java @@ -47,7 +47,6 @@ import org.apache.hc.core5.reactor.ssl.TlsDetails; import org.apache.hc.core5.ssl.SSLContexts; import org.apache.hc.core5.util.Timeout; -import org.apache.lucene.util.SetOnce; import org.opensearch.Version; import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksAction; import org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest; @@ -60,6 +59,7 @@ import org.opensearch.client.RestClientBuilder; import org.opensearch.client.WarningsHandler; import org.opensearch.common.CheckedRunnable; +import org.opensearch.common.SetOnce; import org.opensearch.common.Strings; import org.opensearch.common.io.PathUtils; import org.opensearch.common.settings.Settings;