Skip to content

Commit

Permalink
Narrow the scope of ZookeeperLockChecker.invalidateCache
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmarion committed Jan 28, 2025
1 parent 7f8f120 commit 2bd5e38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.accumulo.core.clientImpl;

import java.util.List;

import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletServerLockChecker;
import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
Expand Down Expand Up @@ -46,7 +48,14 @@ public boolean isLockHeld(String tserver, String session) {

@Override
public void invalidateCache(String tserver) {
zc.clear(root + "/" + tserver);
String serverPath = root + "/" + tserver;
var tserverZPath = ServiceLock.path(serverPath);
List<String> children =
ServiceLock.validateAndSort(tserverZPath, zc.getChildren(tserverZPath.toString()));
if (!children.isEmpty()) {
String lockNode = children.get(0);
zc.clear(serverPath + "/" + lockNode);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;

import java.util.List;

import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.fate.zookeeper.ZooCache;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -45,9 +47,31 @@ public void setUp() {

@Test
public void testInvalidateCache() {
zc.clear(context.getZooKeeperRoot() + Constants.ZTSERVERS + "/server");
expect(zc.getChildren(context.getZooKeeperRoot() + Constants.ZTSERVERS + "/server"))
.andReturn(List.of("zlock#00000000-0000-0000-0000-aaaaaaaaaaaa#0000000001"));
zc.clear(context.getZooKeeperRoot() + Constants.ZTSERVERS
+ "/server/zlock#00000000-0000-0000-0000-aaaaaaaaaaaa#0000000001");
replay(zc);
zklc.invalidateCache("server");
verify(zc);
}

@Test
public void testInvalidateCacheInvalidLock() {
expect(zc.getChildren(context.getZooKeeperRoot() + Constants.ZTSERVERS + "/server"))
.andReturn(List.of("myLock"));
replay(zc);
zklc.invalidateCache("server");
verify(zc);
}

@Test
public void testInvalidateCacheNoLocks() {
expect(zc.getChildren(context.getZooKeeperRoot() + Constants.ZTSERVERS + "/server"))
.andReturn(List.of(""));
replay(zc);
zklc.invalidateCache("server");
verify(zc);
}

}

0 comments on commit 2bd5e38

Please sign in to comment.