From e91a9fd2f98e5e6d0bfe646060d313317809ae9d Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 22 Aug 2017 15:27:17 -0700 Subject: [PATCH] HBASE-18658 Purge hokey hbase Service implementation; use (internal) Guava Service instead Removes hbase Service. Moves the single user, ClusterSchemaServiceImpl to use relocated internal Guava Service instead. --- .../main/java/org/apache/hadoop/hbase/Service.java | 50 ---------------------- .../hadoop/hbase/master/ClusterSchemaService.java | 2 +- .../hbase/master/ClusterSchemaServiceImpl.java | 27 ++++++------ .../org/apache/hadoop/hbase/master/HMaster.java | 12 ++++-- 4 files changed, 22 insertions(+), 69 deletions(-) delete mode 100644 hbase-common/src/main/java/org/apache/hadoop/hbase/Service.java diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/Service.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/Service.java deleted file mode 100644 index 97d93cc758..0000000000 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/Service.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.hadoop.hbase; - -import java.io.IOException; - -import org.apache.hadoop.hbase.classification.InterfaceAudience; - -/** - * Simple Service. - */ -// This is a WIP. We have Services throughout hbase. Either have all implement what is here or -// just remove this as an experiment that did not work out. -// TODO: Move on to guava Service after we update our guava version; later guava has nicer -// Service implmentation. -// TODO: Move all Services on to this one Interface. -@InterfaceAudience.Private -public interface Service { - /** - * Initiates service startup (if necessary), returning once the service has finished starting. - * @throws IOException Throws exception if already running and if we fail to start successfully. - */ - void startAndWait() throws IOException; - - /** - * @return True if this Service is running. - */ - boolean isRunning(); - - /** - * Initiates service shutdown (if necessary), returning once the service has finished stopping. - * @throws IOException Throws exception if not running of if we fail to stop successfully. - */ - void stopAndWait() throws IOException; -} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaService.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaService.java index 43353bafc8..9cfbe8c775 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaService.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaService.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.Service; import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.shaded.com.google.common.util.concurrent.Service; /** * Mixes in ClusterSchema and Service diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java index bf3ae7e9bd..2b5c6e9efc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterSchemaServiceImpl.java @@ -33,11 +33,11 @@ import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; import org.apache.hadoop.hbase.master.procedure.ModifyNamespaceProcedure; import org.apache.hadoop.hbase.procedure2.Procedure; import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; +import org.apache.hadoop.hbase.shaded.com.google.common.util.concurrent.AbstractService; import org.apache.hadoop.hbase.util.NonceKey; @InterfaceAudience.Private -class ClusterSchemaServiceImpl implements ClusterSchemaService { - private boolean running = false; +class ClusterSchemaServiceImpl extends AbstractService implements ClusterSchemaService { private final TableNamespaceManager tableNamespaceManager; private final MasterServices masterServices; private final static List EMPTY_NAMESPACE_LIST = @@ -50,28 +50,25 @@ class ClusterSchemaServiceImpl implements ClusterSchemaService { // All below are synchronized so consistent view on whether running or not. - @Override - public synchronized boolean isRunning() { - return this.running; - } private synchronized void checkIsRunning() throws ServiceNotRunningException { if (!isRunning()) throw new ServiceNotRunningException(); } @Override - public synchronized void startAndWait() throws IOException { - if (isRunning()) throw new IllegalStateException("Already running; cannot double-start."); - // Set to running FIRST because tableNamespaceManager start uses this class to do namespace ops - this.running = true; - this.tableNamespaceManager.start(); + public synchronized void doStart() { + try { + this.tableNamespaceManager.start(); + notifyStarted(); + } catch (IOException ioe) { + notifyFailed(ioe); + } } @Override - public synchronized void stopAndWait() throws IOException { - checkIsRunning(); - // You can't stop tableNamespaceManager. - this.running = false; + protected void doStop() { + // This is no stop for the table manager. + notifyStopped(); } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 6b4d4e935d..5a6d29536f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -36,9 +36,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; @@ -1016,8 +1017,13 @@ public class HMaster extends HRegionServer implements MasterServices { void initClusterSchemaService() throws IOException, InterruptedException { this.clusterSchemaService = new ClusterSchemaServiceImpl(this); - this.clusterSchemaService.startAndWait(); - if (!this.clusterSchemaService.isRunning()) throw new HBaseIOException("Failed start"); + this.clusterSchemaService.startAsync(); + try { + this.clusterSchemaService.awaitRunning(getConfiguration().getInt("hbase.wait.on.service.seconds", + 10 * 60), TimeUnit.SECONDS); + } catch (TimeoutException toe) { + throw new IOException("Timedout starting ClusterSchemaService", toe); + } } void initQuotaManager() throws IOException { -- 2.11.0 (Apple Git-81)