HBASE-25860 Add metric for successful wal roll requests. (#3241)
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
parent
39fdeae838
commit
1f04fac6d1
@ -74,6 +74,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.
|
||||
@ -111,4 +113,11 @@ public interface MetricsWALSource extends BaseSource {
|
||||
void incrementSizeLogRoll();
|
||||
|
||||
void incrementWrittenBytes(long val);
|
||||
|
||||
/**
|
||||
* Increment the number of successful log roll requests.
|
||||
*/
|
||||
void incrementSuccessfulLogRolls();
|
||||
|
||||
long getSuccessfulLogRolls();
|
||||
}
|
||||
|
@ -47,6 +47,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;
|
||||
@ -79,6 +80,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<>();
|
||||
}
|
||||
@ -155,4 +158,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();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.wal.WALKey;
|
||||
@ -90,4 +91,13 @@ public class MetricsWAL extends WALActionsListener.Base {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,14 +18,17 @@
|
||||
|
||||
package org.apache.hadoop.hbase.regionserver.wal;
|
||||
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.wal.WALKey;
|
||||
import org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -34,6 +37,9 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
@Category(SmallTests.class)
|
||||
public class TestMetricsWAL {
|
||||
@Rule
|
||||
public TestName name = new TestName();
|
||||
|
||||
@Test
|
||||
public void testLogRollRequested() throws Exception {
|
||||
MetricsWALSource source = mock(MetricsWALSourceImpl.class);
|
||||
@ -110,4 +116,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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user