-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/issue-20592
- Loading branch information
Showing
61 changed files
with
861 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type = "fixed" | ||
message = "Fix link target for search query error documentation links." | ||
|
||
issues = ["13822"] | ||
pulls = ["20563"] | ||
|
||
details.user = """ | ||
The documentation link now points to the error types section again, instead of just the search query page. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type = "f" | ||
message = "Datanode preflight check for node.lock, preventing parallel run of opensearch and datanode" | ||
|
||
pulls = ["20366"] |
89 changes: 89 additions & 0 deletions
89
data-node/src/main/java/org/graylog/datanode/rest/OpensearchLockCheckController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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.rest; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import org.graylog.datanode.configuration.DatanodeConfiguration; | ||
import org.graylog.plugins.views.storage.migration.state.actions.OpensearchLockCheckResult; | ||
import org.graylog.plugins.views.storage.migration.state.actions.OpensearchNodeLock; | ||
import org.graylog2.bootstrap.preflight.PreflightCheckException; | ||
|
||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.FileLock; | ||
import java.nio.channels.NonWritableChannelException; | ||
import java.nio.channels.OverlappingFileLockException; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Collections; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Path("/lock-check") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class OpensearchLockCheckController { | ||
|
||
private final java.nio.file.Path dataTargetDir; | ||
|
||
@Inject | ||
public OpensearchLockCheckController(DatanodeConfiguration datanodeConfiguration) { | ||
this(datanodeConfiguration.datanodeDirectories().getDataTargetDir()); | ||
} | ||
|
||
public OpensearchLockCheckController(java.nio.file.Path dataTargetDir) { | ||
this.dataTargetDir = dataTargetDir; | ||
} | ||
|
||
@GET | ||
public OpensearchLockCheckResult checkLockFiles() { | ||
final java.nio.file.Path nodesDir = dataTargetDir.resolve("nodes"); | ||
if (Files.isDirectory(nodesDir)) { | ||
try (final Stream<java.nio.file.Path> nodes = Files.list(nodesDir)) { | ||
return nodes.map(n -> new OpensearchNodeLock(n, isDirLocked(n))) | ||
.collect(Collectors.collectingAndThen(Collectors.toList(), OpensearchLockCheckResult::new)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
return new OpensearchLockCheckResult(Collections.emptyList()); | ||
} | ||
} | ||
|
||
private static boolean isDirLocked(java.nio.file.Path nodeDir) { | ||
final java.nio.file.Path lockFile = nodeDir.resolve("node.lock"); | ||
if (Files.exists(lockFile)) { | ||
try (FileChannel channel = FileChannel.open(lockFile, StandardOpenOption.WRITE)) { | ||
final FileLock fileLock = channel.tryLock(); | ||
if (fileLock != null) { // file was not locked, we are good to go, let's release immediately | ||
fileLock.release(); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} catch (OverlappingFileLockException e) { | ||
return true; | ||
} catch (NonWritableChannelException | IOException e) { | ||
throw new PreflightCheckException("Failed to verify free node.lock file", e); | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
data-node/src/test/java/org/graylog/datanode/rest/OpensearchLockCheckControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.rest; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import org.assertj.core.api.Assertions; | ||
import org.graylog.plugins.views.storage.migration.state.actions.OpensearchLockCheckResult; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.FileLock; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
|
||
class OpensearchLockCheckControllerTest { | ||
@Test | ||
void testNotLockedDir(@TempDir Path tempDir) throws IOException { | ||
final OpensearchLockCheckController controller = new OpensearchLockCheckController(tempDir); | ||
createLockFile(tempDir); | ||
final OpensearchLockCheckResult result = controller.checkLockFiles(); | ||
Assertions.assertThat(result.locks()) | ||
.hasSize(1) | ||
.allSatisfy(l -> Assertions.assertThat(l.locked()).isFalse()); | ||
} | ||
|
||
@Test | ||
void testLockedDir(@TempDir Path tempDir) throws IOException { | ||
final OpensearchLockCheckController controller = new OpensearchLockCheckController(tempDir); | ||
final Path lockFile = createLockFile(tempDir); | ||
lock(lockFile); | ||
final OpensearchLockCheckResult result = controller.checkLockFiles(); | ||
Assertions.assertThat(result.locks()) | ||
.hasSize(1) | ||
.allSatisfy(l -> Assertions.assertThat(l.locked()).isTrue()); | ||
} | ||
|
||
@Test | ||
void testEmptyDir(@TempDir Path tempDir) { | ||
final OpensearchLockCheckController controller = new OpensearchLockCheckController(tempDir); | ||
final OpensearchLockCheckResult result = controller.checkLockFiles(); | ||
Assertions.assertThat(result.locks()) | ||
.isEmpty(); | ||
} | ||
|
||
@Nonnull | ||
private static Path createLockFile(Path tempDir) throws IOException { | ||
final Path nodeDir = tempDir.resolve("nodes").resolve("0"); | ||
Files.createDirectories(nodeDir); | ||
final Path lockFile = nodeDir.resolve("node.lock"); | ||
Files.createFile(lockFile); | ||
return lockFile; | ||
} | ||
|
||
private FileLock lock(Path lockFile) throws IOException { | ||
FileChannel channel = FileChannel.open(lockFile, StandardOpenOption.WRITE); | ||
return channel.lock(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...plugins/views/storage/migration/state/actions/DatanodeOpensearchClusterCheckResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.plugins.views.storage.migration.state.actions; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
|
||
public interface DatanodeOpensearchClusterCheckResource { | ||
|
||
@GET("/lock-check") | ||
Call<OpensearchLockCheckResult> checkLocks(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../org/graylog/plugins/views/storage/migration/state/actions/OpensearchLockCheckResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.plugins.views.storage.migration.state.actions; | ||
|
||
import java.util.Collection; | ||
|
||
public record OpensearchLockCheckResult(Collection<OpensearchNodeLock> locks) { | ||
} |
22 changes: 22 additions & 0 deletions
22
...in/java/org/graylog/plugins/views/storage/migration/state/actions/OpensearchNodeLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.plugins.views.storage.migration.state.actions; | ||
|
||
import java.nio.file.Path; | ||
|
||
public record OpensearchNodeLock(Path path, boolean locked) { | ||
} |
Oops, something went wrong.