drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject [3/4] drill git commit: DRILL-4523: Disallow using loopback address in distributed mode
Date Thu, 07 Apr 2016 01:07:15 GMT
DRILL-4523: Disallow using loopback address in distributed mode

closes #445


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/9514cbe7
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/9514cbe7
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/9514cbe7

Branch: refs/heads/master
Commit: 9514cbe7574a5bfce40bf8fe982faf2aef48bc0e
Parents: a759552
Author: Arina Ielchiieva <arina.yelchiyeva@gmail.com>
Authored: Thu Mar 24 16:46:06 2016 +0000
Committer: Sudheesh Katkam <skatkam@maprtech.com>
Committed: Wed Apr 6 16:57:40 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/drill/exec/server/Drillbit.java    |  9 ++++++---
 .../org/apache/drill/exec/service/ServiceEngine.java   | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/9514cbe7/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
index 441fa91..d981342 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java
@@ -86,18 +86,21 @@ public class Drillbit implements AutoCloseable {
     final boolean allowPortHunting = serviceSet != null;
     context = new BootStrapContext(config, classpathScan);
     manager = new WorkManager(context);
-    engine = new ServiceEngine(manager.getControlMessageHandler(), manager.getUserWorker(),
context,
-        manager.getWorkBus(), manager.getBee(), allowPortHunting);
 
     webServer = new WebServer(config, context.getMetrics(), manager);
-
+    boolean isDistributedMode = false;
     if (serviceSet != null) {
       coord = serviceSet.getCoordinator();
       storeProvider = new CachingPersistentStoreProvider(new LocalPersistentStoreProvider(config));
     } else {
       coord = new ZKClusterCoordinator(config);
       storeProvider = new PersistentStoreRegistry(this.coord, config).newPStoreProvider();
+      isDistributedMode = true;
     }
+
+    engine = new ServiceEngine(manager.getControlMessageHandler(), manager.getUserWorker(),
context,
+        manager.getWorkBus(), manager.getBee(), allowPortHunting, isDistributedMode);
+
     logger.info("Construction completed ({} ms).", w.elapsed(TimeUnit.MILLISECONDS));
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/9514cbe7/exec/java-exec/src/main/java/org/apache/drill/exec/service/ServiceEngine.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/service/ServiceEngine.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/service/ServiceEngine.java
index 169e26e..17edbc2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/service/ServiceEngine.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/service/ServiceEngine.java
@@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.drill.common.AutoCloseables;
 import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.exec.ExecConstants;
@@ -59,13 +60,14 @@ public class ServiceEngine implements AutoCloseable {
   private final DrillConfig config;
   boolean useIP = false;
   private final boolean allowPortHunting;
+  private final boolean isDistributedMode;
   private final BufferAllocator userAllocator;
   private final BufferAllocator controlAllocator;
   private final BufferAllocator dataAllocator;
 
 
   public ServiceEngine(ControlMessageHandler controlMessageHandler, UserWorker userWorker,
BootStrapContext context,
-      WorkEventBus workBus, WorkerBee bee, boolean allowPortHunting) throws DrillbitStartupException
{
+      WorkEventBus workBus, WorkerBee bee, boolean allowPortHunting, boolean isDistributedMode)
throws DrillbitStartupException {
     userAllocator = newAllocator(context, "rpc:user", "drill.exec.rpc.user.server.memory.reservation",
         "drill.exec.rpc.user.server.memory.maximum");
     controlAllocator = newAllocator(context, "rpc:bit-control",
@@ -85,6 +87,7 @@ public class ServiceEngine implements AutoCloseable {
     this.dataPool = new DataConnectionCreator(context, dataAllocator, workBus, bee, allowPortHunting);
     this.config = context.getConfig();
     this.allowPortHunting = allowPortHunting;
+    this.isDistributedMode = isDistributedMode;
     registerMetrics(context.getMetrics());
 
   }
@@ -141,6 +144,8 @@ public class ServiceEngine implements AutoCloseable {
   public DrillbitEndpoint start() throws DrillbitStartupException, UnknownHostException{
     int userPort = userServer.bind(config.getInt(ExecConstants.INITIAL_USER_PORT), allowPortHunting);
     String address = useIP ?  InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getCanonicalHostName();
+    checkLoopbackAddress(address);
+
     DrillbitEndpoint partialEndpoint = DrillbitEndpoint.newBuilder()
         .setAddress(address)
         //.setAddress("localhost")
@@ -177,6 +182,12 @@ public class ServiceEngine implements AutoCloseable {
     });
   }
 
+  private void checkLoopbackAddress(String address) throws DrillbitStartupException, UnknownHostException
{
+    if (isDistributedMode && InetAddress.getByName(address).isLoopbackAddress())
{
+      throw new DrillbitStartupException("Drillbit is disallowed to bind to loopback address
in distributed mode.");
+    }
+  }
+
   @Override
   public void close() throws Exception {
     // this takes time so close them in parallel


Mime
View raw message