-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove node from cluster when node locks broken #61400
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9478e2b
Remove node from cluster when node locks are broken.
amoghRZP 3ce8839
Merge remote-tracking branch 'origin/master' into broken_nl_handling
amoghRZP eeb51ba
changes as per suggested in review comments
amoghRZP c43b6fb
Keeping one test for broken node locks in FsHealthServiceTests
amoghRZP 841a8b1
Merge branch 'master' into broken_nl_handling
amoghRZP 4a207fb
Changes error message being logged and clearing boolean flag at the e…
amoghRZP 9caac47
Merge branch 'master' into broken_nl_handling
elasticmachine fd9d292
Merge remote-tracking branch 'upstream/master' into broken_nl_handling
amoghRZP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -42,8 +42,8 @@ | |
import java.io.OutputStream; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.OpenOption; | ||
import java.nio.file.Path; | ||
import java.nio.file.OpenOption; | ||
import java.nio.file.attribute.FileAttribute; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
@@ -231,6 +231,36 @@ public void testFailsHealthOnSinglePathWriteFailure() throws IOException { | |
} | ||
} | ||
|
||
public void testFailsHealthOnUnexpectedLockFileSize() throws IOException { | ||
FileSystem fileSystem = PathUtils.getDefaultFileSystem(); | ||
final Settings settings = Settings.EMPTY; | ||
TestThreadPool testThreadPool = new TestThreadPool(getClass().getName(), settings); | ||
FileSystemUnexpectedLockFileSizeProvider unexpectedLockFileSizeFileSystemProvider = new FileSystemUnexpectedLockFileSizeProvider( | ||
fileSystem, 1, testThreadPool); | ||
fileSystem = unexpectedLockFileSizeFileSystemProvider.getFileSystem(null); | ||
PathUtilsForTesting.installMock(fileSystem); | ||
final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); | ||
try (NodeEnvironment env = newNodeEnvironment()) { | ||
FsHealthService fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env); | ||
fsHealthService.new FsHealthMonitor().run(); | ||
assertEquals(HEALTHY, fsHealthService.getHealth().getStatus()); | ||
assertEquals("health check passed", fsHealthService.getHealth().getInfo()); | ||
|
||
// enabling unexpected file size injection | ||
unexpectedLockFileSizeFileSystemProvider.injectUnexpectedFileSize.set(true); | ||
|
||
fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env); | ||
fsHealthService.new FsHealthMonitor().run(); | ||
assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus()); | ||
assertThat(fsHealthService.getHealth().getInfo(), is("health check failed due to broken node lock")); | ||
assertEquals(1, unexpectedLockFileSizeFileSystemProvider.getInjectedPathCount()); | ||
} finally { | ||
unexpectedLockFileSizeFileSystemProvider.injectUnexpectedFileSize.set(false); | ||
PathUtilsForTesting.teardown(); | ||
ThreadPool.terminate(testThreadPool, 500, TimeUnit.MILLISECONDS); | ||
} | ||
} | ||
|
||
private static class FileSystemIOExceptionProvider extends FilterFileSystemProvider { | ||
|
||
AtomicBoolean injectIOException = new AtomicBoolean(); | ||
|
@@ -254,7 +284,8 @@ public int getInjectedPathCount(){ | |
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException { | ||
if (injectIOException.get()){ | ||
assert pathPrefix != null : "must set pathPrefix before starting disruptions"; | ||
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) { | ||
if (path.toString().startsWith(pathPrefix) && path.toString(). | ||
endsWith(FsHealthService.FsHealthMonitor.TEMP_FILE_NAME)) { | ||
injectedPaths.incrementAndGet(); | ||
throw new IOException("fake IOException"); | ||
} | ||
|
@@ -289,7 +320,8 @@ public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, | |
public void force(boolean metaData) throws IOException { | ||
if (injectIOException.get()) { | ||
assert pathPrefix != null : "must set pathPrefix before starting disruptions"; | ||
if (path.toString().startsWith(pathPrefix) && path.toString().endsWith(".es_temp_file")) { | ||
if (path.toString().startsWith(pathPrefix) && path.toString(). | ||
endsWith(FsHealthService.FsHealthMonitor.TEMP_FILE_NAME)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
injectedPaths.incrementAndGet(); | ||
throw new IOException("fake IOException"); | ||
} | ||
|
@@ -341,4 +373,39 @@ public void force(boolean metaData) throws IOException { | |
}; | ||
} | ||
} | ||
|
||
private static class FileSystemUnexpectedLockFileSizeProvider extends FilterFileSystemProvider { | ||
|
||
AtomicBoolean injectUnexpectedFileSize = new AtomicBoolean(); | ||
AtomicInteger injectedPaths = new AtomicInteger(); | ||
|
||
private final long size; | ||
private final ThreadPool threadPool; | ||
|
||
FileSystemUnexpectedLockFileSizeProvider(FileSystem inner, long size, ThreadPool threadPool) { | ||
super("disrupt_fs_health://", inner); | ||
this.size = size; | ||
this.threadPool = threadPool; | ||
} | ||
|
||
public int getInjectedPathCount(){ | ||
return injectedPaths.get(); | ||
} | ||
|
||
@Override | ||
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { | ||
return new FilterFileChannel(super.newFileChannel(path, options, attrs)) { | ||
@Override | ||
public long size() throws IOException { | ||
if (injectUnexpectedFileSize.get()) { | ||
if (path.getFileName().toString().equals(NodeEnvironment.NODE_LOCK_FILENAME)) { | ||
injectedPaths.incrementAndGet(); | ||
return size; | ||
} | ||
} | ||
return super.size(); | ||
} | ||
}; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍