-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
speeds up fate lock acquisition (#5262)
Stores the lock data for fate locks in the zookeeper node name instead of the zookeeper data for the node. Ran some local performance test with hundreds of fate operations and saw lock times go from 750ms to 15ms. fixes #5181 Co-authored-by: Christopher Tubbs <[email protected]>
1 parent
e37cae1
commit 3213646
Showing
7 changed files
with
284 additions
and
117 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
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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
/* | ||
* 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 static org.junit.jupiter.api.Assertions.fail; | ||
|
||
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 | ||
String lockData = "WRITE:" + fateId.canonical(); | ||
var lockNode = | ||
new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + String.format("%010d", 40)); | ||
assertEquals(40, lockNode.sequence); | ||
assertEquals(lockData, lockNode.fateLockEntry.get().serialize()); | ||
|
||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(lockData + "#" + String.format("%010d", 40))); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + String.format("%d", 40))); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + String.format("%09d", 40))); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + String.format("%011d", 40))); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#abc")); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + 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}) { | ||
var seq = String.format("%010d", i); | ||
if (seq.length() == 10) { | ||
assertThrows(NumberFormatException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + seq)); | ||
} else if (seq.length() == 11) { | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + seq)); | ||
} else { | ||
fail("Unexpected length " + seq.length()); | ||
} | ||
} | ||
|
||
// Test a negative number that is not formatted w/ %010d | ||
assertThrows(IllegalArgumentException.class, | ||
() -> new FateLock.NodeName(FateLock.PREFIX + lockData + "#" + String.format("%d", -40))); | ||
} | ||
} |
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