diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 9ee3bb8e71..4cb6dd8db6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -62,6 +62,9 @@ Trunk (unreleased changes) HDFS-3016. Security in unit tests. (Jaimin Jetly via jitendra) + HDFS-3014. FSEditLogOp and its subclasses should have toString() method. + (Sho Shimauchi via atm) + OPTIMIZATIONS HDFS-2477. Optimize computing the diff between a block report and the diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java index 61b4ef8a41..f075770c33 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java @@ -19,6 +19,7 @@ import java.util.zip.CheckedInputStream; import java.util.zip.Checksum; +import java.util.Arrays; import java.util.EnumMap; import org.apache.hadoop.fs.ChecksumException; @@ -305,6 +306,36 @@ private static Block[] readBlocks( } return blocks; } + + public String stringifyMembers() { + StringBuilder builder = new StringBuilder(); + builder.append("[length="); + builder.append(length); + builder.append(", path="); + builder.append(path); + builder.append(", replication="); + builder.append(replication); + builder.append(", mtime="); + builder.append(mtime); + builder.append(", atime="); + builder.append(atime); + builder.append(", blockSize="); + builder.append(blockSize); + builder.append(", blocks="); + builder.append(Arrays.toString(blocks)); + builder.append(", permissions="); + builder.append(permissions); + builder.append(", clientName="); + builder.append(clientName); + builder.append(", clientMachine="); + builder.append(clientMachine); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class AddOp extends AddCloseOp { @@ -315,6 +346,14 @@ private AddOp() { static AddOp getInstance() { return (AddOp)opInstances.get().get(OP_ADD); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AddOp "); + builder.append(stringifyMembers()); + return builder.toString(); + } } static class CloseOp extends AddCloseOp { @@ -325,6 +364,14 @@ private CloseOp() { static CloseOp getInstance() { return (CloseOp)opInstances.get().get(OP_CLOSE); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CloseOp "); + builder.append(stringifyMembers()); + return builder.toString(); + } } static class SetReplicationOp extends FSEditLogOp { @@ -366,6 +413,21 @@ void readFields(DataInputStream in, int logVersion) this.replication = readShort(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SetReplicationOp [path="); + builder.append(path); + builder.append(", replication="); + builder.append(replication); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class ConcatDeleteOp extends FSEditLogOp { @@ -440,6 +502,25 @@ void readFields(DataInputStream in, int logVersion) this.timestamp = readLong(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ConcatDeleteOp [length="); + builder.append(length); + builder.append(", trg="); + builder.append(trg); + builder.append(", srcs="); + builder.append(Arrays.toString(srcs)); + builder.append(", timestamp="); + builder.append(timestamp); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class RenameOldOp extends FSEditLogOp { @@ -497,6 +578,25 @@ void readFields(DataInputStream in, int logVersion) this.timestamp = readLong(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("RenameOldOp [length="); + builder.append(length); + builder.append(", src="); + builder.append(src); + builder.append(", dst="); + builder.append(dst); + builder.append(", timestamp="); + builder.append(timestamp); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class DeleteOp extends FSEditLogOp { @@ -545,6 +645,23 @@ void readFields(DataInputStream in, int logVersion) this.timestamp = readLong(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DeleteOp [length="); + builder.append(length); + builder.append(", path="); + builder.append(path); + builder.append(", timestamp="); + builder.append(timestamp); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class MkdirOp extends FSEditLogOp { @@ -623,6 +740,25 @@ void readFields(DataInputStream in, int logVersion) this.permissions = null; } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MkdirOp [length="); + builder.append(length); + builder.append(", path="); + builder.append(path); + builder.append(", timestamp="); + builder.append(timestamp); + builder.append(", permissions="); + builder.append(permissions); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class SetGenstampOp extends FSEditLogOp { @@ -652,6 +788,19 @@ void readFields(DataInputStream in, int logVersion) throws IOException { this.genStamp = FSImageSerialization.readLong(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SetGenstampOp [genStamp="); + builder.append(genStamp); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } @SuppressWarnings("deprecation") @@ -676,6 +825,17 @@ void readFields(DataInputStream in, int logVersion) //Datanodes are not persistent any more. FSImageSerialization.DatanodeImage.skipOne(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DatanodeAddOp [opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } @SuppressWarnings("deprecation") @@ -701,6 +861,17 @@ void readFields(DataInputStream in, int logVersion) nodeID.readFields(in); //Datanodes are not persistent any more. } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DatanodeRemoveOp [opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class SetPermissionsOp extends FSEditLogOp { @@ -738,6 +909,21 @@ void readFields(DataInputStream in, int logVersion) this.src = FSImageSerialization.readString(in); this.permissions = FsPermission.read(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SetPermissionsOp [src="); + builder.append(src); + builder.append(", permissions="); + builder.append(permissions); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class SetOwnerOp extends FSEditLogOp { @@ -783,6 +969,23 @@ void readFields(DataInputStream in, int logVersion) this.username = FSImageSerialization.readString_EmptyAsNull(in); this.groupname = FSImageSerialization.readString_EmptyAsNull(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SetOwnerOp [src="); + builder.append(src); + builder.append(", username="); + builder.append(username); + builder.append(", groupname="); + builder.append(groupname); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class SetNSQuotaOp extends FSEditLogOp { @@ -809,6 +1012,21 @@ void readFields(DataInputStream in, int logVersion) this.src = FSImageSerialization.readString(in); this.nsQuota = FSImageSerialization.readLong(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SetNSQuotaOp [src="); + builder.append(src); + builder.append(", nsQuota="); + builder.append(nsQuota); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class ClearNSQuotaOp extends FSEditLogOp { @@ -833,6 +1051,19 @@ void readFields(DataInputStream in, int logVersion) throws IOException { this.src = FSImageSerialization.readString(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ClearNSQuotaOp [src="); + builder.append(src); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class SetQuotaOp extends FSEditLogOp { @@ -878,6 +1109,23 @@ void readFields(DataInputStream in, int logVersion) this.nsQuota = FSImageSerialization.readLong(in); this.dsQuota = FSImageSerialization.readLong(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SetQuotaOp [src="); + builder.append(src); + builder.append(", nsQuota="); + builder.append(nsQuota); + builder.append(", dsQuota="); + builder.append(dsQuota); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class TimesOp extends FSEditLogOp { @@ -936,6 +1184,25 @@ void readFields(DataInputStream in, int logVersion) this.atime = readLong(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("TimesOp [length="); + builder.append(length); + builder.append(", path="); + builder.append(path); + builder.append(", mtime="); + builder.append(mtime); + builder.append(", atime="); + builder.append(atime); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class SymlinkOp extends FSEditLogOp { @@ -1011,6 +1278,29 @@ void readFields(DataInputStream in, int logVersion) } this.permissionStatus = PermissionStatus.read(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SymlinkOp [length="); + builder.append(length); + builder.append(", path="); + builder.append(path); + builder.append(", value="); + builder.append(value); + builder.append(", mtime="); + builder.append(mtime); + builder.append(", atime="); + builder.append(atime); + builder.append(", permissionStatus="); + builder.append(permissionStatus); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class RenameOp extends FSEditLogOp { @@ -1097,6 +1387,27 @@ static BytesWritable toBytesWritable(Rename... options) { } return new BytesWritable(bytes); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("RenameOp [length="); + builder.append(length); + builder.append(", src="); + builder.append(src); + builder.append(", dst="); + builder.append(dst); + builder.append(", timestamp="); + builder.append(timestamp); + builder.append(", options="); + builder.append(Arrays.toString(options)); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class ReassignLeaseOp extends FSEditLogOp { @@ -1142,6 +1453,23 @@ void readFields(DataInputStream in, int logVersion) this.path = FSImageSerialization.readString(in); this.newHolder = FSImageSerialization.readString(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ReassignLeaseOp [leaseHolder="); + builder.append(leaseHolder); + builder.append(", path="); + builder.append(path); + builder.append(", newHolder="); + builder.append(newHolder); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class GetDelegationTokenOp extends FSEditLogOp { @@ -1185,6 +1513,21 @@ void readFields(DataInputStream in, int logVersion) this.expiryTime = readLong(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GetDelegationTokenOp [token="); + builder.append(token); + builder.append(", expiryTime="); + builder.append(expiryTime); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class RenewDelegationTokenOp extends FSEditLogOp { @@ -1228,6 +1571,21 @@ void readFields(DataInputStream in, int logVersion) this.expiryTime = readLong(in); } } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("RenewDelegationTokenOp [token="); + builder.append(token); + builder.append(", expiryTime="); + builder.append(expiryTime); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class CancelDelegationTokenOp extends FSEditLogOp { @@ -1259,6 +1617,19 @@ void readFields(DataInputStream in, int logVersion) this.token = new DelegationTokenIdentifier(); this.token.readFields(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("CancelDelegationTokenOp [token="); + builder.append(token); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class UpdateMasterKeyOp extends FSEditLogOp { @@ -1289,6 +1660,19 @@ void readFields(DataInputStream in, int logVersion) this.key = new DelegationKey(); this.key.readFields(in); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("UpdateMasterKeyOp [key="); + builder.append(key); + builder.append(", opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class LogSegmentOp extends FSEditLogOp { @@ -1311,6 +1695,17 @@ public void readFields(DataInputStream in, int logVersion) void writeFields(DataOutputStream out) throws IOException { // no data stored } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("LogSegmentOp [opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static class InvalidOp extends FSEditLogOp { @@ -1331,6 +1726,17 @@ void readFields(DataInputStream in, int logVersion) throws IOException { // nothing to read } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("InvalidOp [opCode="); + builder.append(opCode); + builder.append(", txid="); + builder.append(txid); + builder.append("]"); + return builder.toString(); + } } static private short readShort(DataInputStream in) throws IOException {