-
Notifications
You must be signed in to change notification settings - Fork 453
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
speeds up fate lock acquisition #5262
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
20fbbe8
speeds up fate lock acquisition
keith-turner 20097d5
Update core/src/main/java/org/apache/accumulo/core/fate/zookeeper/Fat…
keith-turner a45b3ad
Update core/src/main/java/org/apache/accumulo/core/fate/zookeeper/Dis…
keith-turner 3fbdd6e
format code
keith-turner 3f25ce0
code review update
keith-turner 95fb8dc
remove TODO
keith-turner 2309b9b
code review update
keith-turner ac9a6b5
improve test
keith-turner 1d4d7f2
use variable
keith-turner 43651d3
Merge branch 'main' into accumulo-5181
keith-turner 1c08a34
follow on changes after merge
keith-turner 33e9bf6
move comment
keith-turner 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
65 changes: 65 additions & 0 deletions
65
core/src/test/java/org/apache/accumulo/core/fate/zookeeper/FateLockTest.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,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.accumulo.core.fate.zookeeper; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.UUID; | ||
|
||
import org.apache.accumulo.core.fate.FateId; | ||
import org.apache.accumulo.core.fate.FateInstanceType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class FateLockTest { | ||
|
||
@Test | ||
public void testParsing() { | ||
var fateId = FateId.from(FateInstanceType.USER, UUID.randomUUID()); | ||
// ZooKeeper docs state that sequence numbers are formatted using %010d | ||
var lockNode = new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + "#" + String.format("%010d", 40)); | ||
assertEquals(40, lockNode.sequence); | ||
assertEquals(fateId.canonical(), lockNode.lockData); | ||
|
||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.FateLockNode(fateId.canonical() + "#" + String.format("%010d", 40))); | ||
assertThrows(IllegalArgumentException.class, () -> new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + "#" + String.format("%d", 40))); | ||
assertThrows(IllegalArgumentException.class, () -> new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + "#" + String.format("%09d", 40))); | ||
assertThrows(IllegalArgumentException.class, () -> new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + "#" + String.format("%011d", 40))); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.FateLockNode(FateLock.PREFIX + fateId.canonical() + "#abc")); | ||
assertThrows(IllegalArgumentException.class, () -> new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + String.format("%010d", 40))); | ||
|
||
// ZooKeeper docs state that sequence numbers can roll and become negative. The FateLock code | ||
// does not support this, so make sure it fails if this happens. | ||
for (int i : new int[] {Integer.MIN_VALUE, Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 10, | ||
Integer.MIN_VALUE / 1000, -40}) { | ||
assertThrows(IllegalArgumentException.class, () -> new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + "#" + String.format("%010d", i))); | ||
} | ||
|
||
assertThrows(IllegalArgumentException.class, () -> new FateLock.FateLockNode( | ||
FateLock.PREFIX + fateId.canonical() + "#" + String.format("%d", -40))); | ||
} | ||
} |
Oops, something went wrong.
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.
In the case of an overflow, the character at (len - 11) be a minus sign and cause this to fail.
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.
It depends on the number of digits in the negative number. If its a 10 digit negative number then
%010d
will produce a 11 char string. If its 9 digits or less then%010d
will produce a 10 char string including the negative. For the 9 digit or less case the#
check will not catch negative, but the laterLong.parseUnsignedLong
call will catch it.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.
For the case Long.parseUnsignedLong catches the problem it throws a more specific exception, I updated the test to check for that.