3131import org .apache .hadoop .fs .FileStatus ;
3232import org .apache .hadoop .fs .FileSystem ;
3333import org .apache .hadoop .fs .Path ;
34+ import org .apache .hadoop .hbase .CompatibilityFactory ;
3435import org .apache .hadoop .hbase .HBaseTestingUtil ;
3536import org .apache .hadoop .hbase .HConstants ;
3637import org .apache .hadoop .hbase .ServerName ;
4546import org .apache .hadoop .hbase .procedure2 .ProcedureTestingUtility ;
4647import org .apache .hadoop .hbase .procedure2 .ProcedureYieldException ;
4748import org .apache .hadoop .hbase .procedure2 .StateMachineProcedure ;
49+ import org .apache .hadoop .hbase .test .MetricsAssertHelper ;
4850import org .apache .hadoop .hbase .testclassification .LargeTests ;
4951import org .apache .hadoop .hbase .testclassification .MasterTests ;
5052import org .apache .hadoop .hbase .util .Bytes ;
6971public class TestSplitWALManager {
7072
7173 private static final Logger LOG = LoggerFactory .getLogger (TestSplitWALManager .class );
74+ private static final MetricsAssertHelper METRICS_HELPER =
75+ CompatibilityFactory .getInstance (MetricsAssertHelper .class );
7276 private static HBaseTestingUtil TEST_UTIL ;
7377 private HMaster master ;
7478 private SplitWALManager splitWALManager ;
@@ -231,6 +235,9 @@ private void splitLogsTestHelper(HBaseTestingUtil testUtil) throws Exception {
231235 // load table
232236 testUtil .loadTable (testUtil .getConnection ().getTable (TABLE_NAME ), FAMILY );
233237 ProcedureExecutor <MasterProcedureEnv > masterPE = hmaster .getMasterProcedureExecutor ();
238+ MetricsMasterSource masterSource = hmaster .getMasterMetrics ().getMetricsSource ();
239+ long splitWALSubmittedBase = METRICS_HELPER
240+ .getCounter (MetricsMasterSource .SPLIT_WAL_METRIC_PREFIX + "SubmittedCount" , masterSource );
234241 ServerName metaServer = testUtil .getHBaseCluster ().getServerHoldingMeta ();
235242 ServerName testServer = testUtil .getHBaseCluster ().getRegionServerThreads ().stream ()
236243 .map (rs -> rs .getRegionServer ().getServerName ()).filter (rs -> rs != metaServer ).findAny ()
@@ -239,6 +246,9 @@ private void splitLogsTestHelper(HBaseTestingUtil testUtil) throws Exception {
239246 assertEquals (1 , procedures .size ());
240247 ProcedureTestingUtility .submitAndWait (masterPE , procedures .get (0 ));
241248 assertEquals (0 , splitWALManager .getWALsToSplit (testServer , false ).size ());
249+ // The SplitWALProcedure above should have been reported to the split WAL metric.
250+ METRICS_HELPER .assertCounter (MetricsMasterSource .SPLIT_WAL_METRIC_PREFIX + "SubmittedCount" ,
251+ splitWALSubmittedBase + 1 , masterSource );
242252
243253 // Validate the old WAL file archive dir
244254 Path walRootDir = hmaster .getMasterFileSystem ().getWALRootDir ();
@@ -251,6 +261,9 @@ private void splitLogsTestHelper(HBaseTestingUtil testUtil) throws Exception {
251261 ProcedureTestingUtility .submitAndWait (masterPE , procedures .get (0 ));
252262 assertEquals (0 , splitWALManager .getWALsToSplit (metaServer , true ).size ());
253263 assertEquals (1 , splitWALManager .getWALsToSplit (metaServer , false ).size ());
264+ // The meta SplitWALProcedure should also have been counted by the split WAL metric.
265+ METRICS_HELPER .assertCounter (MetricsMasterSource .SPLIT_WAL_METRIC_PREFIX + "SubmittedCount" ,
266+ splitWALSubmittedBase + 2 , masterSource );
254267 // There should be archiveFileCount + 1 WALs after SplitWALProcedure finish
255268 assertEquals (archiveFileCount + 1 , walFS .listStatus (walArchivePath ).length ,
256269 "Splitted WAL files should be archived" );
0 commit comments