HDFS-16461. Expose JournalNode storage info in the jmx metrics (#4002)

This commit is contained in:
Viraj Jasani 2022-02-22 09:34:36 +05:30 committed by GitHub
parent 697e5d4636
commit e363f51ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 3 deletions

View File

@ -423,6 +423,14 @@ public class JournalNode implements Tool, Configurable, JournalNodeMXBean {
return this.startTime;
}
@Override
// JournalNodeMXBean
public List<String> getStorageInfos() {
return journalsById.values().stream()
.map(journal -> journal.getStorage().toMapString())
.collect(Collectors.toList());
}
/**
* Register JournalNodeMXBean
*/

View File

@ -64,4 +64,13 @@ public interface JournalNodeMXBean {
* @return the start time of the JournalNode.
*/
long getJNStartedTimeInMillis();
/**
* Get the list of the storage infos of JournalNode's journals. Storage infos
* include layout version, namespace id, cluster id and creation time of the
* File system state.
*
* @return the list of storage infos associated with journals.
*/
List<String> getStorageInfos();
}

View File

@ -21,6 +21,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.SortedSet;
@ -112,6 +113,20 @@ public class StorageInfo {
.append(";nsid=").append(namespaceID).append(";c=").append(cTime);
return sb.toString();
}
/**
* Returns string representation of Storage info attributes stored in Map.
*
* @return string representation of storage info attributes.
*/
public String toMapString() {
Map<String, Object> storageInfo = new HashMap<>();
storageInfo.put("LayoutVersion", layoutVersion);
storageInfo.put("ClusterId", clusterID);
storageInfo.put("NamespaceId", namespaceID);
storageInfo.put("CreationTime", cTime);
return storageInfo.toString();
}
public String toColonSeparatedString() {
return Joiner.on(":").join(

View File

@ -44,6 +44,7 @@ public class TestJournalNodeMXBean {
private static final String NAMESERVICE = "ns1";
private static final int NUM_JN = 1;
private static final int NS_ID = 12345;
private MiniJournalCluster jCluster;
private JournalNode jn;
@ -80,9 +81,8 @@ public class TestJournalNodeMXBean {
assertFalse(journalStatus.contains(NAMESERVICE));
// format the journal ns1
final NamespaceInfo FAKE_NSINFO = new NamespaceInfo(12345, "mycluster",
"my-bp", 0L);
jn.getOrCreateJournal(NAMESERVICE).format(FAKE_NSINFO, false);
final NamespaceInfo fakeNsInfo = new NamespaceInfo(NS_ID, "mycluster", "my-bp", 0L);
jn.getOrCreateJournal(NAMESERVICE).format(fakeNsInfo, false);
// check again after format
// getJournalsStatus
@ -109,6 +109,11 @@ public class TestJournalNodeMXBean {
assertEquals(jn.getJNStartedTimeInMillis(), startTime);
String version = (String) mbs.getAttribute(mxbeanName, "Version");
assertEquals(jn.getVersion(), version);
String[] journalStorageInfos = (String[]) mbs.getAttribute(mxbeanName, "StorageInfos");
assertEquals(jn.getStorageInfos().size(), journalStorageInfos.length);
assertTrue(journalStorageInfos[1].contains("ClusterId=mycluster"));
assertTrue(journalStorageInfos[1].contains("CreationTime=0"));
assertTrue(journalStorageInfos[1].contains("NamespaceId=" + NS_ID));
// restart journal node without formatting
jCluster = new MiniJournalCluster.Builder(new Configuration()).format(false)