-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
KAFKA-6647 KafkaStreams.cleanUp creates .lock file in directory it tries to clean #4702
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4933768
KAFKA-6647 KafkaStreams.cleanUp creates .lock file in directory it tr…
tedyu 5c8f746
Put lock file above task dir
tedyu 587517e
Address checkstyle error
tedyu e7a5e47
Modify StateDirectoryTest
tedyu 9e96cf4
Modify StateDirectoryTest
tedyu 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 |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.channels.FileLock; | ||
import java.nio.channels.OverlappingFileLockException; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Arrays; | ||
|
@@ -88,27 +89,6 @@ public void shouldCreateTaskStateDirectory() { | |
assertTrue(taskDirectory.isDirectory()); | ||
} | ||
|
||
@Test | ||
public void shouldLockTaskStateDirectory() throws IOException { | ||
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. Why did you remove this test? 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. directory.lock(taskId) is at different level than channel.tryLock() , rendering the test useless. |
||
final TaskId taskId = new TaskId(0, 0); | ||
final File taskDirectory = directory.directoryForTask(taskId); | ||
|
||
directory.lock(taskId); | ||
|
||
try ( | ||
final FileChannel channel = FileChannel.open( | ||
new File(taskDirectory, StateDirectory.LOCK_FILE_NAME).toPath(), | ||
StandardOpenOption.CREATE, StandardOpenOption.WRITE) | ||
) { | ||
channel.tryLock(); | ||
fail("shouldn't be able to lock already locked directory"); | ||
} catch (final OverlappingFileLockException e) { | ||
// pass | ||
} finally { | ||
directory.unlock(taskId); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldBeTrueIfAlreadyHoldsLock() throws IOException { | ||
final TaskId taskId = new TaskId(0, 0); | ||
|
@@ -140,17 +120,18 @@ public void shouldNotLockDeletedDirectory() throws IOException { | |
@Test | ||
public void shouldLockMulitpleTaskDirectories() throws IOException { | ||
final TaskId taskId = new TaskId(0, 0); | ||
final File task1Dir = directory.directoryForTask(taskId); | ||
final File task1Dir = directory.stateDir(); | ||
final TaskId taskId2 = new TaskId(1, 0); | ||
final File task2Dir = directory.directoryForTask(taskId2); | ||
final File task2Dir = directory.stateDir(); | ||
|
||
|
||
try ( | ||
final FileChannel channel1 = FileChannel.open( | ||
new File(task1Dir, StateDirectory.LOCK_FILE_NAME).toPath(), | ||
new File(task1Dir, taskId + StateDirectory.LOCK_FILE_NAME).toPath(), | ||
StandardOpenOption.CREATE, | ||
StandardOpenOption.WRITE); | ||
final FileChannel channel2 = FileChannel.open(new File(task2Dir, StateDirectory.LOCK_FILE_NAME).toPath(), | ||
final FileChannel channel2 = FileChannel.open( | ||
new File(task2Dir, taskId2 + StateDirectory.LOCK_FILE_NAME).toPath(), | ||
StandardOpenOption.CREATE, | ||
StandardOpenOption.WRITE) | ||
) { | ||
|
@@ -196,15 +177,14 @@ public void shouldCleanUpTaskStateDirectoriesThatAreNotCurrentlyLocked() throws | |
directory.directoryForTask(new TaskId(2, 0)); | ||
|
||
List<File> files = Arrays.asList(appDir.listFiles()); | ||
assertEquals(3, files.size()); | ||
assertEquals(1, files.size()); | ||
|
||
time.sleep(1000); | ||
directory.cleanRemovedTasks(0); | ||
|
||
files = Arrays.asList(appDir.listFiles()); | ||
assertEquals(2, files.size()); | ||
assertTrue(files.contains(new File(appDir, task0.toString()))); | ||
assertTrue(files.contains(new File(appDir, task1.toString()))); | ||
files = Arrays.asList(directory.stateDir().listFiles()); | ||
// lock files have been cleaned | ||
assertEquals(0, files.size()); | ||
} finally { | ||
directory.unlock(task0); | ||
directory.unlock(task1); | ||
|
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.
why remove the
directoryForTask
method?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.
The location of the lock file is lifted one level up.
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.
After discussion on #4713 I think this idea should actually work. Nit: Can we rename the lock to
LOCK_FILE_NAME + " -" + taskId
though.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.
I can rename the lock if people think we can continue with this solution.