-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-28209: Create a jmx metrics to expose the oldWALs directory size
Signed-off-by: Wellington Chevreuil <[email protected]>
- Loading branch information
1 parent
6d7b9c8
commit 7133958
Showing
12 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
hbase-server/src/main/java/org/apache/hadoop/hbase/master/OldWALsDirSizeChore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.master; | ||
|
||
import java.io.IOException; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.ScheduledChore; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This chore is used to update the 'oldWALsDirSize' variable in {@link MasterWalManager} through | ||
* the {@link MasterWalManager#updateOldWALsDirSize()} method. | ||
*/ | ||
@InterfaceAudience.Private | ||
public class OldWALsDirSizeChore extends ScheduledChore { | ||
private static final Logger LOG = LoggerFactory.getLogger(OldWALsDirSizeChore.class); | ||
|
||
private final MasterServices master; | ||
|
||
public OldWALsDirSizeChore(MasterServices master) { | ||
super(master.getServerName() + "-OldWALsDirSizeChore", master, | ||
master.getConfiguration().getInt(HConstants.HBASE_OLDWAL_DIR_SIZE_UPDATER_PERIOD, | ||
HConstants.DEFAULT_HBASE_OLDWAL_DIR_SIZE_UPDATER_PERIOD)); | ||
this.master = master; | ||
} | ||
|
||
@Override | ||
protected void chore() { | ||
try { | ||
this.master.getMasterWalManager().updateOldWALsDirSize(); | ||
} catch (IOException e) { | ||
LOG.error("Got exception while trying to update the old WALs Directory size counter: " | ||
+ e.getMessage(), e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOldWALsDirSizeChore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.master; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.HBaseTestingUtility; | ||
import org.apache.hadoop.hbase.master.assignment.MockMasterServices; | ||
import org.apache.hadoop.hbase.testclassification.MasterTests; | ||
import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Tests for OldWALsDirSizeChore Here we are using the {@link MockMasterServices} to mock the Hbase | ||
* Master. Chore's won't be running automatically; we need to run every time. | ||
*/ | ||
@Category({ MasterTests.class, SmallTests.class }) | ||
public class TestOldWALsDirSizeChore { | ||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestOldWALsDirSizeChore.class); | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(TestOldWALsDirSizeChore.class); | ||
|
||
private MockMasterServices master; | ||
|
||
private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
master = new MockMasterServices(HTU.getConfiguration()); | ||
master.start(10, null); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
master.stop("tearDown"); | ||
} | ||
|
||
@Test | ||
public void testOldWALsDirSizeChore() throws IOException { | ||
// Assume the OldWALs directory size is initially zero as the chore hasn't run yet | ||
long currentOldWALsDirSize = master.getMasterWalManager().getOldWALsDirSize(); | ||
assertEquals("Initial OldWALs directory size should be zero before running the chore", 0, | ||
currentOldWALsDirSize); | ||
|
||
int dummyFileSize = 50 * 1024 * 1024; // 50MB | ||
byte[] dummyData = new byte[dummyFileSize]; | ||
|
||
// Create a dummy file in the OldWALs directory | ||
Path dummyFileInOldWALsDir = new Path(master.getMasterWalManager().getOldLogDir(), "dummy.txt"); | ||
try (FSDataOutputStream outputStream = | ||
master.getMasterWalManager().getFileSystem().create(dummyFileInOldWALsDir)) { | ||
outputStream.write(dummyData); | ||
} | ||
|
||
// Run the OldWALsDirSizeChore to update the directory size | ||
OldWALsDirSizeChore oldWALsDirSizeChore = new OldWALsDirSizeChore(master); | ||
oldWALsDirSizeChore.chore(); | ||
|
||
// Verify that the OldWALs directory size has increased by the file size | ||
assertEquals("OldWALs directory size after chore should be as expected", dummyFileSize, | ||
master.getMasterWalManager().getOldWALsDirSize()); | ||
} | ||
} |