|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.master; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 | + |
| 22 | +import org.apache.hadoop.conf.Configuration; |
| 23 | +import org.apache.hadoop.hbase.CompatibilityFactory; |
| 24 | +import org.apache.hadoop.hbase.HBaseTestingUtil; |
| 25 | +import org.apache.hadoop.hbase.HConstants; |
| 26 | +import org.apache.hadoop.hbase.ServerName; |
| 27 | +import org.apache.hadoop.hbase.SingleProcessHBaseCluster; |
| 28 | +import org.apache.hadoop.hbase.TableName; |
| 29 | +import org.apache.hadoop.hbase.client.Put; |
| 30 | +import org.apache.hadoop.hbase.client.RegionInfo; |
| 31 | +import org.apache.hadoop.hbase.client.Table; |
| 32 | +import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; |
| 33 | +import org.apache.hadoop.hbase.master.assignment.AssignmentManager; |
| 34 | +import org.apache.hadoop.hbase.test.MetricsAssertHelper; |
| 35 | +import org.apache.hadoop.hbase.testclassification.MasterTests; |
| 36 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 37 | +import org.apache.hadoop.hbase.util.Bytes; |
| 38 | +import org.apache.hadoop.hbase.util.TableDescriptorChecker; |
| 39 | +import org.junit.jupiter.api.AfterAll; |
| 40 | +import org.junit.jupiter.api.BeforeAll; |
| 41 | +import org.junit.jupiter.api.BeforeEach; |
| 42 | +import org.junit.jupiter.api.Tag; |
| 43 | +import org.junit.jupiter.api.Test; |
| 44 | +import org.junit.jupiter.api.TestInfo; |
| 45 | +import org.slf4j.Logger; |
| 46 | +import org.slf4j.LoggerFactory; |
| 47 | + |
| 48 | +@Tag(MasterTests.TAG) |
| 49 | +@Tag(MediumTests.TAG) |
| 50 | +public class TestAssignmentManagerRitDurationMetrics { |
| 51 | + |
| 52 | + private static final Logger LOG = |
| 53 | + LoggerFactory.getLogger(TestAssignmentManagerRitDurationMetrics.class); |
| 54 | + |
| 55 | + private static final MetricsAssertHelper METRICS_HELPER = |
| 56 | + CompatibilityFactory.getInstance(MetricsAssertHelper.class); |
| 57 | + |
| 58 | + private static SingleProcessHBaseCluster CLUSTER; |
| 59 | + private static HMaster MASTER; |
| 60 | + private static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); |
| 61 | + private static final int MSG_INTERVAL = 1000; |
| 62 | + |
| 63 | + private String methodName; |
| 64 | + |
| 65 | + @BeforeAll |
| 66 | + public static void startCluster() throws Exception { |
| 67 | + LOG.info("Starting cluster"); |
| 68 | + Configuration conf = TEST_UTIL.getConfiguration(); |
| 69 | + |
| 70 | + // Enable sanity check for coprocessor, so that region reopen fails on the RS |
| 71 | + conf.setBoolean(TableDescriptorChecker.TABLE_SANITY_CHECKS, true); |
| 72 | + // set RIT stuck warning threshold to a small value |
| 73 | + conf.setInt(HConstants.METRICS_RIT_STUCK_WARNING_THRESHOLD, 20); |
| 74 | + // set msgInterval to 1 second |
| 75 | + conf.setInt("hbase.regionserver.msginterval", MSG_INTERVAL); |
| 76 | + // set tablesOnMaster to none |
| 77 | + conf.set("hbase.balancer.tablesOnMaster", "none"); |
| 78 | + // set client sync wait timeout to 5sec |
| 79 | + conf.setInt("hbase.client.sync.wait.timeout.msec", 5000); |
| 80 | + conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); |
| 81 | + conf.setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 2500); |
| 82 | + // set a small interval for updating rit metrics |
| 83 | + conf.setInt(AssignmentManager.RIT_CHORE_INTERVAL_MSEC_CONF_KEY, MSG_INTERVAL); |
| 84 | + // set a small assign attempts for avoiding assert when retrying. (HBASE-20533) |
| 85 | + conf.setInt(AssignmentManager.ASSIGN_MAX_ATTEMPTS, 3); |
| 86 | + // keep rs online so it can report the failed opens. |
| 87 | + conf.setBoolean(CoprocessorHost.ABORT_ON_ERROR_KEY, false); |
| 88 | + |
| 89 | + TEST_UTIL.startMiniCluster(2); |
| 90 | + CLUSTER = TEST_UTIL.getHBaseCluster(); |
| 91 | + MASTER = CLUSTER.getMaster(); |
| 92 | + // Disable sanity check for coprocessor, so that modify table runs on the HMaster |
| 93 | + MASTER.getConfiguration().setBoolean(TableDescriptorChecker.TABLE_SANITY_CHECKS, false); |
| 94 | + } |
| 95 | + |
| 96 | + @AfterAll |
| 97 | + public static void after() throws Exception { |
| 98 | + LOG.info("AFTER {} <= IS THIS NULL?", TEST_UTIL); |
| 99 | + TEST_UTIL.shutdownMiniCluster(); |
| 100 | + } |
| 101 | + |
| 102 | + @BeforeEach |
| 103 | + public void setUp(TestInfo testInfo) throws Exception { |
| 104 | + methodName = testInfo.getTestMethod().get().getName(); |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + public void testRitDurationHistogramMetric() throws Exception { |
| 109 | + final TableName tableName = TableName.valueOf(methodName); |
| 110 | + final byte[] family = Bytes.toBytes("family"); |
| 111 | + try (Table table = TEST_UTIL.createTable(tableName, family)) { |
| 112 | + final byte[] row = Bytes.toBytes("row"); |
| 113 | + final byte[] qualifier = Bytes.toBytes("qualifier"); |
| 114 | + final byte[] value = Bytes.toBytes("value"); |
| 115 | + |
| 116 | + Put put = new Put(row); |
| 117 | + put.addColumn(family, qualifier, value); |
| 118 | + table.put(put); |
| 119 | + Thread.sleep(MSG_INTERVAL * 2); |
| 120 | + |
| 121 | + MetricsAssignmentManagerSource amSource = |
| 122 | + MASTER.getAssignmentManager().getAssignmentManagerMetrics().getMetricsProcSource(); |
| 123 | + long ritDurationNumOps = getRitCountFromRegionStates(amSource); |
| 124 | + |
| 125 | + RegionInfo regionInfo = MASTER.getAssignmentManager().getRegionStates() |
| 126 | + .getRegionsOfTable(tableName).iterator().next(); |
| 127 | + ServerName current = |
| 128 | + MASTER.getAssignmentManager().getRegionStates().getRegionServerOfRegion(regionInfo); |
| 129 | + ServerName target = MASTER.getServerManager().getOnlineServersList().stream() |
| 130 | + .filter(sn -> !sn.equals(current)).findFirst() |
| 131 | + .orElseThrow(() -> new IllegalStateException("Need at least two regionservers")); |
| 132 | + |
| 133 | + TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), target); |
| 134 | + TEST_UTIL.waitFor(10_000, () -> getRitCountFromRegionStates(amSource) > ritDurationNumOps); |
| 135 | + TEST_UTIL.waitUntilNoRegionTransitScheduled(); |
| 136 | + Thread.sleep(MSG_INTERVAL * 5); |
| 137 | + assertEquals(ritDurationNumOps + 1, getRitCountFromRegionStates(amSource)); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + private long getRitCountFromRegionStates(MetricsAssignmentManagerSource amSource) { |
| 142 | + return METRICS_HELPER.getCounter("ritDurationNumOps", amSource); |
| 143 | + } |
| 144 | +} |
0 commit comments