Skip to content

Commit 04f02d2

Browse files
committed
Addressed checkstyle/findbug as well as review comments.
1 parent 989158a commit 04f02d2

File tree

16 files changed

+93
-102
lines changed

16 files changed

+93
-102
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/dev-support/findbugsExcludeFile.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<Class name="org.apache.hadoop.hdfs.util.StripedBlockUtil$ChunkByteArray"/>
2323
<Class name="org.apache.hadoop.hdfs.protocol.SnapshotDiffReportListing$DiffReportListingEntry"/>
2424
<Class name="org.apache.hadoop.hdfs.protocol.SnapshotDiffReportListing"/>
25+
<Class name="org.apache.hadoop.hdfs.protocol.SnapshotStatus"/>
26+
</Or>
2527
</Or>
2628
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2" />
2729
</Match>

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,16 +2192,16 @@ public SnapshottableDirectoryStatus[] getSnapshottableDirListing()
21922192
}
21932193

21942194
/**
2195-
* Get listing of all the snapshots for a snapshottable directory
2195+
* Get listing of all the snapshots for a snapshottable directory.
21962196
*
21972197
* @return Information about all the snapshots for a snapshottable directory
21982198
* @throws IOException If an I/O error occurred
2199-
* @see ClientProtocol#getSnapshotListing()
2199+
* @see ClientProtocol#getSnapshotListing(String)
22002200
*/
22012201
public SnapshotStatus[] getSnapshotListing(String snapshotRoot)
22022202
throws IOException {
22032203
checkOpen();
2204-
try (TraceScope ignored = tracer.newScope("getSnapshottableDirListing")) {
2204+
try (TraceScope ignored = tracer.newScope("getSnapshotListing")) {
22052205
return namenode.getSnapshotListing(snapshotRoot);
22062206
} catch (RemoteException re) {
22072207
throw re.unwrapRemoteException();

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSOpsCountStatistics.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public enum OpType {
111111
SET_XATTR("op_set_xattr"),
112112
GET_SNAPSHOT_DIFF("op_get_snapshot_diff"),
113113
GET_SNAPSHOTTABLE_DIRECTORY_LIST("op_get_snapshottable_directory_list"),
114+
GET_SNAPSHOT_LIST("op_get_snapshot_list"),
114115
TRUNCATE(CommonStatisticNames.OP_TRUNCATE),
115116
UNSET_EC_POLICY("op_unset_ec_policy"),
116117
UNSET_STORAGE_POLICY("op_unset_storage_policy");

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,11 @@ public SnapshottableDirectoryStatus[] getSnapshottableDirListing()
21552155
*/
21562156
public SnapshotStatus[] getSnapshotListing(Path snapshotRoot)
21572157
throws IOException {
2158-
return dfs.getSnapshotListing(getPathName(snapshotRoot));
2158+
Path absF = fixRelativePart(snapshotRoot);
2159+
statistics.incrementReadOps(1);
2160+
storageStatistics
2161+
.incrementOpCounter(OpType.GET_SNAPSHOT_LIST);
2162+
return dfs.getSnapshotListing(getPathName(absF));
21592163
}
21602164

21612165
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ SnapshottableDirectoryStatus[] getSnapshottableDirListing()
728728
throws IOException;
729729

730730
/**
731-
* Get listing of all the snapshots for a snapshottable directory
731+
* Get listing of all the snapshots for a snapshottable directory.
732732
*
733733
* @return Information about all the snapshots for a snapshottable directory
734734
* @throws IOException If an I/O error occurred

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
import org.apache.hadoop.hdfs.DFSUtilClient;
2828

2929
/**
30-
* Metadata about a snapshottable directory
30+
* Metadata about a snapshottable directory.
3131
*/
3232
public class SnapshotStatus {
3333
/**
34-
* Basic information of the snapshot directory
34+
* Basic information of the snapshot directory.
3535
*/
3636
private final HdfsFileStatus dirStatus;
3737

3838
/**
39-
* Snapshot ID for the snapshot
39+
* Snapshot ID for the snapshot.
4040
*/
4141
private final int snapshotID;
4242

@@ -45,16 +45,16 @@ public class SnapshotStatus {
4545
*/
4646
private final byte[] parentFullPath;
4747

48-
public SnapshotStatus(long modification_time, long access_time,
48+
public SnapshotStatus(long modificationTime, long accessTime,
4949
FsPermission permission,
5050
EnumSet<HdfsFileStatus.Flags> flags,
5151
String owner, String group, byte[] localName,
5252
long inodeId, int childrenNum, int snapshotID,
5353
byte[] parentFullPath) {
5454
this.dirStatus = new HdfsFileStatus.Builder()
5555
.isdir(true)
56-
.mtime(modification_time)
57-
.atime(access_time)
56+
.mtime(modificationTime)
57+
.atime(accessTime)
5858
.perm(permission)
5959
.flags(flags)
6060
.owner(owner)
@@ -102,9 +102,9 @@ public Path getFullPath() {
102102
String parentFullPathStr =
103103
(parentFullPath == null || parentFullPath.length == 0) ?
104104
"/" : DFSUtilClient.bytes2String(parentFullPath);
105-
return new Path(getSnapshotPath(parentFullPathStr,
106-
dirStatus.getLocalName()));
107-
}
105+
return new Path(getSnapshotPath(parentFullPathStr,
106+
dirStatus.getLocalName()));
107+
}
108108

109109
/**
110110
* Print a list of {@link SnapshotStatus} out to a given stream.

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelperClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,9 @@ public static SnapshottableDirectoryStatus convert(
16741674

16751675
public static SnapshotStatus[] convert(
16761676
HdfsProtos.SnapshotListingProto sdlp) {
1677-
if (sdlp == null)
1677+
if (sdlp == null) {
16781678
return null;
1679+
}
16791680
List<HdfsProtos.SnapshotStatusProto> list = sdlp
16801681
.getSnapshotListingList();
16811682
if (list.isEmpty()) {
@@ -2712,8 +2713,9 @@ public static SnapshottableDirectoryListingProto convert(
27122713

27132714
public static HdfsProtos.SnapshotListingProto convert(
27142715
SnapshotStatus[] status) {
2715-
if (status == null)
2716+
if (status == null) {
27162717
return null;
2718+
}
27172719
HdfsProtos.SnapshotStatusProto[] protos =
27182720
new HdfsProtos.SnapshotStatusProto[status.length];
27192721
for (int i = 0; i < status.length; i++) {

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterSnapshot.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,17 @@ public SnapshotStatus[] getSnapshotListing(String snapshotRoot)
163163
rpcServer.checkOperation(NameNode.OperationCategory.READ);
164164
final List<RemoteLocation> locations =
165165
rpcServer.getLocationsForPath(snapshotRoot, true, false);
166-
RemoteMethod method = new RemoteMethod("getSnapshotListing",
167-
new Class<?>[] {String.class},
166+
RemoteMethod remoteMethod = new RemoteMethod("getSnapshotListing",
167+
new Class<?>[]{String.class},
168168
new RemoteParam());
169-
Set<FederationNamespaceInfo> nss = namenodeResolver.getNamespaces();
170-
Map<FederationNamespaceInfo, SnapshotStatus[]> ret =
171-
rpcClient.invokeConcurrent(
172-
nss, method, true, false, SnapshotStatus[].class);
173-
174-
return RouterRpcServer.merge(ret, SnapshotStatus.class);
169+
if (rpcServer.isInvokeConcurrent(snapshotRoot)) {
170+
Map<RemoteLocation, SnapshotStatus[]> ret = rpcClient.invokeConcurrent(
171+
locations, remoteMethod, true, false, SnapshotStatus[].class);
172+
return ret.values().iterator().next();
173+
} else {
174+
return rpcClient.invokeSequential(
175+
locations, remoteMethod, SnapshotStatus[].class, null);
176+
}
175177
}
176178

177179
public SnapshotDiffReport getSnapshotDiffReport(String snapshotRoot,

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,9 @@
7171
import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties;
7272
import org.apache.hadoop.hdfs.NameNodeProxies;
7373
import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;
74-
import org.apache.hadoop.hdfs.protocol.AddErasureCodingPolicyResponse;
75-
import org.apache.hadoop.hdfs.protocol.BlockStoragePolicy;
76-
import org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo;
77-
import org.apache.hadoop.hdfs.protocol.CachePoolEntry;
78-
import org.apache.hadoop.hdfs.protocol.CachePoolInfo;
79-
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
80-
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
81-
import org.apache.hadoop.hdfs.protocol.DirectoryListing;
82-
import org.apache.hadoop.hdfs.protocol.ECBlockGroupStats;
83-
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
84-
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyInfo;
85-
import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyState;
86-
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
74+
import org.apache.hadoop.hdfs.protocol.*;
8775
import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
8876
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
89-
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
90-
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
91-
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
92-
import org.apache.hadoop.hdfs.protocol.ReplicatedBlockStats;
93-
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
94-
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReportListing;
95-
import org.apache.hadoop.hdfs.protocol.SnapshotException;
96-
import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus;
9777
import org.apache.hadoop.hdfs.security.token.block.ExportedBlockKeys;
9878
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
9979
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil;
@@ -110,6 +90,7 @@
11090
import org.apache.hadoop.hdfs.server.namenode.INodeDirectory;
11191
import org.apache.hadoop.hdfs.server.namenode.NameNode;
11292
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
93+
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper;
11394
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations;
11495
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations;
11596
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorageReport;
@@ -926,6 +907,16 @@ public void testGetSnapshotListing() throws IOException {
926907
SnapshottableDirectoryStatus snapshotDir0 = dirList[0];
927908
assertEquals(snapshotPath, snapshotDir0.getFullPath().toString());
928909

910+
// check for snapshot listing through the Router
911+
SnapshotStatus[] snapshots = routerProtocol.
912+
getSnapshotListing(snapshotPath);
913+
assertEquals(2, snapshots.length);
914+
assertEquals(SnapshotTestHelper.getSnapshotRoot
915+
(new Path(snapshotPath), snapshot1),
916+
snapshots[0].getFullPath());
917+
assertEquals(SnapshotTestHelper.getSnapshotRoot
918+
(new Path(snapshotPath), snapshot2),
919+
snapshots[1].getFullPath());
929920
// Check for difference report in two snapshot
930921
SnapshotDiffReport diffReport = routerProtocol.getSnapshotDiffReport(
931922
snapshotPath, snapshot1, snapshot2);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,14 @@ static SnapshottableDirectoryStatus[] getSnapshottableDirListing(
156156
}
157157

158158
static SnapshotStatus[] getSnapshotListing(
159-
FSDirectory fsd, SnapshotManager snapshotManager, String path)
159+
FSDirectory fsd, FSPermissionChecker pc, SnapshotManager snapshotManager,
160+
String path)
160161
throws IOException {
161-
FSPermissionChecker pc = fsd.getPermissionChecker();
162162
fsd.readLock();
163163
try {
164164
INodesInPath iip = fsd.getINodesInPath(path, DirOp.READ);
165165
if (fsd.isPermissionEnabled()) {
166-
fsd.checkPermission(pc, iip, false, null, null, FsAction.READ,
167-
FsAction.READ);
166+
fsd.checkPathAccess(pc, iip, FsAction.READ);
168167
}
169168
return snapshotManager.getSnapshotListing(iip);
170169
} finally {

0 commit comments

Comments
 (0)