add a callback when shard level routing changes
This commit is contained in:
parent
8b9aa1fd27
commit
0d3dd3845d
|
@ -201,15 +201,21 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
|||
}
|
||||
|
||||
public InternalIndexShard routingEntry(ShardRouting shardRouting) {
|
||||
ShardRouting currentRouting = this.shardRouting;
|
||||
if (!shardRouting.shardId().equals(shardId())) {
|
||||
throw new ElasticSearchIllegalArgumentException("Trying to set a routing entry with shardId [" + shardRouting.shardId() + "] on a shard with shardId [" + shardId() + "]");
|
||||
}
|
||||
if (this.shardRouting != null) {
|
||||
if (!shardRouting.primary() && this.shardRouting.primary()) {
|
||||
if (currentRouting != null) {
|
||||
if (!shardRouting.primary() && currentRouting.primary()) {
|
||||
logger.warn("suspect illegal state: trying to move shard from primary mode to backup mode");
|
||||
}
|
||||
// if its the same routing, return
|
||||
if (currentRouting.equals(shardRouting)) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
this.shardRouting = shardRouting;
|
||||
indicesLifecycle.shardRoutingChanged(this, currentRouting, shardRouting);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.service.IndexService;
|
||||
|
@ -28,8 +29,6 @@ import org.elasticsearch.index.shard.service.IndexShard;
|
|||
/**
|
||||
* A global component allowing to register for lifecycle of an index (create/closed) and
|
||||
* an index shard (created/closed).
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface IndicesLifecycle {
|
||||
|
||||
|
@ -48,6 +47,17 @@ public interface IndicesLifecycle {
|
|||
*/
|
||||
public abstract static class Listener {
|
||||
|
||||
/**
|
||||
* Called when the shard routing has changed state.
|
||||
*
|
||||
* @param indexShard The index shard
|
||||
* @param oldRouting The old routing state (can be null)
|
||||
* @param newRouting The new routing state
|
||||
*/
|
||||
public void shardRoutingChanged(IndexShard indexShard, @Nullable ShardRouting oldRouting, ShardRouting newRouting) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the index gets created.
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
|
@ -50,6 +51,12 @@ public class InternalIndicesLifecycle extends AbstractComponent implements Indic
|
|||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void shardRoutingChanged(IndexShard indexShard, @Nullable ShardRouting oldRouting, ShardRouting newRouting) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.shardRoutingChanged(indexShard, oldRouting, newRouting);
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeIndexCreated(Index index) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.beforeIndexCreated(index);
|
||||
|
|
Loading…
Reference in New Issue