-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HDFS-17049. EC: Fix duplicate block group IDs generated by SequentialBlockGroupIdGenerator. #5743
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,15 @@ | |
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.not; | ||
| import static org.junit.Assert.assertThat; | ||
| import static org.junit.Assert.fail; | ||
| import static org.mockito.Mockito.doAnswer; | ||
| import static org.mockito.Mockito.spy; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -172,6 +176,41 @@ public void testTriggerBlockGroupIdCollision() throws IOException { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that the values generated by blockGroup ID generator are unique, | ||
| * even if they are generated concurrently. | ||
| * @throws Exception | ||
| */ | ||
| @Test | ||
| public void testBlockGroupIdThreadSafety() throws Exception { | ||
| List<List<Long>> blockIds = new ArrayList<>(); | ||
| List<Thread> threads = new ArrayList<>(); | ||
| for (int i = 0; i < 20; i++) { | ||
| blockIds.add(new ArrayList<>()); | ||
| threads.add(new Thread(() -> { | ||
| for (int j = 0; j < 1000; j++) { | ||
| long next = blockGrpIdGenerator.nextValue(); | ||
| blockIds.get(j).add(next); | ||
| } | ||
| })); | ||
| } | ||
| for (Thread t : threads) { | ||
| t.start(); | ||
| } | ||
| for (Thread t : threads) { | ||
| t.join(); | ||
| } | ||
| Set<Long> allBlockIds = new HashSet<>(); | ||
|
Contributor
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. Here will be more readable? Any more simple check way? Such as using
Contributor
Author
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. Sorry I'm not understand how to use |
||
| for (List<Long> set : blockIds) { | ||
| for (long id : set) { | ||
| if (allBlockIds.contains(id)) { | ||
| fail("Same block group id is generated!"); | ||
| } | ||
| allBlockIds.add(id); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test that collisions in the blockGroup ID when the id is occupied by legacy | ||
| * block. | ||
|
|
||
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.
synchronized public long nextValue()->public synchronized long nextValue()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.
Fixed.