-
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.
Make IndexStoreListener a pluggable interface (#16583)
Signed-off-by: Jay Deng <jayd0104@gmail.com> (cherry picked from commit 9b7681c) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
468e925
commit b602dfd
Showing
7 changed files
with
138 additions
and
29 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
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
73 changes: 73 additions & 0 deletions
73
server/src/main/java/org/opensearch/index/store/IndexStoreListener.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,73 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.opensearch.index.store; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.opensearch.common.annotation.PublicApi; | ||
import org.opensearch.core.index.Index; | ||
import org.opensearch.core.index.shard.ShardId; | ||
import org.opensearch.env.NodeEnvironment; | ||
import org.opensearch.index.IndexSettings; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* A listener that is executed on per-index and per-shard store events, like deleting shard path | ||
* | ||
* @opensearch.api | ||
*/ | ||
@PublicApi(since = "2.19.0") | ||
public interface IndexStoreListener { | ||
default void beforeShardPathDeleted(ShardId shardId, IndexSettings indexSettings, NodeEnvironment env) {} | ||
|
||
default void beforeIndexPathDeleted(Index index, IndexSettings indexSettings, NodeEnvironment env) {} | ||
|
||
IndexStoreListener EMPTY = new IndexStoreListener() { | ||
}; | ||
|
||
/** | ||
* A Composite listener that multiplexes calls to each of the listeners methods. | ||
* | ||
* @opensearch.api | ||
*/ | ||
@PublicApi(since = "2.19.0") | ||
final class CompositeIndexStoreListener implements IndexStoreListener { | ||
private final List<IndexStoreListener> listeners; | ||
private final static Logger logger = LogManager.getLogger(CompositeIndexStoreListener.class); | ||
|
||
public CompositeIndexStoreListener(List<IndexStoreListener> listeners) { | ||
this.listeners = Collections.unmodifiableList(listeners); | ||
} | ||
|
||
@Override | ||
public void beforeShardPathDeleted(ShardId shardId, IndexSettings indexSettings, NodeEnvironment env) { | ||
for (IndexStoreListener listener : listeners) { | ||
try { | ||
listener.beforeShardPathDeleted(shardId, indexSettings, env); | ||
} catch (Exception e) { | ||
logger.warn(() -> new ParameterizedMessage("beforeShardPathDeleted listener [{}] failed", listener), e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeIndexPathDeleted(Index index, IndexSettings indexSettings, NodeEnvironment env) { | ||
for (IndexStoreListener listener : listeners) { | ||
try { | ||
listener.beforeIndexPathDeleted(index, indexSettings, env); | ||
} catch (Exception e) { | ||
logger.warn(() -> new ParameterizedMessage("beforeIndexPathDeleted listener [{}] failed", listener), e); | ||
} | ||
} | ||
} | ||
} | ||
} |
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