Skip to content

Commit

Permalink
[GATEWAY] Move GatewayShardsState logic into IndexShard
Browse files Browse the repository at this point in the history
The index shard should take care of shard state persistence since it has
all the information and the gateway concept has been removed in master.
  • Loading branch information
s1monw committed Mar 19, 2015
1 parent 1168347 commit a6897aa
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 542 deletions.
Expand Up @@ -301,19 +301,21 @@ public boolean equals(Object o) {
if (shardId != that.shardId) {
return false;
}
if (currentNodeId != null ? !currentNodeId.equals(that.currentNodeId) : that.currentNodeId != null)
if (currentNodeId != null ? !currentNodeId.equals(that.currentNodeId) : that.currentNodeId != null) {
return false;
}
if (index != null ? !index.equals(that.index) : that.index != null) {
return false;
}
if (relocatingNodeId != null ? !relocatingNodeId.equals(that.relocatingNodeId) : that.relocatingNodeId != null)
if (relocatingNodeId != null ? !relocatingNodeId.equals(that.relocatingNodeId) : that.relocatingNodeId != null) {
return false;
}
if (state != that.state) {
return false;
}
if (restoreSource != null ? !restoreSource.equals(that.restoreSource) : that.restoreSource != null)
if (restoreSource != null ? !restoreSource.equals(that.restoreSource) : that.restoreSource != null) {
return false;

}
return true;
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/elasticsearch/gateway/Gateway.java
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.indices.IndicesService;

import java.nio.file.Path;

Expand All @@ -43,7 +44,6 @@ public class Gateway extends AbstractComponent implements ClusterStateListener {

private final NodeEnvironment nodeEnv;

private final GatewayShardsState shardsState;
private final GatewayMetaState metaState;

private final TransportNodesListGatewayMetaState listGatewayMetaState;
Expand All @@ -52,8 +52,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener {
private final ClusterName clusterName;

@Inject
public Gateway(Settings settings, ClusterService clusterService, NodeEnvironment nodeEnv,
GatewayShardsState shardsState, GatewayMetaState metaState,
public Gateway(Settings settings, ClusterService clusterService, NodeEnvironment nodeEnv, GatewayMetaState metaState,
TransportNodesListGatewayMetaState listGatewayMetaState, ClusterName clusterName) {
super(settings);
this.clusterService = clusterService;
Expand All @@ -62,8 +61,6 @@ public Gateway(Settings settings, ClusterService clusterService, NodeEnvironment
this.listGatewayMetaState = listGatewayMetaState;
this.clusterName = clusterName;

this.shardsState = shardsState;

clusterService.addLast(this);

// we define what is our minimum "master" nodes, use that to allow for recovery
Expand Down Expand Up @@ -180,7 +177,6 @@ public void clusterChanged(final ClusterChangedEvent event) {
// order is important, first metaState, and then shardsState
// so dangling indices will be recorded
metaState.clusterChanged(event);
shardsState.clusterChanged(event);
}

public interface GatewayStateRecoveredListener {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/elasticsearch/gateway/GatewayMetaState.java
Expand Up @@ -37,6 +37,7 @@
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.env.NodeEnvironment;

import java.io.IOException;
Expand Down Expand Up @@ -68,6 +69,9 @@ public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateSer
this.danglingIndicesState = danglingIndicesState;
nodesListGatewayMetaState.init(this);

if (DiscoveryNode.dataNode(settings)) {
ensureNoPre019ShardState(nodeEnv);
}

if (DiscoveryNode.masterNode(settings) || DiscoveryNode.dataNode(settings)) {
nodeEnv.ensureAtomicMoveSupported();
Expand Down Expand Up @@ -230,4 +234,21 @@ private void pre20Upgrade() throws Exception {
+ "used some custom routing logic, you can now remove these settings from your `elasticsearch.yml` file", DEPRECATED_SETTING_ROUTING_HASH_FUNCTION, DEPRECATED_SETTING_ROUTING_USE_TYPE);
}
}


// shard state BWC
private void ensureNoPre019ShardState(NodeEnvironment nodeEnv) throws Exception {
for (Path dataLocation : nodeEnv.nodeDataPaths()) {
final Path stateLocation = dataLocation.resolve(MetaDataStateFormat.STATE_DIR_NAME);
if (Files.exists(stateLocation)) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(stateLocation, "shards-*")) {
for (Path stateFile : stream) {
throw new ElasticsearchIllegalStateException("Detected pre 0.19 shard state file please upgrade to a version before "
+ Version.CURRENT.minimumCompatibilityVersion()
+ " first to upgrade state structures - shard state found: [" + stateFile.getParent().toAbsolutePath());
}
}
}
}
}
}
1 change: 0 additions & 1 deletion src/main/java/org/elasticsearch/gateway/GatewayModule.java
Expand Up @@ -32,7 +32,6 @@ protected void configure() {
bind(DanglingIndicesState.class).asEagerSingleton();
bind(GatewayService.class).asEagerSingleton();
bind(Gateway.class).asEagerSingleton();
bind(GatewayShardsState.class).asEagerSingleton();
bind(TransportNodesListGatewayMetaState.class).asEagerSingleton();
bind(GatewayMetaState.class).asEagerSingleton();
bind(TransportNodesListGatewayStartedShards.class).asEagerSingleton();
Expand Down
275 changes: 0 additions & 275 deletions src/main/java/org/elasticsearch/gateway/GatewayShardsState.java

This file was deleted.

0 comments on commit a6897aa

Please sign in to comment.