HBASE-25860 Add metric for successful wal roll requests. (#3238)

Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Rushabh Shah 2021-05-08 03:28:29 -04:00 committed by GitHub
parent c2a1d31270
commit 8c2332d465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 1 deletions

View File

@ -76,6 +76,8 @@ public interface MetricsWALSource extends BaseSource {
"How many times a roll was requested due to file size roll threshold.";
String WRITTEN_BYTES = "writtenBytes";
String WRITTEN_BYTES_DESC = "Size (in bytes) of the data written to the WAL.";
String SUCCESSFUL_LOG_ROLLS = "successfulLogRolls";
String SUCCESSFUL_LOG_ROLLS_DESC = "Number of successful log rolls requests";
/**
* Add the append size.
@ -115,4 +117,11 @@ public interface MetricsWALSource extends BaseSource {
void incrementSizeLogRoll();
void incrementWrittenBytes(long val);
/**
* Increment the number of successful log roll requests.
*/
void incrementSuccessfulLogRolls();
long getSuccessfulLogRolls();
}

View File

@ -46,6 +46,7 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo
private final MutableFastCounter slowSyncRollRequested;
private final MutableFastCounter sizeRollRequested;
private final MutableFastCounter writtenBytes;
private final MutableFastCounter successfulLogRolls;
// Per table metrics.
private final ConcurrentMap<TableName, MutableFastCounter> perTableAppendCount;
private final ConcurrentMap<TableName, MutableFastCounter> perTableAppendSize;
@ -78,6 +79,8 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo
sizeRollRequested = this.getMetricsRegistry()
.newCounter(SIZE_ROLL_REQUESTED, SIZE_ROLL_REQUESTED_DESC, 0L);
writtenBytes = this.getMetricsRegistry().newCounter(WRITTEN_BYTES, WRITTEN_BYTES_DESC, 0L);
successfulLogRolls = this.getMetricsRegistry()
.newCounter(SUCCESSFUL_LOG_ROLLS, SUCCESSFUL_LOG_ROLLS_DESC, 0L);
perTableAppendCount = new ConcurrentHashMap<>();
perTableAppendSize = new ConcurrentHashMap<>();
}
@ -159,4 +162,14 @@ public class MetricsWALSourceImpl extends BaseSourceImpl implements MetricsWALSo
public void incrementWrittenBytes(long val) {
writtenBytes.incr(val);
}
@Override
public void incrementSuccessfulLogRolls() {
successfulLogRolls.incr();
}
@Override
public long getSuccessfulLogRolls() {
return successfulLogRolls.value();
}
}

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.regionserver.wal;
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.wal.WALEdit;
@ -91,4 +92,13 @@ public class MetricsWAL implements WALActionsListener {
break;
}
}
@Override
public void postLogRoll(Path oldPath, Path newPath) {
// oldPath can be null if this is the first time we created a wal
// Also newPath can be equal to oldPath if AbstractFSWAL#replaceWriter fails
if (newPath != oldPath) {
source.incrementSuccessfulLogRolls();
}
}
}

View File

@ -24,6 +24,7 @@ import static org.mockito.Mockito.verify;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.MiscTests;
@ -32,11 +33,15 @@ import org.apache.hadoop.hbase.wal.WALKey;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
@Category({MiscTests.class, SmallTests.class})
public class TestMetricsWAL {
@Rule
public TestName name = new TestName();
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
@ -74,7 +79,8 @@ public class TestMetricsWAL {
@Test
public void testSlowAppend() throws Exception {
MetricsWALSource source = new MetricsWALSourceImpl();
String testName = name.getMethodName();
MetricsWALSource source = new MetricsWALSourceImpl(testName, testName, testName, testName);
MetricsWAL metricsWAL = new MetricsWAL(source);
TableName tableName = TableName.valueOf("foo");
WALKey walKey = new WALKeyImpl(null, tableName, -1);
@ -129,4 +135,25 @@ public class TestMetricsWAL {
assertEquals(i * numIters, tableAppendSize);
}
}
@Test
public void testLogRolls() {
String testName = name.getMethodName();
MetricsWALSource source = new MetricsWALSourceImpl(testName, testName, testName, testName);
MetricsWAL metricsWAL = new MetricsWAL(source);
Path path1 = new Path("path-1");
int count = 1;
// oldPath is null but newPath is not null;
metricsWAL.postLogRoll(null, path1);
assertEquals(count, source.getSuccessfulLogRolls());
// Simulating a case where AbstractFSWAL#replaceWriter fails
metricsWAL.postLogRoll(path1, path1);
assertEquals(count, source.getSuccessfulLogRolls());
count++;
Path path2 = new Path("path-2");
metricsWAL.postLogRoll(path1, path2);
assertEquals(count, source.getSuccessfulLogRolls());
}
}