-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wrr-state-across-requests
- Loading branch information
Showing
101 changed files
with
824 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ BWC_VERSION: | |
- "2.4.1" | ||
- "2.4.2" | ||
- "2.5.0" | ||
- "2.5.1" | ||
- "2.6.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
libs/core/src/main/java/org/opensearch/common/SetOnce.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<T> 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<T> { | ||
private T object; | ||
|
||
private Wrapper(T object) { | ||
this.object = object; | ||
} | ||
} | ||
|
||
private final AtomicReference<Wrapper<T>> 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<T> wrapper = set.get(); | ||
return wrapper == null ? null : wrapper.object; | ||
} | ||
} |
Oops, something went wrong.