This is an automated email from the ASF dual-hosted git repository.

dlmarion 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 29ff11258d Included port number in Monitor ServiceLockData (#4607)
29ff11258d is described below

commit 29ff11258dc173e786a418d053141a25fb3c7f69
Author: Dave Marion <dlmar...@apache.org>
AuthorDate: Tue May 28 10:06:04 2024 -0400

    Included port number in Monitor ServiceLockData (#4607)
    
    Closes #4602
---
 .../java/org/apache/accumulo/monitor/Monitor.java   | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git 
a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java 
b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
index 10ccf19c6c..2740a2049f 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
@@ -474,13 +474,6 @@ public class Monitor extends AbstractServer implements 
HighlyAvailableService {
       log.debug("Monitor started on port {}", livePort);
     }
 
-    try {
-      getMonitorLock();
-    } catch (Exception e) {
-      log.error("Failed to get Monitor ZooKeeper lock");
-      throw new RuntimeException(e);
-    }
-
     String advertiseHost = getHostname();
     if (advertiseHost.equals("0.0.0.0")) {
       try {
@@ -492,6 +485,13 @@ public class Monitor extends AbstractServer implements 
HighlyAvailableService {
     HostAndPort monitorHostAndPort = HostAndPort.fromParts(advertiseHost, 
livePort);
     log.debug("Using {} to advertise monitor location in ZooKeeper", 
monitorHostAndPort);
 
+    try {
+      getMonitorLock(monitorHostAndPort);
+    } catch (Exception e) {
+      log.error("Failed to get Monitor ZooKeeper lock");
+      throw new RuntimeException(e);
+    }
+
     MetricsInfo metricsInfo = getContext().getMetricsInfo();
     metricsInfo.addServiceTags(getApplicationName(), monitorHostAndPort);
     metricsInfo.addMetricsProducers(this);
@@ -796,7 +796,8 @@ public class Monitor extends AbstractServer implements 
HighlyAvailableService {
   /**
    * Get the monitor lock in ZooKeeper
    */
-  private void getMonitorLock() throws KeeperException, InterruptedException {
+  private void getMonitorLock(HostAndPort monitorLocation)
+      throws KeeperException, InterruptedException {
     ServerContext context = getContext();
     final String zRoot = context.getZooKeeperRoot();
     final String monitorPath = zRoot + Constants.ZMONITOR;
@@ -833,8 +834,8 @@ public class Monitor extends AbstractServer implements 
HighlyAvailableService {
     while (true) {
       MoniterLockWatcher monitorLockWatcher = new MoniterLockWatcher();
       monitorLock = new ServiceLock(zoo.getZooKeeper(), monitorLockPath, 
zooLockUUID);
-      monitorLock.lock(monitorLockWatcher,
-          new ServiceLockData(zooLockUUID, getHostname(), ThriftService.NONE));
+      monitorLock.lock(monitorLockWatcher, new ServiceLockData(zooLockUUID,
+          monitorLocation.getHost() + ":" + monitorLocation.getPort(), 
ThriftService.NONE));
 
       monitorLockWatcher.waitForChange();
 

Reply via email to