Skip to content

Commit

Permalink
HDFS-17444. Add getJournalSyncerStarted jmx metrics, to Indicates whe…
Browse files Browse the repository at this point in the history
…ther the JournalSyncer thread has been started.
  • Loading branch information
xiaojunxiang2023 committed Apr 1, 2024
1 parent 5bfca65 commit 745dd1f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,18 @@ public boolean accept(File file) {
return JSON.toString(status);
}

@Override // JournalNodeMXBean
public String getJournalSyncerStatus() {
StringBuilder sbuilder = new StringBuilder();
journalSyncersById.keySet().forEach((jid) ->
sbuilder.append(jid)
.append(","));
if (sbuilder.length() > 0) {
sbuilder.deleteCharAt(sbuilder.length() - 1);
}
return "[" + sbuilder.toString() + "]";
}

@Override // JournalNodeMXBean
public String getHostAndPort() {
return NetUtils.getHostPortString(rpcServer.getAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public interface JournalNodeMXBean {
*/
String getJournalsStatus();

/**
* Query JournalSyncer status.
*
* @return JournalSyncer status.
*
* example: "[ns1,ns3]" string means:
* JournalSyncer thread for ns1 and ns3 has enter working state,
* but for ns2 has not enter working state yet
*/
String getJournalSyncerStatus();

/**
* Get host and port of JournalNode.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,21 @@ public void testJournalNodeMXBean() throws Exception {
assertEquals(jn.getJournalsStatus(), journalStatus);
assertFalse(journalStatus.contains(NAMESERVICE));

// getJournalSyncerStatus
String journalSyncerStarted = (String) mbs.getAttribute(mxbeanName,
"JournalSyncerStatus");
assertEquals(jn.getJournalSyncerStatus(), journalSyncerStarted);
assertFalse(journalSyncerStarted.contains(NAMESERVICE));

// format the journal ns1
final NamespaceInfo fakeNsInfo = new NamespaceInfo(NS_ID, "mycluster", "my-bp", 0L);
jn.getOrCreateJournal(NAMESERVICE).format(fakeNsInfo, false);

// check again after getOrCreateJournal
journalSyncerStarted = (String) mbs.getAttribute(mxbeanName,
"JournalSyncerStatus");
assertTrue(journalSyncerStarted.contains(NAMESERVICE));

// check again after format
// getJournalsStatus
journalStatus = (String) mbs.getAttribute(mxbeanName, "JournalsStatus");
Expand Down

0 comments on commit 745dd1f

Please sign in to comment.