HADOOP-11296. Nfs3FileAttributes should not change the values of rdev, nlink and size in the constructor. Contributed by Brandon Li.

This commit is contained in:
Haohui Mai 2014-11-10 15:42:47 -08:00
parent 92de44c2c5
commit d47a34fc66
3 changed files with 32 additions and 25 deletions

View File

@ -76,6 +76,9 @@ Release 2.7.0 - UNRELEASED
HADOOP-11289. Fix typo in RpcUtil log message. (Charles Lamb via wheat9) HADOOP-11289. Fix typo in RpcUtil log message. (Charles Lamb via wheat9)
HADOOP-11294. Nfs3FileAttributes should not change the values of rdev,
nlink and size in the constructor. (Brandon Li via wheat9)
Release 2.6.0 - 2014-11-15 Release 2.6.0 - 2014-11-15
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -49,8 +49,6 @@ public class Nfs3FileAttributes {
* values should be agreed upon by the client and server. If the client and * values should be agreed upon by the client and server. If the client and
* server do not agree upon the values, the client should treat these fields * server do not agree upon the values, the client should treat these fields
* as if they are set to 0. * as if they are set to 0.
* <br>
* For Hadoop, currently this field is always zero.
*/ */
public static class Specdata3 { public static class Specdata3 {
final int specdata1; final int specdata1;
@ -82,20 +80,17 @@ public class Nfs3FileAttributes {
} }
public Nfs3FileAttributes() { public Nfs3FileAttributes() {
this(NfsFileType.NFSREG, 0, (short)0, 0, 0, 0, 0, 0, 0, 0); this(NfsFileType.NFSREG, 1, (short)0, 0, 0, 0, 0, 0, 0, 0, new Specdata3());
} }
public Nfs3FileAttributes(NfsFileType nfsType, int nlink, short mode, int uid, public Nfs3FileAttributes(NfsFileType nfsType, int nlink, short mode, int uid,
int gid, long size, long fsid, long fileId, long mtime, long atime) { int gid, long size, long fsid, long fileId, long mtime, long atime, Specdata3 rdev) {
this.type = nfsType.toValue(); this.type = nfsType.toValue();
this.mode = mode; this.mode = mode;
this.nlink = (type == NfsFileType.NFSDIR.toValue()) ? (nlink + 2) : 1; this.nlink = nlink;
this.uid = uid; this.uid = uid;
this.gid = gid; this.gid = gid;
this.size = size; this.size = size;
if(type == NfsFileType.NFSDIR.toValue()) {
this.size = getDirSize(nlink);
}
this.used = this.size; this.used = this.size;
this.rdev = new Specdata3(); this.rdev = new Specdata3();
this.fsid = fsid; this.fsid = fsid;
@ -103,6 +98,7 @@ public class Nfs3FileAttributes {
this.mtime = new NfsTime(mtime); this.mtime = new NfsTime(mtime);
this.atime = atime != 0 ? new NfsTime(atime) : this.mtime; this.atime = atime != 0 ? new NfsTime(atime) : this.mtime;
this.ctime = this.mtime; this.ctime = this.mtime;
this.rdev = rdev;
} }
public Nfs3FileAttributes(Nfs3FileAttributes other) { public Nfs3FileAttributes(Nfs3FileAttributes other) {
@ -147,10 +143,7 @@ public class Nfs3FileAttributes {
attr.gid = xdr.readInt(); attr.gid = xdr.readInt();
attr.size = xdr.readHyper(); attr.size = xdr.readHyper();
attr.used = xdr.readHyper(); attr.used = xdr.readHyper();
// Ignore rdev attr.rdev = new Specdata3(xdr.readInt(), xdr.readInt());
xdr.readInt();
xdr.readInt();
attr.rdev = new Specdata3();
attr.fsid = xdr.readHyper(); attr.fsid = xdr.readHyper();
attr.fileId = xdr.readHyper(); attr.fileId = xdr.readHyper();
attr.atime = NfsTime.deserialize(xdr); attr.atime = NfsTime.deserialize(xdr);
@ -228,11 +221,11 @@ public class Nfs3FileAttributes {
return this.gid; return this.gid;
} }
/** public Specdata3 getRdev() {
* HDFS directory size is always zero. Try to return something meaningful return rdev;
* here. Assume each child take 32bytes. }
*/
public static long getDirSize(int childNum) { public void setRdev(Specdata3 rdev) {
return (childNum + 2) * 32; this.rdev = rdev;
} }
} }

View File

@ -67,11 +67,14 @@ public class Nfs3Utils {
*/ */
NfsFileType fileType = fs.isDir() ? NfsFileType.NFSDIR : NfsFileType.NFSREG; NfsFileType fileType = fs.isDir() ? NfsFileType.NFSDIR : NfsFileType.NFSREG;
fileType = fs.isSymlink() ? NfsFileType.NFSLNK : fileType; fileType = fs.isSymlink() ? NfsFileType.NFSLNK : fileType;
int nlink = (fileType == NfsFileType.NFSDIR) ? fs.getChildrenNum() + 2 : 1;
return new Nfs3FileAttributes(fileType, fs.getChildrenNum(), fs long size = (fileType == NfsFileType.NFSDIR) ? getDirSize(fs
.getPermission().toShort(), iug.getUidAllowingUnknown(fs.getOwner()), .getChildrenNum()) : fs.getLen();
iug.getGidAllowingUnknown(fs.getGroup()), fs.getLen(), 0 /* fsid */, return new Nfs3FileAttributes(fileType, nlink,
fs.getFileId(), fs.getModificationTime(), fs.getAccessTime()); fs.getPermission().toShort(), iug.getUidAllowingUnknown(fs.getOwner()),
iug.getGidAllowingUnknown(fs.getGroup()), size, 0 /* fsid */,
fs.getFileId(), fs.getModificationTime(), fs.getAccessTime(),
new Nfs3FileAttributes.Specdata3());
} }
public static Nfs3FileAttributes getFileAttr(DFSClient client, public static Nfs3FileAttributes getFileAttr(DFSClient client,
@ -80,6 +83,14 @@ public class Nfs3Utils {
return fs == null ? null : getNfs3FileAttrFromFileStatus(fs, iug); return fs == null ? null : getNfs3FileAttrFromFileStatus(fs, iug);
} }
/**
* HDFS directory size is always zero. Try to return something meaningful
* here. Assume each child take 32bytes.
*/
public static long getDirSize(int childNum) {
return (childNum + 2) * 32;
}
public static WccAttr getWccAttr(DFSClient client, String fileIdPath) public static WccAttr getWccAttr(DFSClient client, String fileIdPath)
throws IOException { throws IOException {
HdfsFileStatus fstat = getFileStatus(client, fileIdPath); HdfsFileStatus fstat = getFileStatus(client, fileIdPath);
@ -87,8 +98,8 @@ public class Nfs3Utils {
return null; return null;
} }
long size = fstat.isDir() ? Nfs3FileAttributes.getDirSize(fstat long size = fstat.isDir() ? getDirSize(fstat.getChildrenNum()) : fstat
.getChildrenNum()) : fstat.getLen(); .getLen();
return new WccAttr(size, new NfsTime(fstat.getModificationTime()), return new WccAttr(size, new NfsTime(fstat.getModificationTime()),
new NfsTime(fstat.getModificationTime())); new NfsTime(fstat.getModificationTime()));
} }