forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Signed-off-by: Jay Deng <jayd0104@gmail.com>
- Loading branch information
Showing
7 changed files
with
129 additions
and
32 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.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. | ||
*/ | ||
final class CompositeIndexStoreListener implements IndexStoreListener { | ||
private final List<IndexStoreListener> listeners; | ||
private final Logger logger = LogManager.getLogger(CompositeIndexStoreListener.class); | ||
|
||
public CompositeIndexStoreListener(List<IndexStoreListener> listeners) { | ||
this.listeners = listeners; | ||
} | ||
|
||
public void addListener(IndexStoreListener listener) { | ||
this.listeners.add(listener); | ||
} | ||
|
||
@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