Search in sources :

Example 1 with PersistedClusterStateService

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Metadata(org.elasticsearch.cluster.metadata.Metadata) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService) ElasticsearchException(org.elasticsearch.ElasticsearchException) Settings(org.elasticsearch.common.settings.Settings)

Example 2 with PersistedClusterStateService

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);
}
Also used : NodeMetadata(org.elasticsearch.env.NodeMetadata) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ElasticsearchException(org.elasticsearch.ElasticsearchException) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService)

Example 3 with PersistedClusterStateService

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService)

Example 4 with PersistedClusterStateService

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) UserException(org.elasticsearch.cli.UserException) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService) Settings(org.elasticsearch.common.settings.Settings)

Example 5 with PersistedClusterStateService

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.");
}
Also used : Path(java.nio.file.Path) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService)

Aggregations

PersistedClusterStateService (org.elasticsearch.gateway.PersistedClusterStateService)8 ClusterState (org.elasticsearch.cluster.ClusterState)3 Metadata (org.elasticsearch.cluster.metadata.Metadata)3 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)3 Settings (org.elasticsearch.common.settings.Settings)3 Path (java.nio.file.Path)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 Before (org.junit.Before)2 UserException (org.elasticsearch.cli.UserException)1 NodeMetadata (org.elasticsearch.env.NodeMetadata)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1