Search in sources :

Example 6 with PersistedClusterStateService

use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.

the class NodeRepurposeCommand method processMasterNoDataNode.

private void processMasterNoDataNode(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);
    if (shardDataPaths.isEmpty()) {
        terminal.println(NO_SHARD_DATA_TO_CLEAN_UP_FOUND);
        return;
    }
    final PersistedClusterStateService persistedClusterStateService = createPersistedClusterStateService(env.settings(), dataPaths);
    final Metadata metadata = loadClusterState(terminal, env, persistedClusterStateService).metadata();
    final Set<Path> indexPaths = uniqueParentPaths(shardDataPaths);
    final Set<String> indexUUIDs = indexUUIDsFor(indexPaths);
    outputVerboseInformation(terminal, shardDataPaths, indexUUIDs, metadata);
    terminal.println(shardMessage(shardDataPaths.size(), indexUUIDs.size()));
    outputHowToSeeVerboseInformation(terminal);
    terminal.println("Node is being re-purposed as master and no-data. Clean-up of shard data will be performed.");
    confirm(terminal, "Do you want to proceed?");
    // clean-up shard dirs
    removePaths(terminal, shardDataPaths);
    terminal.println("Node successfully repurposed to 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)

Example 7 with PersistedClusterStateService

use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.

the class NodeRepurposeCommandTests method createNodePaths.

@Before
public void createNodePaths() throws IOException {
    dataMasterSettings = buildEnvSettings(Settings.EMPTY);
    environment = TestEnvironment.newEnvironment(dataMasterSettings);
    try (NodeEnvironment nodeEnvironment = new NodeEnvironment(dataMasterSettings, environment)) {
        nodePaths = nodeEnvironment.nodeDataPaths();
        final String nodeId = randomAlphaOfLength(10);
        try (PersistedClusterStateService.Writer writer = new PersistedClusterStateService(nodePaths, nodeId, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(dataMasterSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L, true).createWriter()) {
            writer.writeFullStateAndCommit(1L, ClusterState.EMPTY_STATE);
        }
    }
    dataNoMasterSettings = Settings.builder().put(dataMasterSettings).put(Node.NODE_MASTER_SETTING.getKey(), false).build();
    noDataNoMasterSettings = Settings.builder().put(dataMasterSettings).put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), false).build();
    noDataMasterSettings = Settings.builder().put(dataMasterSettings).put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true).build();
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Matchers.containsString(org.hamcrest.Matchers.containsString) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService) Before(org.junit.Before)

Example 8 with PersistedClusterStateService

use of org.elasticsearch.gateway.PersistedClusterStateService in project crate by crate.

the class OverrideNodeVersionCommandTests method createNodePaths.

@Before
public void createNodePaths() throws IOException {
    final Settings settings = buildEnvSettings(Settings.EMPTY);
    environment = TestEnvironment.newEnvironment(settings);
    try (NodeEnvironment nodeEnvironment = new NodeEnvironment(settings, environment)) {
        nodePaths = nodeEnvironment.nodeDataPaths();
        nodeId = nodeEnvironment.nodeId();
        try (PersistedClusterStateService.Writer writer = new PersistedClusterStateService(nodePaths, nodeId, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L, true).createWriter()) {
            writer.writeFullStateAndCommit(1L, ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().persistentSettings(Settings.builder().put(Metadata.SETTING_READ_ONLY_SETTING.getKey(), true).build()).build()).build());
        }
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) PersistedClusterStateService(org.elasticsearch.gateway.PersistedClusterStateService) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

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