You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gobblin.apache.org by ap...@apache.org on 2021/07/23 03:45:08 UTC

[gobblin] branch master updated: [GOBBLIN-1491] Add option to mark up/down D2 servers for gobblin service on leadership change (#3333)

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

aplex pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/gobblin.git


The following commit(s) were added to refs/heads/master by this push:
     new c65e5d0  [GOBBLIN-1491] Add option to mark up/down D2 servers for gobblin service on leadership change (#3333)
c65e5d0 is described below

commit c65e5d05f24eb2f7f643c67abbdf0171939072bc
Author: Jack Moseley <jm...@linkedin.com>
AuthorDate: Thu Jul 22 20:44:57 2021 -0700

    [GOBBLIN-1491] Add option to mark up/down D2 servers for gobblin service on leadership change (#3333)
    
    Currently, D2 servers are started on all hosts at the time of service start. This change will allow using D2 delayed start, then marking up/down the servers when a host becomes the master/slave respectively. This means only the master will be announced to D2, so all requests will be routed to it.
    
    The logic for markup is linkedin specific so must be implemented in internal code.
---
 .../apache/gobblin/service/ServiceConfigKeys.java  |  2 ++
 .../gobblin/service/modules/core/D2Announcer.java  | 34 ++++++++++++++++++++++
 .../modules/core/GobblinServiceConfiguration.java  |  4 +++
 .../modules/core/GobblinServiceGuiceModule.java    |  2 ++
 .../modules/core/GobblinServiceManager.java        | 12 +++++++-
 .../service/modules/core/NoopD2Announcer.java      | 25 ++++++++++++++++
 6 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/gobblin-api/src/main/java/org/apache/gobblin/service/ServiceConfigKeys.java b/gobblin-api/src/main/java/org/apache/gobblin/service/ServiceConfigKeys.java
index 5edc975..0578620 100644
--- a/gobblin-api/src/main/java/org/apache/gobblin/service/ServiceConfigKeys.java
+++ b/gobblin-api/src/main/java/org/apache/gobblin/service/ServiceConfigKeys.java
@@ -35,6 +35,8 @@ public class ServiceConfigKeys {
   public static final String GOBBLIN_SERVICE_GIT_CONFIG_MONITOR_ENABLED_KEY = GOBBLIN_SERVICE_PREFIX + "gitConfigMonitor.enabled";
   public static final String GOBBLIN_SERVICE_DAG_MANAGER_ENABLED_KEY = GOBBLIN_SERVICE_PREFIX + "dagManager.enabled";
   public static final String GOBBLIN_SERVICE_JOB_STATUS_MONITOR_ENABLED_KEY = GOBBLIN_SERVICE_PREFIX + "jobStatusMonitor.enabled";
+  // If true, will mark up/down d2 servers on leadership so that all requests will be routed to the leader node
+  public static final String GOBBLIN_SERVICE_D2_ONLY_ANNOUNCE_LEADER = GOBBLIN_SERVICE_PREFIX + "d2.onlyAnnounceLeader";
 
   // Helix / ServiceScheduler Keys
   public static final String HELIX_CLUSTER_NAME_KEY = GOBBLIN_SERVICE_PREFIX + "helix.cluster.name";
diff --git a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/D2Announcer.java b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/D2Announcer.java
new file mode 100644
index 0000000..4f8f3e3
--- /dev/null
+++ b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/D2Announcer.java
@@ -0,0 +1,34 @@
+/*
+ * 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
+ *
+ *    http://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.gobblin.service.modules.core;
+
+
+/**
+ * Interface for marking up/down D2 servers on gobblin service startup. This is only required if using delayed announcement.
+ */
+public interface D2Announcer {
+  /**
+   * Mark up this host's D2 server
+   */
+  void markUpServer();
+
+  /**
+   * Mark down this host's D2 server
+   */
+  void markDownServer();
+}
diff --git a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceConfiguration.java b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceConfiguration.java
index 0326dd7..9553715 100644
--- a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceConfiguration.java
+++ b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceConfiguration.java
@@ -71,6 +71,9 @@ public class GobblinServiceConfiguration {
   private final boolean flowCatalogLocalCommit;
 
   @Getter
+  private final boolean onlyAnnounceLeader;
+
+  @Getter
   private final Config innerConfig;
 
   @Getter
@@ -111,5 +114,6 @@ public class GobblinServiceConfiguration {
         ConfigUtils.getBoolean(config, ServiceConfigKeys.GOBBLIN_SERVICE_RESTLI_SERVER_ENABLED_KEY, true);
     this.isTopologySpecFactoryEnabled =
         ConfigUtils.getBoolean(config, ServiceConfigKeys.GOBBLIN_SERVICE_TOPOLOGY_SPEC_FACTORY_ENABLED_KEY, true);
+    this.onlyAnnounceLeader = ConfigUtils.getBoolean(config, ServiceConfigKeys.GOBBLIN_SERVICE_D2_ONLY_ANNOUNCE_LEADER, false);
   }
 }
diff --git a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceGuiceModule.java b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceGuiceModule.java
index 91aeb64..21db6d7 100644
--- a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceGuiceModule.java
+++ b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceGuiceModule.java
@@ -214,6 +214,8 @@ public class GobblinServiceGuiceModule implements Module {
 
     binder.bind(JobIssueEventHandler.class);
 
+    binder.bind(D2Announcer.class).to(NoopD2Announcer.class);
+
     LOGGER.info("Bindings configured");
   }
 
diff --git a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java
index 9818ef5..8c2a49c 100644
--- a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java
+++ b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceManager.java
@@ -191,6 +191,8 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
 
   protected Optional<HelixLeaderState> helixLeaderGauges;
 
+  @Inject(optional = true)
+  protected D2Announcer d2Announcer;
 
   private final MetricContext metricContext;
   private final Metrics metrics;
@@ -272,7 +274,7 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
    * Handle leadership change.
    * @param changeContext notification context
    */
-  private void  handleLeadershipChange(NotificationContext changeContext) {
+  private void handleLeadershipChange(NotificationContext changeContext) {
     if (this.helixManager.isPresent() && this.helixManager.get().isLeader()) {
       LOGGER.info("Leader notification for {} HM.isLeader {}", this.helixManager.get().getInstanceName(),
           this.helixManager.get().isLeader());
@@ -297,6 +299,10 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
           this.eventBus.register(this.dagManager);
         }
       }
+
+      if (configuration.isOnlyAnnounceLeader()) {
+        this.d2Announcer.markUpServer();
+      }
     } else if (this.helixManager.isPresent()) {
       LOGGER.info("Leader lost notification for {} HM.isLeader {}", this.helixManager.get().getInstanceName(),
           this.helixManager.get().isLeader());
@@ -318,6 +324,10 @@ public class GobblinServiceManager implements ApplicationLauncher, StandardMetri
         this.dagManager.setActive(false);
         this.eventBus.unregister(this.dagManager);
       }
+
+      if (configuration.isOnlyAnnounceLeader()) {
+        this.d2Announcer.markDownServer();
+      }
     }
   }
 
diff --git a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/NoopD2Announcer.java b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/NoopD2Announcer.java
new file mode 100644
index 0000000..4bd889d
--- /dev/null
+++ b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/NoopD2Announcer.java
@@ -0,0 +1,25 @@
+/*
+ * 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
+ *
+ *    http://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.gobblin.service.modules.core;
+
+
+public class NoopD2Announcer implements D2Announcer {
+  public void markUpServer() {}
+
+  public void markDownServer() {}
+}