Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zen2: Persist cluster states the old way on non-master-eligible nodes #36247

Merged
merged 5 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ public void applyClusterState(ClusterChangedEvent event) {
}

try {
// Hack: This is to ensure that non-master-eligible Zen2 nodes always store a current term
// that's higher than the last accepted term.
// TODO: can we get rid of this hack?
if (event.state().term() > getCurrentTerm()) {
innerSetCurrentTerm(event.state().term());
}

updateClusterState(event.state(), event.previousState());
incrementalWrite = true;
} catch (WriteStateException e) {
Expand All @@ -225,17 +232,21 @@ public ClusterState getLastAcceptedState() {

@Override
public void setCurrentTerm(long currentTerm) {
Manifest manifest = new Manifest(currentTerm, previousManifest.getClusterStateVersion(), previousManifest.getGlobalGeneration(),
new HashMap<>(previousManifest.getIndexGenerations()));
try {
metaStateService.writeManifestAndCleanup("current term changed", manifest);
previousManifest = manifest;
innerSetCurrentTerm(currentTerm);
} catch (WriteStateException e) {
logger.warn("Exception occurred when setting current term", e);
//TODO re-throw exception
}
}

private void innerSetCurrentTerm(long currentTerm) throws WriteStateException {
Manifest manifest = new Manifest(currentTerm, previousManifest.getClusterStateVersion(), previousManifest.getGlobalGeneration(),
new HashMap<>(previousManifest.getIndexGenerations()));
metaStateService.writeManifestAndCleanup("current term changed", manifest);
previousManifest = manifest;
}

@Override
public void setLastAcceptedState(ClusterState clusterState) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import org.elasticsearch.cluster.coordination.CoordinationState;
import org.elasticsearch.cluster.coordination.Coordinator;
import org.elasticsearch.cluster.coordination.InMemoryPersistedState;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.service.ClusterApplier;
import org.elasticsearch.cluster.service.ClusterApplierService;
import org.elasticsearch.cluster.service.MasterService;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
Expand Down Expand Up @@ -80,6 +83,12 @@ public Map<String, Supplier<Discovery>> getDiscoveryTypes(ThreadPool threadPool,
if (USE_ZEN2.get(settings)) {
Supplier<CoordinationState.PersistedState> persistedStateSupplier = () -> {
gatewayMetaState.applyClusterStateUpdaters();
if (DiscoveryNode.isMasterNode(settings) == false) {
// use Zen1 way of writing cluster state for non-master-eligible nodes
// this avoids concurrent manipulating of IndexMetadata with IndicesStore
((ClusterApplierService) clusterApplier).addLowPriorityApplier(gatewayMetaState);
return new InMemoryPersistedState(gatewayMetaState.getCurrentTerm(), gatewayMetaState.getLastAcceptedState());
}
return gatewayMetaState;
};

Expand Down