use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.
the class UnsafeBootstrapMasterCommand method processNodePaths.
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
final Tuple<Long, ClusterState> state = loadTermAndClusterState(persistedClusterStateService, env);
final ClusterState oldClusterState = state.v2();
final Metadata metadata = oldClusterState.metadata();
final CoordinationMetadata coordinationMetadata = metadata.coordinationMetadata();
if (coordinationMetadata == null || coordinationMetadata.getLastCommittedConfiguration() == null || coordinationMetadata.getLastCommittedConfiguration().isEmpty()) {
throw new ElasticsearchException(EMPTY_LAST_COMMITTED_VOTING_CONFIG_MSG);
}
terminal.println(String.format(Locale.ROOT, CLUSTER_STATE_TERM_VERSION_MSG_FORMAT, coordinationMetadata.term(), metadata.version()));
CoordinationMetadata newCoordinationMetadata = CoordinationMetadata.builder(coordinationMetadata).clearVotingConfigExclusions().lastAcceptedConfiguration(new CoordinationMetadata.VotingConfiguration(Collections.singleton(persistedClusterStateService.getNodeId()))).lastCommittedConfiguration(new CoordinationMetadata.VotingConfiguration(Collections.singleton(persistedClusterStateService.getNodeId()))).build();
Settings persistentSettings = Settings.builder().put(metadata.persistentSettings()).put(UNSAFE_BOOTSTRAP.getKey(), true).build();
Metadata newMetadata = Metadata.builder(metadata).clusterUUID(Metadata.UNKNOWN_CLUSTER_UUID).generateClusterUuidIfNeeded().clusterUUIDCommitted(true).persistentSettings(persistentSettings).coordinationMetadata(newCoordinationMetadata).build();
final ClusterState newClusterState = ClusterState.builder(oldClusterState).metadata(newMetadata).build();
terminal.println(Terminal.Verbosity.VERBOSE, "[old cluster state = " + oldClusterState + ", new cluster state = " + newClusterState + "]");
confirm(terminal, CONFIRMATION_MSG);
try (PersistedClusterStateService.Writer writer = persistedClusterStateService.createWriter()) {
writer.writeFullStateAndCommit(state.v1(), newClusterState);
}
terminal.println(MASTER_NODE_BOOTSTRAPPED_MSG);
}
use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.
the class ElasticsearchNodeCommand method createPersistedClusterStateService.
public static PersistedClusterStateService createPersistedClusterStateService(Settings settings, Path[] dataPaths) throws IOException {
final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(dataPaths);
if (nodeMetadata == null) {
throw new ElasticsearchException(NO_NODE_METADATA_FOUND_MSG);
}
String nodeId = nodeMetadata.nodeId();
return new PersistedClusterStateService(dataPaths, nodeId, NAMED_X_CONTENT_REGISTRY, BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L, true);
}
use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.
the class DetachClusterCommand method processNodePaths.
@Override
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException {
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
final ClusterState oldClusterState = loadTermAndClusterState(persistedClusterStateService, env).v2();
final ClusterState newClusterState = ClusterState.builder(oldClusterState).metadata(updateMetadata(oldClusterState.metadata())).build();
terminal.println(Terminal.Verbosity.VERBOSE, "[old cluster state = " + oldClusterState + ", new cluster state = " + newClusterState + "]");
confirm(terminal, CONFIRMATION_MSG);
try (PersistedClusterStateService.Writer writer = persistedClusterStateService.createWriter()) {
writer.writeFullStateAndCommit(updateCurrentTerm(), newClusterState);
}
terminal.println(NODE_DETACHED_MSG);
}
use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.
the class RemoveSettingsCommand method processNodePaths.
@Override
protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException, UserException {
final List<String> settingsToRemove = arguments.values(options);
if (settingsToRemove.isEmpty()) {
throw new UserException(ExitCodes.USAGE, "Must supply at least one setting to remove");
}
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state");
final Tuple<Long, ClusterState> termAndClusterState = loadTermAndClusterState(persistedClusterStateService, env);
final ClusterState oldClusterState = termAndClusterState.v2();
final Settings oldPersistentSettings = oldClusterState.metadata().persistentSettings();
terminal.println(Terminal.Verbosity.VERBOSE, "persistent settings: " + oldPersistentSettings);
final Settings.Builder newPersistentSettingsBuilder = Settings.builder().put(oldPersistentSettings);
for (String settingToRemove : settingsToRemove) {
boolean matched = false;
for (String settingKey : oldPersistentSettings.keySet()) {
if (Regex.simpleMatch(settingToRemove, settingKey)) {
newPersistentSettingsBuilder.remove(settingKey);
if (matched == false) {
terminal.println("The following settings will be removed:");
}
matched = true;
terminal.println(settingKey + ": " + oldPersistentSettings.get(settingKey));
}
}
if (matched == false) {
throw new UserException(ExitCodes.USAGE, "No persistent cluster settings matching [" + settingToRemove + "] were found on this node");
}
}
final ClusterState newClusterState = ClusterState.builder(oldClusterState).metadata(Metadata.builder(oldClusterState.metadata()).persistentSettings(newPersistentSettingsBuilder.build()).build()).build();
terminal.println(Terminal.Verbosity.VERBOSE, "[old cluster state = " + oldClusterState + ", new cluster state = " + newClusterState + "]");
confirm(terminal, CONFIRMATION_MSG);
try (PersistedClusterStateService.Writer writer = persistedClusterStateService.createWriter()) {
writer.writeFullStateAndCommit(termAndClusterState.v1(), newClusterState);
}
terminal.println(SETTINGS_REMOVED_MSG);
}
use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.
the class NodeRepurposeCommand method processNoMasterNoDataNode.
private void processNoMasterNoDataNode(Terminal terminal, Path[] dataPaths, Environment env) throws IOException {
NodeEnvironment.NodePath[] nodePaths = toNodePaths(dataPaths);
terminal.println(Terminal.Verbosity.VERBOSE, "Collecting shard data paths");
List<Path> shardDataPaths = NodeEnvironment.collectShardDataPaths(nodePaths);
terminal.println(Terminal.Verbosity.VERBOSE, "Collecting index metadata paths");
List<Path> indexMetadataPaths = NodeEnvironment.collectIndexMetadataPaths(nodePaths);
Set<Path> indexPaths = uniqueParentPaths(shardDataPaths, indexMetadataPaths);
final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
final Metadata metadata = loadClusterState(terminal, env, persistedClusterStateService).metadata();
if (indexPaths.isEmpty() && metadata.indices().isEmpty()) {
terminal.println(Terminal.Verbosity.NORMAL, NO_DATA_TO_CLEAN_UP_FOUND);
return;
}
final Set<String> indexUUIDs = Sets.union(indexUUIDsFor(indexPaths), StreamSupport.stream(metadata.indices().values().spliterator(), false).map(imd -> imd.value.getIndexUUID()).collect(Collectors.toSet()));
outputVerboseInformation(terminal, indexPaths, indexUUIDs, metadata);
terminal.println(noMasterMessage(indexUUIDs.size(), shardDataPaths.size(), indexMetadataPaths.size()));
outputHowToSeeVerboseInformation(terminal);
terminal.println("Node is being re-purposed as no-master and no-data. Clean-up of index data will be performed.");
confirm(terminal, "Do you want to proceed?");
// clean-up shard dirs
removePaths(terminal, indexPaths);
// clean-up all metadata dirs
MetadataStateFormat.deleteMetaState(dataPaths);
IOUtils.rm(Stream.of(dataPaths).map(path -> path.resolve(INDICES_FOLDER)).toArray(Path[]::new));
terminal.println("Node successfully repurposed to no-master and no-data.");
}
Aggregations