HDFS-16461. Expose JournalNode storage info in the jmx metrics (#4002)
This commit is contained in:
parent
697e5d4636
commit
e363f51ffb
@ -423,6 +423,14 @@ public class JournalNode implements Tool, Configurable, JournalNodeMXBean {
|
|||||||
return this.startTime;
|
return this.startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// JournalNodeMXBean
|
||||||
|
public List<String> getStorageInfos() {
|
||||||
|
return journalsById.values().stream()
|
||||||
|
.map(journal -> journal.getStorage().toMapString())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register JournalNodeMXBean
|
* Register JournalNodeMXBean
|
||||||
*/
|
*/
|
||||||
|
@ -64,4 +64,13 @@ public interface JournalNodeMXBean {
|
|||||||
* @return the start time of the JournalNode.
|
* @return the start time of the JournalNode.
|
||||||
*/
|
*/
|
||||||
long getJNStartedTimeInMillis();
|
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();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
@ -113,6 +114,20 @@ public class StorageInfo {
|
|||||||
return sb.toString();
|
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() {
|
public String toColonSeparatedString() {
|
||||||
return Joiner.on(":").join(
|
return Joiner.on(":").join(
|
||||||
layoutVersion, namespaceID, cTime, clusterID);
|
layoutVersion, namespaceID, cTime, clusterID);
|
||||||
|
@ -44,6 +44,7 @@ public class TestJournalNodeMXBean {
|
|||||||
|
|
||||||
private static final String NAMESERVICE = "ns1";
|
private static final String NAMESERVICE = "ns1";
|
||||||
private static final int NUM_JN = 1;
|
private static final int NUM_JN = 1;
|
||||||
|
private static final int NS_ID = 12345;
|
||||||
|
|
||||||
private MiniJournalCluster jCluster;
|
private MiniJournalCluster jCluster;
|
||||||
private JournalNode jn;
|
private JournalNode jn;
|
||||||
@ -80,9 +81,8 @@ public class TestJournalNodeMXBean {
|
|||||||
assertFalse(journalStatus.contains(NAMESERVICE));
|
assertFalse(journalStatus.contains(NAMESERVICE));
|
||||||
|
|
||||||
// format the journal ns1
|
// format the journal ns1
|
||||||
final NamespaceInfo FAKE_NSINFO = new NamespaceInfo(12345, "mycluster",
|
final NamespaceInfo fakeNsInfo = new NamespaceInfo(NS_ID, "mycluster", "my-bp", 0L);
|
||||||
"my-bp", 0L);
|
jn.getOrCreateJournal(NAMESERVICE).format(fakeNsInfo, false);
|
||||||
jn.getOrCreateJournal(NAMESERVICE).format(FAKE_NSINFO, false);
|
|
||||||
|
|
||||||
// check again after format
|
// check again after format
|
||||||
// getJournalsStatus
|
// getJournalsStatus
|
||||||
@ -109,6 +109,11 @@ public class TestJournalNodeMXBean {
|
|||||||
assertEquals(jn.getJNStartedTimeInMillis(), startTime);
|
assertEquals(jn.getJNStartedTimeInMillis(), startTime);
|
||||||
String version = (String) mbs.getAttribute(mxbeanName, "Version");
|
String version = (String) mbs.getAttribute(mxbeanName, "Version");
|
||||||
assertEquals(jn.getVersion(), 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
|
// restart journal node without formatting
|
||||||
jCluster = new MiniJournalCluster.Builder(new Configuration()).format(false)
|
jCluster = new MiniJournalCluster.Builder(new Configuration()).format(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user