Skip to content

Commit e363f51

Browse files
authored
HDFS-16461. Expose JournalNode storage info in the jmx metrics (#4002)
1 parent 697e5d4 commit e363f51

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalNode.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ public long getJNStartedTimeInMillis() {
423423
return this.startTime;
424424
}
425425

426+
@Override
427+
// JournalNodeMXBean
428+
public List<String> getStorageInfos() {
429+
return journalsById.values().stream()
430+
.map(journal -> journal.getStorage().toMapString())
431+
.collect(Collectors.toList());
432+
}
433+
426434
/**
427435
* Register JournalNodeMXBean
428436
*/

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalNodeMXBean.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,13 @@ public interface JournalNodeMXBean {
6464
* @return the start time of the JournalNode.
6565
*/
6666
long getJNStartedTimeInMillis();
67+
68+
/**
69+
* Get the list of the storage infos of JournalNode's journals. Storage infos
70+
* include layout version, namespace id, cluster id and creation time of the
71+
* File system state.
72+
*
73+
* @return the list of storage infos associated with journals.
74+
*/
75+
List<String> getStorageInfos();
6776
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/StorageInfo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.FileInputStream;
2222
import java.io.IOException;
2323
import java.io.RandomAccessFile;
24+
import java.util.HashMap;
2425
import java.util.Map;
2526
import java.util.Properties;
2627
import java.util.SortedSet;
@@ -112,6 +113,20 @@ public String toString() {
112113
.append(";nsid=").append(namespaceID).append(";c=").append(cTime);
113114
return sb.toString();
114115
}
116+
117+
/**
118+
* Returns string representation of Storage info attributes stored in Map.
119+
*
120+
* @return string representation of storage info attributes.
121+
*/
122+
public String toMapString() {
123+
Map<String, Object> storageInfo = new HashMap<>();
124+
storageInfo.put("LayoutVersion", layoutVersion);
125+
storageInfo.put("ClusterId", clusterID);
126+
storageInfo.put("NamespaceId", namespaceID);
127+
storageInfo.put("CreationTime", cTime);
128+
return storageInfo.toString();
129+
}
115130

116131
public String toColonSeparatedString() {
117132
return Joiner.on(":").join(

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournalNodeMXBean.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class TestJournalNodeMXBean {
4444

4545
private static final String NAMESERVICE = "ns1";
4646
private static final int NUM_JN = 1;
47+
private static final int NS_ID = 12345;
4748

4849
private MiniJournalCluster jCluster;
4950
private JournalNode jn;
@@ -80,9 +81,8 @@ public void testJournalNodeMXBean() throws Exception {
8081
assertFalse(journalStatus.contains(NAMESERVICE));
8182

8283
// format the journal ns1
83-
final NamespaceInfo FAKE_NSINFO = new NamespaceInfo(12345, "mycluster",
84-
"my-bp", 0L);
85-
jn.getOrCreateJournal(NAMESERVICE).format(FAKE_NSINFO, false);
84+
final NamespaceInfo fakeNsInfo = new NamespaceInfo(NS_ID, "mycluster", "my-bp", 0L);
85+
jn.getOrCreateJournal(NAMESERVICE).format(fakeNsInfo, false);
8686

8787
// check again after format
8888
// getJournalsStatus
@@ -109,6 +109,11 @@ public void testJournalNodeMXBean() throws Exception {
109109
assertEquals(jn.getJNStartedTimeInMillis(), startTime);
110110
String version = (String) mbs.getAttribute(mxbeanName, "Version");
111111
assertEquals(jn.getVersion(), version);
112+
String[] journalStorageInfos = (String[]) mbs.getAttribute(mxbeanName, "StorageInfos");
113+
assertEquals(jn.getStorageInfos().size(), journalStorageInfos.length);
114+
assertTrue(journalStorageInfos[1].contains("ClusterId=mycluster"));
115+
assertTrue(journalStorageInfos[1].contains("CreationTime=0"));
116+
assertTrue(journalStorageInfos[1].contains("NamespaceId=" + NS_ID));
112117

113118
// restart journal node without formatting
114119
jCluster = new MiniJournalCluster.Builder(new Configuration()).format(false)

0 commit comments

Comments
 (0)