HBASE-17478 Avoid reporting FS use when quotas are disabled Also, gracefully produce responses when quotas are disabled.
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/cc2517f5 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/cc2517f5 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/cc2517f5 Branch: refs/heads/HBASE-16961 Commit: cc2517f5e2bc3953e8a34b65cb2bab295f5b5f0f Parents: 50effd6 Author: Josh Elser <els...@apache.org> Authored: Tue Jan 17 14:41:45 2017 -0500 Committer: Josh Elser <els...@apache.org> Committed: Mon Mar 20 18:02:55 2017 -0400 ---------------------------------------------------------------------- .../hadoop/hbase/master/MasterRpcServices.java | 4 +++ .../hadoop/hbase/quotas/MasterQuotaManager.java | 13 +++++-- .../hbase/regionserver/HRegionServer.java | 5 ++- .../hbase/quotas/TestMasterQuotaManager.java | 37 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/cc2517f5/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.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 f10d4bb..a7a2f94 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.Procedure; import org.apache.hadoop.hbase.procedure2.ProcedureUtil; 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; @@ -2016,6 +2017,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()); http://git-wip-us.apache.org/repos/asf/hbase/blob/cc2517f5/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/MasterQuotaManager.java ---------------------------------------------------------------------- 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 a5832f9..cb614ea 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<HRegionInfo, Long> EMPTY_MAP = Collections.unmodifiableMap( + new HashMap<>()); private final MasterServices masterServices; private NamedLock<String> 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<HRegionInfo, Long> snapshotRegionSizes() { - // TODO Make proper API + if (null == regionSizes) { + return EMPTY_MAP; + } + // TODO Make proper API? return new HashMap<>(regionSizes); } } http://git-wip-us.apache.org/repos/asf/hbase/blob/cc2517f5/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java ---------------------------------------------------------------------- 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 79e2c46..81c58c3 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( http://git-wip-us.apache.org/repos/asf/hbase/blob/cc2517f5/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestMasterQuotaManager.java ---------------------------------------------------------------------- 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 0000000..e383593 --- /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()); + } +}