Skip to content

Commit 9ad5197

Browse files
author
Haohui Mai
committed
HDFS-6156. Simplify the JMX API that provides snapshot information. Contributed by Shinichi Yamashita.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1582847 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0cf6ccf commit 9ad5197

File tree

7 files changed

+76
-62
lines changed

7 files changed

+76
-62
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ Release 2.5.0 - UNRELEASED
286286
HDFS-6162. Format strings should use platform independent line separator.
287287
(suresh)
288288

289+
HDFS-6156. Simplify the JMX API that provides snapshot information.
290+
(wheat9)
291+
289292
Release 2.4.0 - UNRELEASED
290293

291294
INCOMPATIBLE CHANGES

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshotInfo.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ public static class Bean {
8686
private final String snapshotDirectory;
8787
private final long modificationTime;
8888

89-
public Bean(Snapshot s) {
90-
this.snapshotID = s.getRoot().getLocalName();
91-
this.snapshotDirectory = s.getRoot().getFullPathName();
92-
this.modificationTime = s.getRoot().getModificationTime();
89+
public Bean(String snapshotID, String snapshotDirectory,
90+
long modificationTime) {
91+
this.snapshotID = snapshotID;
92+
this.snapshotDirectory = snapshotDirectory;
93+
this.modificationTime = modificationTime;
9394
}
9495

9596
public String getSnapshotID() {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/SnapshottableDirectoryStatus.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,15 @@ public static class Bean {
176176
private final String owner;
177177
private final String group;
178178

179-
public Bean(SnapshottableDirectoryStatus s) {
180-
this.path = s.getFullPath().toString();
181-
this.snapshotNumber = s.getSnapshotNumber();
182-
this.snapshotQuota = s.getSnapshotQuota();
183-
this.modificationTime = s.getDirStatus().getModificationTime();
184-
this.permission =
185-
Short.valueOf(Integer.toOctalString(
186-
s.getDirStatus().getPermission().toShort()));
187-
this.owner = s.getDirStatus().getOwner();
188-
this.group = s.getDirStatus().getGroup();
179+
public Bean(String path, int snapshotNumber, int snapshotQuota,
180+
long modificationTime, short permission, String owner, String group) {
181+
this.path = path;
182+
this.snapshotNumber = snapshotNumber;
183+
this.snapshotQuota = snapshotQuota;
184+
this.modificationTime = modificationTime;
185+
this.permission = permission;
186+
this.owner = owner;
187+
this.group = group;
189188
}
190189

191190
public String getPath() {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotManager.java

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -387,44 +387,43 @@ public void shutdown() {
387387
}
388388

389389
@Override // SnapshotStatsMXBean
390-
public SnapshotDirectoryMXBean getSnapshotStats() {
391-
SnapshottableDirectoryStatus[] stats = getSnapshottableDirListing(null);
392-
if (stats == null) {
393-
return null;
394-
}
395-
return new SnapshotDirectoryMXBean(stats);
396-
}
397-
398-
public class SnapshotDirectoryMXBean {
399-
private List<SnapshottableDirectoryStatus.Bean> directory =
390+
public SnapshottableDirectoryStatus.Bean[]
391+
getSnapshottableDirectories() {
392+
List<SnapshottableDirectoryStatus.Bean> beans =
400393
new ArrayList<SnapshottableDirectoryStatus.Bean>();
401-
private List<SnapshotInfo.Bean> snapshots =
402-
new ArrayList<SnapshotInfo.Bean>();
403-
404-
public SnapshotDirectoryMXBean(SnapshottableDirectoryStatus[] stats) {
405-
set(stats);
394+
for (INodeDirectorySnapshottable d : getSnapshottableDirs()) {
395+
beans.add(toBean(d));
406396
}
397+
return beans.toArray(new SnapshottableDirectoryStatus.Bean[beans.size()]);
398+
}
407399

408-
public void set(SnapshottableDirectoryStatus[] stats) {
409-
for (SnapshottableDirectoryStatus s : stats) {
410-
directory.add(new SnapshottableDirectoryStatus.Bean(s));
411-
try {
412-
for (Snapshot shot : getSnapshottableRoot(
413-
s.getFullPath().toString()).getSnapshotList()) {
414-
snapshots.add(new SnapshotInfo.Bean(shot));
415-
}
416-
} catch (IOException e) {
417-
continue;
418-
}
400+
@Override // SnapshotStatsMXBean
401+
public SnapshotInfo.Bean[] getSnapshots() {
402+
List<SnapshotInfo.Bean> beans = new ArrayList<SnapshotInfo.Bean>();
403+
for (INodeDirectorySnapshottable d : getSnapshottableDirs()) {
404+
for (Snapshot s : d.getSnapshotList()) {
405+
beans.add(toBean(s));
419406
}
420407
}
408+
return beans.toArray(new SnapshotInfo.Bean[beans.size()]);
409+
}
421410

422-
public List<SnapshottableDirectoryStatus.Bean> getDirectory() {
423-
return directory;
424-
}
411+
public static SnapshottableDirectoryStatus.Bean toBean(
412+
INodeDirectorySnapshottable d) {
413+
return new SnapshottableDirectoryStatus.Bean(
414+
d.getFullPathName(),
415+
d.getNumSnapshots(),
416+
d.getSnapshotQuota(),
417+
d.getModificationTime(),
418+
Short.valueOf(Integer.toOctalString(
419+
d.getFsPermissionShort())),
420+
d.getUserName(),
421+
d.getGroupName());
422+
}
425423

426-
public List<SnapshotInfo.Bean> getSnapshots() {
427-
return snapshots;
428-
}
424+
public static SnapshotInfo.Bean toBean(Snapshot s) {
425+
return new SnapshotInfo.Bean(
426+
s.getRoot().getLocalName(), s.getRoot().getFullPathName(),
427+
s.getRoot().getModificationTime());
429428
}
430429
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotStatsMXBean.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.namenode.snapshot;
1919

20-
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager.SnapshotDirectoryMXBean;
20+
import org.apache.hadoop.hdfs.protocol.SnapshotInfo;
21+
import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus;
2122

2223
/**
2324
* This is an interface used to retrieve statistic information related to
@@ -30,5 +31,13 @@ public interface SnapshotStatsMXBean {
3031
*
3132
* @return the list of snapshottable directories
3233
*/
33-
public SnapshotDirectoryMXBean getSnapshotStats();
34+
public SnapshottableDirectoryStatus.Bean[] getSnapshottableDirectories();
35+
36+
/**
37+
* Return the list of snapshots
38+
*
39+
* @return the list of snapshots
40+
*/
41+
public SnapshotInfo.Bean[] getSnapshots();
42+
3443
}

hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/dfshealth.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189

190190
<script type="text/x-dust-template" id="tmpl-snapshot">
191191
<div class="page-header"><h1>Snapshot Summary</h1></div>
192-
<div class="page-header"><h1><small>Snapshottable directories: {@size key=SnapshotStats.directory}{/size}</small></div>
192+
<div class="page-header"><h1><small>Snapshottable directories: {@size key=SnapshottableDirectories}{/size}</small></div>
193193
<small>
194194
<table class="table">
195195
<thead>
@@ -203,7 +203,7 @@
203203
<th>Group</th>
204204
</tr>
205205
</thead>
206-
{#SnapshotStats.directory}
206+
{#SnapshottableDirectories}
207207
<tr>
208208
<td>{path}</td>
209209
<td>{snapshotNumber}</td>
@@ -213,11 +213,11 @@
213213
<td>{owner}</td>
214214
<td>{group}</td>
215215
</tr>
216-
{/SnapshotStats.directory}
216+
{/SnapshottableDirectories}
217217
</table>
218218
</small>
219219

220-
<div class="page-header"><h1><small>Snapshotted directories: {@size key=SnapshotStats.snapshots}{/size}</small></div>
220+
<div class="page-header"><h1><small>Snapshotted directories: {@size key=Snapshots}{/size}</small></div>
221221

222222
<small>
223223
<table class="table">
@@ -228,13 +228,13 @@
228228
<th>Modification Time</th>
229229
</tr>
230230
</thead>
231-
{#SnapshotStats.snapshots}
231+
{#Snapshots}
232232
<tr>
233233
<td>{snapshotID}</td>
234234
<td>{snapshotDirectory}</td>
235235
<td>{modificationTime|date_tostring}</td>
236236
</tr>
237-
{/SnapshotStats.snapshots}
237+
{/Snapshots}
238238
</table>
239239
</small>
240240
</script>

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotStatsMXBean.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,20 @@ public void testSnapshotStatsMXBeanInfo() throws Exception {
5959
ObjectName mxbeanName = new ObjectName(
6060
"Hadoop:service=NameNode,name=SnapshotInfo");
6161

62-
CompositeData statsbean =
63-
(CompositeData) mbs.getAttribute(mxbeanName, "SnapshotStats");
64-
int numDirectories = Array.getLength(statsbean.get("directory"));
62+
CompositeData[] directories =
63+
(CompositeData[]) mbs.getAttribute(
64+
mxbeanName, "SnapshottableDirectories");
65+
int numDirectories = Array.getLength(directories);
6566
assertEquals(sm.getNumSnapshottableDirs(), numDirectories);
66-
int numSnapshots = Array.getLength(statsbean.get("snapshots"));
67+
CompositeData[] snapshots =
68+
(CompositeData[]) mbs.getAttribute(mxbeanName, "Snapshots");
69+
int numSnapshots = Array.getLength(snapshots);
6770
assertEquals(sm.getNumSnapshots(), numSnapshots);
6871

69-
CompositeData directory = (CompositeData) Array.get(statsbean.get("directory"), 0);
70-
CompositeData snapshots = (CompositeData) Array.get(statsbean.get("snapshots"), 0);
71-
assertTrue(((String) directory.get("path")).contains(pathName));
72-
assertTrue(((String) snapshots.get("snapshotDirectory")).contains(pathName));
72+
CompositeData d = (CompositeData) Array.get(directories, 0);
73+
CompositeData s = (CompositeData) Array.get(snapshots, 0);
74+
assertTrue(((String) d.get("path")).contains(pathName));
75+
assertTrue(((String) s.get("snapshotDirectory")).contains(pathName));
7376
} finally {
7477
if (cluster != null) {
7578
cluster.shutdown();

0 commit comments

Comments
 (0)