HBASE-17478 Avoid reporting FS use when quotas are disabled
Also, gracefully produce responses when quotas are disabled.
This commit is contained in:
parent
f1066cd774
commit
4ad49bc3ac
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
if (QuotaUtil.isQuotaEnabled(conf)) {
|
||||
this.fsUtilizationChore = new FileSystemUtilizationChore(this);
|
||||
}
|
||||
|
||||
// Setup RPC client for master communication
|
||||
rpcClient = RpcClientFactory.createClient(conf, clusterId, new InetSocketAddress(
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue