Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-25679 Size of log queue metric is incorrect #3072

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,8 @@ private long getOldestWalTimestamp() {
}
return oldestWalTimestamp;
}

public MetricsSource getMetrics() {
return metrics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ private void dequeueCurrentLog() throws IOException {
logQueue.remove(walGroupId);
setCurrentPath(null);
setPosition(0);
metrics.decrSizeOfLogQueue();
}

private void readNextEntryAndSetPosition() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public static void tearDownAfterClass() throws Exception {

@Before
public void setUp() throws Exception {
logQueue = new ReplicationSourceLogQueue(conf, new MetricsSource("2"));
MetricsSource source = new MetricsSource("2");
// Source with the same id is shared and carries values from the last run
source.clear();
logQueue = new ReplicationSourceLogQueue(conf, source);
List<WALActionsListener> listeners = new ArrayList<WALActionsListener>();
pathWatcher = new PathWatcher();
listeners.add(pathWatcher);
Expand Down Expand Up @@ -811,4 +814,28 @@ private void appendEntries(WALProvider.Writer writer, int numEntries) throws IOE
}
writer.close();
}

/**
* Tests size of log queue is incremented and decremented properly.
*/
@Test
public void testSizeOfLogQueue() throws Exception {
// There should be always 1 log which is current wal.
assertEquals(1, logQueue.getMetrics().getSizeOfLogQueue());
appendToLog();
log.rollWriter();
// After rolling there will be 2 wals in the queue
assertEquals(2, logQueue.getMetrics().getSizeOfLogQueue());

try (WALEntryStream entryStream =
new WALEntryStream(logQueue, fs, conf, logQueue.getMetrics(), fakeWalGroupId)) {
// There's one edit in the log, read it.
assertTrue(entryStream.hasNext());
WAL.Entry entry = entryStream.next();
assertNotNull(entry);
assertFalse(entryStream.hasNext());
}
// After removing one wal, size of log queue will be 1 again.
assertEquals(1, logQueue.getMetrics().getSizeOfLogQueue());
}
}