You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by do...@apache.org on 2019/02/19 14:18:34 UTC

[incubator-iotdb] branch fix_jdbc_service_start_up_error updated: fix a bug

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

dope pushed a commit to branch fix_jdbc_service_start_up_error
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/fix_jdbc_service_start_up_error by this push:
     new f558af9  fix a bug
f558af9 is described below

commit f558af922d8d3d971d32a103d2ad6052bef5b7d6
Author: xuyi556677@163.com <xu...@163.com>
AuthorDate: Tue Feb 19 22:18:13 2019 +0800

    fix a bug
---
 .../org/apache/iotdb/db/service/JDBCService.java   | 41 +++++++++++++---------
 .../iotdb/db/service/JDBCServiceEventHandler.java  |  8 ++---
 2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java b/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
index 5cf8a66..c7e8cd5 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
@@ -55,7 +55,8 @@ public class JDBCService implements JDBCServiceMBean, IService {
   private Processor<TSIService.Iface> processor;
   private TThreadPoolServer.Args poolArgs;
   private TSServiceImpl impl;
-  private CountDownLatch countDownLatch;
+  private CountDownLatch startLatch;
+  private CountDownLatch stopLatch;
 
   private JDBCService() {
   }
@@ -66,11 +67,11 @@ public class JDBCService implements JDBCServiceMBean, IService {
 
   @Override
   public String getJDBCServiceStatus() {
-    if(countDownLatch == null || countDownLatch.getCount() == 0){
+	if(startLatch != null && startLatch.getCount() == 0) {
+	  return STATUS_UP;
+	} else {
       return STATUS_DOWN;
-    } else{
-      return STATUS_UP;
-    }
+	}
   }
 
   @Override
@@ -110,11 +111,12 @@ public class JDBCService implements JDBCServiceMBean, IService {
     }
     LOGGER.info("{}: start {}...", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName());
     try {
-      countDownLatch = new CountDownLatch(0);
-      jdbcServiceThread = new JDBCServiceThread(countDownLatch);
+      reset();
+      jdbcServiceThread = new JDBCServiceThread(startLatch, stopLatch);
       jdbcServiceThread.setName(ThreadName.JDBC_SERVICE.getName());
       jdbcServiceThread.start();
-    } catch (IOException e) {
+      startLatch.await();
+    } catch (IOException | InterruptedException e) {
       String errorMessage = String
           .format("Failed to start %s because of %s", this.getID().getName(),
               e.getMessage());
@@ -125,6 +127,11 @@ public class JDBCService implements JDBCServiceMBean, IService {
     LOGGER.info("{}: start {} successfully, listening on port {}", IoTDBConstant.GLOBAL_DB_NAME,
         this.getID().getName(), IoTDBDescriptor.getInstance().getConfig().rpcPort);
   }
+  
+  private void reset() {
+    startLatch = new CountDownLatch(1);
+    stopLatch = new CountDownLatch(1);	  
+  }
 
   @Override
   public synchronized void restartService() throws StartupException {
@@ -143,7 +150,8 @@ public class JDBCService implements JDBCServiceMBean, IService {
       ((JDBCServiceThread) jdbcServiceThread).close();
     }
     try {
-      countDownLatch.await();
+      stopLatch.await();
+      reset();
       LOGGER.info("{}: close {} successfully", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName());
     } catch (InterruptedException e) {
       LOGGER.error("{}: close {} failed because {}", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName(), e);
@@ -162,13 +170,15 @@ public class JDBCService implements JDBCServiceMBean, IService {
 
     private TServerSocket serverTransport;
     private TServer poolServer;
-    private CountDownLatch latch;
+    private CountDownLatch threadStartLatch;
+    private CountDownLatch threadStopLatch;
 
-    public JDBCServiceThread(CountDownLatch latch) throws IOException {
+    public JDBCServiceThread(CountDownLatch threadStartLatch, CountDownLatch threadStopLatch) throws IOException {
       protocolFactory = new TBinaryProtocol.Factory();
       impl = new TSServiceImpl();
       processor = new TSIService.Processor<>(impl);
-      this.latch = latch;
+      this.threadStartLatch = threadStartLatch;
+      this.threadStopLatch = threadStopLatch;
     }
 
     @Override
@@ -181,7 +191,7 @@ public class JDBCService implements JDBCServiceMBean, IService {
         poolArgs.processor(processor);
         poolArgs.protocolFactory(protocolFactory);
         poolServer = new TThreadPoolServer(poolArgs);
-        poolServer.setServerEventHandler(new JDBCServiceEventHandler(impl, latch));
+        poolServer.setServerEventHandler(new JDBCServiceEventHandler(impl, threadStartLatch));
         poolServer.serve();
       } catch (TTransportException e) {
         LOGGER.error("{}: failed to start {}, because ", IoTDBConstant.GLOBAL_DB_NAME,
@@ -201,13 +211,12 @@ public class JDBCService implements JDBCServiceMBean, IService {
         poolServer.stop();
         poolServer = null;
       }
-
       if (serverTransport != null) {
         serverTransport.close();
         serverTransport = null;
       }
-      if(latch.getCount() == 1) {
-    	latch.countDown();
+      if (threadStopLatch.getCount() == 1) {
+    	threadStopLatch.countDown();
       }
     }
   }
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java b/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
index a737302..b39632f 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
@@ -32,11 +32,11 @@ public class JDBCServiceEventHandler implements TServerEventHandler {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(JDBCServiceEventHandler.class);
   private TSServiceImpl serviceImpl;
-  CountDownLatch latch;
+  CountDownLatch startLatch;
 
-  public JDBCServiceEventHandler(TSServiceImpl serviceImpl, CountDownLatch latch) {
+  public JDBCServiceEventHandler(TSServiceImpl serviceImpl, CountDownLatch startLatch) {
     this.serviceImpl = serviceImpl;
-    this.latch = latch;
+    this.startLatch = startLatch;
   }
 
   @Override
@@ -56,7 +56,7 @@ public class JDBCServiceEventHandler implements TServerEventHandler {
 
   @Override
   public void preServe() {
-    this.latch = new CountDownLatch(1);
+    this.startLatch.countDown();
   }
 
   @Override