Skip to content

Commit

Permalink
HBASE-25860 Add metric for successful wal roll requests. (#3238)
Browse files Browse the repository at this point in the history
Signed-off-by: Viraj Jasani <vjasani@apache.org>
  • Loading branch information
shahrs87 authored and virajjasani committed May 8, 2021
1 parent d3b5464 commit eaea5e4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,6 +79,8 @@ public MetricsWALSourceImpl(String metricsName,
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<>();
}
Expand Down Expand Up @@ -159,4 +162,14 @@ public long getSlowAppendCount() {
public void incrementWrittenBytes(long val) {
writtenBytes.incr(val);
}

@Override
public void incrementSuccessfulLogRolls() {
successfulLogRolls.incr();
}

@Override
public long getSuccessfulLogRolls() {
return successfulLogRolls.value();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@

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.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALKey;
import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
import org.apache.hadoop.util.StringUtils;

/**
Expand Down Expand Up @@ -94,4 +95,13 @@ public void logRollRequested(WALActionsListener.RollRequestReason reason) {
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

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;
Expand All @@ -32,11 +33,15 @@
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 =
Expand Down Expand Up @@ -74,7 +79,8 @@ public void testPostSync() throws Exception {

@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);
Expand Down Expand Up @@ -129,4 +135,25 @@ public void testPerTableWALMetrics() throws Exception {
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());
}
}

0 comments on commit eaea5e4

Please sign in to comment.