This is an automated email from the ASF dual-hosted git repository.
kturner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new 496b8a2613 added unit test for TGW code to find servers (#5885)
496b8a2613 is described below
commit 496b8a26130da425010eff7ebac67e478e3b7626
Author: Keith Turner <[email protected]>
AuthorDate: Tue Sep 16 10:56:15 2025 -0400
added unit test for TGW code to find servers (#5885)
TGW has code for finding servers that would break if TServerInstance
ever changes its compare to method. Refactored code to make it testable
and added unit test that should detect any changes in the compareto
method.
---
.../accumulo/manager/TabletGroupWatcher.java | 25 ++++++----
.../accumulo/manager/TabletGroupWatcherTest.java | 55 ++++++++++++++++++++++
2 files changed, 71 insertions(+), 9 deletions(-)
diff --git
a/server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java
b/server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java
index 975ac8f245..29eb475c8e 100644
---
a/server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java
+++
b/server/manager/src/main/java/org/apache/accumulo/manager/TabletGroupWatcher.java
@@ -107,6 +107,7 @@ import org.slf4j.event.Level;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
+import com.google.common.net.HostAndPort;
abstract class TabletGroupWatcher extends AccumuloDaemonThread {
@@ -853,20 +854,26 @@ abstract class TabletGroupWatcher extends
AccumuloDaemonThread {
}
}
+ static TServerInstance
findServerIgnoringSession(SortedMap<TServerInstance,?> servers,
+ HostAndPort server) {
+ var tail = servers.tailMap(new TServerInstance(server,
0L)).keySet().iterator();
+ if (tail.hasNext()) {
+ TServerInstance found = tail.next();
+ if (found.getHostAndPort().equals(server)) {
+ return found;
+ }
+ }
+
+ return null;
+ }
+
private void hostSuspendedTablet(TabletLists tLists, TabletMetadata tm,
Location location,
TableConfiguration tableConf) {
if
(manager.getSteadyTime().minus(tm.getSuspend().suspensionTime).toMillis()
< tableConf.getTimeInMillis(Property.TABLE_SUSPEND_DURATION)) {
// Tablet is suspended. See if its tablet server is back.
- TServerInstance returnInstance = null;
- Iterator<TServerInstance> find = tLists.destinations
- .tailMap(new TServerInstance(tm.getSuspend().server, "
")).keySet().iterator();
- if (find.hasNext()) {
- TServerInstance found = find.next();
- if (found.getHostAndPort().equals(tm.getSuspend().server)) {
- returnInstance = found;
- }
- }
+ TServerInstance returnInstance =
+ findServerIgnoringSession(tLists.destinations,
tm.getSuspend().server);
// Old tablet server is back. Return this tablet to its previous owner.
if (returnInstance != null) {
diff --git
a/server/manager/src/test/java/org/apache/accumulo/manager/TabletGroupWatcherTest.java
b/server/manager/src/test/java/org/apache/accumulo/manager/TabletGroupWatcherTest.java
new file mode 100644
index 0000000000..dd4aef9e51
--- /dev/null
+++
b/server/manager/src/test/java/org/apache/accumulo/manager/TabletGroupWatcherTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.manager;
+
+import static
org.apache.accumulo.manager.TabletGroupWatcher.findServerIgnoringSession;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.metadata.TServerInstance;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.net.HostAndPort;
+
+public class TabletGroupWatcherTest {
+ @Test
+ public void testFindingServer() {
+ TreeMap<TServerInstance,String> servers = new TreeMap<>();
+
+ servers.put(new TServerInstance("192.168.1.2:9997", 50L), "tserver1");
+ // add an entry where only the session differs. For this case the code
does not really care
+ // which one is found, the impl happens to find the first one. This
situation could happen
+ // temporarily, and it should not cause any problems.
+ servers.put(new TServerInstance("192.168.1.2:9997", 70L), "tserver2");
+ servers.put(new TServerInstance("192.168.1.4:9997", -90L), "tserver3");
+
+ assertNull(findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.1:9997")));
+ assertNull(findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.2:9996")));
+ assertNull(findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.2:9998")));
+ assertNull(findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.3:9997")));
+ assertNull(findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.5:9997")));
+
+ assertEquals(new TServerInstance("192.168.1.2:9997", 50L),
+ findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.2:9997")));
+ assertEquals(new TServerInstance("192.168.1.4:9997", -90L),
+ findServerIgnoringSession(servers,
HostAndPort.fromString("192.168.1.4:9997")));
+ }
+}