From 4ad49bc3ac86708144d126ea0a4cbfa68f226834 Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Tue, 17 Jan 2017 14:41:45 -0500 Subject: [PATCH] HBASE-17478 Avoid reporting FS use when quotas are disabled Also, gracefully produce responses when quotas are disabled. --- .../hbase/master/MasterRpcServices.java | 4 ++ .../hbase/quotas/MasterQuotaManager.java | 13 ++++++- .../hbase/regionserver/HRegionServer.java | 5 ++- .../hbase/quotas/TestMasterQuotaManager.java | 37 +++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotaManager.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java index db48bdb050a..be782df3d86 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java @@ -59,6 +59,7 @@ import org.apache.hadoop.hbase.procedure.MasterProcedureManager; import org.apache.hadoop.hbase.procedure2.LockInfo; import org.apache.hadoop.hbase.procedure2.Procedure; import org.apache.hadoop.hbase.quotas.MasterQuotaManager; +import org.apache.hadoop.hbase.quotas.QuotaUtil; import org.apache.hadoop.hbase.regionserver.RSRpcServices; import org.apache.hadoop.hbase.replication.ReplicationException; import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; @@ -1911,6 +1912,9 @@ public class MasterRpcServices extends RSRpcServices RegionSpaceUseReportRequest request) throws ServiceException { try { master.checkInitialized(); + if (!QuotaUtil.isQuotaEnabled(master.getConfiguration())) { + return RegionSpaceUseReportResponse.newBuilder().build(); + } MasterQuotaManager quotaManager = this.master.getMasterQuotaManager(); for (RegionSpaceUse report : request.getSpaceUseList()) { quotaManager.addRegionSize(HRegionInfo.convert(report.getRegion()), report.getSize()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java index a5832f98132..cb614eadf8c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.quotas; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -58,6 +59,8 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.TimedQuota; @InterfaceStability.Evolving public class MasterQuotaManager implements RegionStateListener { private static final Log LOG = LogFactory.getLog(MasterQuotaManager.class); + private static final Map EMPTY_MAP = Collections.unmodifiableMap( + new HashMap<>()); private final MasterServices masterServices; private NamedLock namespaceLocks; @@ -529,13 +532,19 @@ public class MasterQuotaManager implements RegionStateListener { } public void addRegionSize(HRegionInfo hri, long size) { - // TODO Make proper API + if (null == regionSizes) { + return; + } + // TODO Make proper API? // TODO Prevent from growing indefinitely regionSizes.put(hri, size); } public Map snapshotRegionSizes() { - // TODO Make proper API + if (null == regionSizes) { + return EMPTY_MAP; + } + // TODO Make proper API? return new HashMap<>(regionSizes); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index ba3b52ff678..a50c8c17b75 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -119,6 +119,7 @@ import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer; import org.apache.hadoop.hbase.mob.MobCacheConfig; import org.apache.hadoop.hbase.procedure.RegionServerProcedureManagerHost; import org.apache.hadoop.hbase.quotas.FileSystemUtilizationChore; +import org.apache.hadoop.hbase.quotas.QuotaUtil; import org.apache.hadoop.hbase.quotas.RegionServerRpcQuotaManager; import org.apache.hadoop.hbase.quotas.RegionServerSpaceQuotaManager; import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration; @@ -933,7 +934,9 @@ public class HRegionServer extends HasThread implements rsQuotaManager = new RegionServerRpcQuotaManager(this); rsSpaceQuotaManager = new RegionServerSpaceQuotaManager(this); - this.fsUtilizationChore = new FileSystemUtilizationChore(this); + if (QuotaUtil.isQuotaEnabled(conf)) { + this.fsUtilizationChore = new FileSystemUtilizationChore(this); + } // Setup RPC client for master communication rpcClient = RpcClientFactory.createClient(conf, clusterId, new InetSocketAddress( diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotaManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotaManager.java new file mode 100644 index 00000000000..e383593251e --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotaManager.java @@ -0,0 +1,37 @@ +/* + * 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.quotas; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; + +import org.apache.hadoop.hbase.master.MasterServices; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestMasterQuotaManager { + + @Test + public void testUninitializedQuotaManangerDoesNotFail() { + MasterServices masterServices = mock(MasterServices.class); + MasterQuotaManager manager = new MasterQuotaManager(masterServices); + manager.addRegionSize(null, 0); + assertNotNull(manager.snapshotRegionSizes()); + } +}