mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
Move lock file check for data dir to later step (#18636)
* do not write/check for lock file in data dir during preflight test * remove unnecessary directory read check, handled by validator * add lockfile check to startup * remove unused exception * fix compatibility check url * add more information and show data node list on restart step * ignore PROCESS_STOPPED event when in WAITING_FOR_CONFIGURATION state to avoid ugly exception * fix test and show MigrationDatanodeList
This commit is contained in:
committed by
GitHub
parent
342c9c3c9b
commit
0a887859ea
@@ -89,7 +89,7 @@ public class Configuration extends BaseConfiguration {
|
||||
@Parameter(value = "opensearch_plugins_location", validators = DirectoryReadableValidator.class)
|
||||
private Path opensearchPluginsDir = Path.of("dist/plugins");
|
||||
|
||||
@Parameter(value = "opensearch_data_location", required = true, validators = DirectoryWritableValidator.class)
|
||||
@Parameter(value = "opensearch_data_location", required = true, validators = DirectoryReadableValidator.class)
|
||||
private Path opensearchDataLocation = Path.of("datanode/data");
|
||||
|
||||
@Parameter(value = "opensearch_logs_location", required = true, validators = DirectoryWritableValidator.class)
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.graylog.datanode.bootstrap.preflight;
|
||||
|
||||
import com.google.common.io.CharStreams;
|
||||
import jakarta.inject.Inject;
|
||||
import org.graylog.datanode.configuration.DatanodeConfiguration;
|
||||
import org.graylog.datanode.configuration.DatanodeDirectories;
|
||||
import org.graylog2.bootstrap.preflight.PreflightCheck;
|
||||
import org.graylog2.bootstrap.preflight.PreflightCheckException;
|
||||
import org.graylog2.plugin.system.NodeId;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
@@ -61,11 +60,10 @@ public class DatanodeDirectoriesLockfileCheck implements PreflightCheck {
|
||||
@Override
|
||||
public void runCheck() throws PreflightCheckException {
|
||||
checkDatanodeLock(directories.getConfigurationTargetDir());
|
||||
checkDatanodeLock(directories.getDataTargetDir());
|
||||
checkDatanodeLock(directories.getLogsTargetDir());
|
||||
}
|
||||
|
||||
private void checkDatanodeLock(Path dir) {
|
||||
public void checkDatanodeLock(Path dir) {
|
||||
final Path lockfile = dir.resolve(DATANODE_LOCKFILE);
|
||||
try (FileChannel channel = FileChannel.open(lockfile, StandardOpenOption.READ, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
||||
doCheckLockFile(channel, dir);
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Graylog, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the Server Side Public License, version 1,
|
||||
* as published by MongoDB, Inc.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* Server Side Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the Server Side Public License
|
||||
* along with this program. If not, see
|
||||
* <http://www.mongodb.com/licensing/server-side-public-license>.
|
||||
*/
|
||||
package org.graylog.datanode.bootstrap.preflight;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DatanodeDirectoryException extends IOException {
|
||||
public DatanodeDirectoryException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DatanodeDirectoryException(String message, IOException cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import jakarta.inject.Inject;
|
||||
import jakarta.inject.Provider;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.graylog.datanode.Configuration;
|
||||
import org.graylog.datanode.bootstrap.preflight.DatanodeDirectoriesLockfileCheck;
|
||||
import org.graylog.datanode.configuration.DatanodeConfiguration;
|
||||
import org.graylog.datanode.metrics.ConfigureMetricsIndexSettings;
|
||||
import org.graylog.datanode.process.OpensearchConfiguration;
|
||||
@@ -58,6 +59,7 @@ public class OpensearchProcessService extends AbstractIdleService implements Pro
|
||||
private final DataNodeProvisioningService dataNodeProvisioningService;
|
||||
private final IndexFieldTypesService indexFieldTypesService;
|
||||
private final ClusterEventBus clusterEventBus;
|
||||
private final DatanodeDirectoriesLockfileCheck lockfileCheck;
|
||||
|
||||
|
||||
@Inject
|
||||
@@ -72,13 +74,15 @@ public class OpensearchProcessService extends AbstractIdleService implements Pro
|
||||
final IndexFieldTypesService indexFieldTypesService,
|
||||
final ObjectMapper objectMapper,
|
||||
final ProcessStateMachine processStateMachine,
|
||||
final ClusterEventBus clusterEventBus) {
|
||||
final ClusterEventBus clusterEventBus,
|
||||
final DatanodeDirectoriesLockfileCheck lockfileCheck) {
|
||||
this.configurationProvider = configurationProvider;
|
||||
this.eventBus = eventBus;
|
||||
this.nodeId = nodeId;
|
||||
this.dataNodeProvisioningService = dataNodeProvisioningService;
|
||||
this.indexFieldTypesService = indexFieldTypesService;
|
||||
this.clusterEventBus = clusterEventBus;
|
||||
this.lockfileCheck = lockfileCheck;
|
||||
this.process = createOpensearchProcess(datanodeConfiguration, trustManager, configuration, nodeService, objectMapper, processStateMachine);
|
||||
eventBus.register(this);
|
||||
}
|
||||
@@ -142,7 +146,14 @@ public class OpensearchProcessService extends AbstractIdleService implements Pro
|
||||
final OpensearchConfiguration config = configurationProvider.get();
|
||||
configure();
|
||||
if (config.securityConfigured()) {
|
||||
this.process.start();
|
||||
|
||||
try {
|
||||
lockfileCheck.checkDatanodeLock(config.datanodeDirectories().getDataTargetDir());
|
||||
this.process.start();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not start up data node", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ public class ProcessStateMachine extends StateMachine<ProcessState, ProcessEvent
|
||||
.permit(ProcessEvent.PROCESS_PREPARED, ProcessState.PREPARED)
|
||||
// jump to started only allowed to facilitate startup with insecure config
|
||||
.permit(ProcessEvent.PROCESS_STARTED, ProcessState.STARTING)
|
||||
.ignore(ProcessEvent.PROCESS_STOPPED)
|
||||
.ignore(ProcessEvent.HEALTH_CHECK_FAILED);
|
||||
|
||||
config.configure(ProcessState.PREPARED)
|
||||
|
||||
Reference in New Issue
Block a user