HDFS-362. FSEditLog should not writes long and short as UTF8, and should not use ArrayWritable for writing non-array items. Contributed by Uma Maheswara Rao G

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1171945 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-09-17 10:53:44 +00:00
parent 94096ff6f5
commit dafa8f7a77
8 changed files with 346 additions and 196 deletions

View File

@ -49,6 +49,10 @@ Trunk (unreleased changes)
HDFS-2333. Change DFSOutputStream back to package private, otherwise, HDFS-2333. Change DFSOutputStream back to package private, otherwise,
there are two SC_START_IN_CTOR findbugs warnings. (szetszwo) there are two SC_START_IN_CTOR findbugs warnings. (szetszwo)
HDFS-362. FSEditLog should not writes long and short as UTF8, and should
not use ArrayWritable for writing non-array items. (Uma Maheswara Rao G
via szetszwo)
Release 0.23.0 - Unreleased Release 0.23.0 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -80,7 +80,9 @@ public class LayoutVersion {
FEDERATION(-35, "Support for namenode federation"), FEDERATION(-35, "Support for namenode federation"),
LEASE_REASSIGNMENT(-36, "Support for persisting lease holder reassignment"), LEASE_REASSIGNMENT(-36, "Support for persisting lease holder reassignment"),
STORED_TXIDS(-37, "Transaction IDs are stored in edits log and image files"), STORED_TXIDS(-37, "Transaction IDs are stored in edits log and image files"),
TXID_BASED_LAYOUT(-38, "File names in NN Storage are based on transaction IDs"); TXID_BASED_LAYOUT(-38, "File names in NN Storage are based on transaction IDs"),
EDITLOG_OP_OPTIMIZATION(-39,
"Use LongWritable and ShortWritable directly instead of ArrayWritable of UTF8");
final int lv; final int lv;
final int ancestorLV; final int ancestorLV;

View File

@ -30,19 +30,16 @@ import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.permission.PermissionStatus; import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.DatanodeID;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.LayoutVersion; import org.apache.hadoop.hdfs.protocol.LayoutVersion;
import org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature; import org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.common.GenerationStamp; import org.apache.hadoop.hdfs.server.common.GenerationStamp;
import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.util.PureJavaCrc32; import org.apache.hadoop.util.PureJavaCrc32;
import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.*; import static org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes.*;
import org.apache.hadoop.security.token.delegation.DelegationKey; import org.apache.hadoop.security.token.delegation.DelegationKey;
import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.ArrayWritable; import org.apache.hadoop.io.ArrayWritable;
import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableFactories; import org.apache.hadoop.io.WritableFactories;
@ -192,19 +189,17 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 nameReplicationPair[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(path), FSImageSerialization.writeShort(replication, out);
toLogReplication(replication), FSImageSerialization.writeLong(mtime, out);
toLogLong(mtime), FSImageSerialization.writeLong(atime, out);
toLogLong(atime), FSImageSerialization.writeLong(blockSize, out);
toLogLong(blockSize)};
new ArrayWritable(DeprecatedUTF8.class, nameReplicationPair).write(out);
new ArrayWritable(Block.class, blocks).write(out); new ArrayWritable(Block.class, blocks).write(out);
permissions.write(out); permissions.write(out);
if (this.opCode == OP_ADD) { if (this.opCode == OP_ADD) {
new DeprecatedUTF8(clientName).write(out); FSImageSerialization.writeString(clientName,out);
new DeprecatedUTF8(clientMachine).write(out); FSImageSerialization.writeString(clientMachine,out);
} }
} }
@ -213,25 +208,43 @@ public abstract class FSEditLogOp {
throws IOException { throws IOException {
// versions > 0 support per file replication // versions > 0 support per file replication
// get name and replication // get name and replication
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.length = in.readInt();
}
if (-7 == logVersion && length != 3|| if (-7 == logVersion && length != 3||
-17 < logVersion && logVersion < -7 && length != 4 || -17 < logVersion && logVersion < -7 && length != 4 ||
logVersion <= -17 && length != 5) { (logVersion <= -17 && length != 5 && !LayoutVersion.supports(
Feature.EDITLOG_OP_OPTIMIZATION, logVersion))) {
throw new IOException("Incorrect data format." + throw new IOException("Incorrect data format." +
" logVersion is " + logVersion + " logVersion is " + logVersion +
" but writables.length is " + " but writables.length is " +
length + ". "); length + ". ");
} }
this.path = FSImageSerialization.readString(in); this.path = FSImageSerialization.readString(in);
this.replication = readShort(in);
this.mtime = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.replication = FSImageSerialization.readShort(in);
this.mtime = FSImageSerialization.readLong(in);
} else {
this.replication = readShort(in);
this.mtime = readLong(in);
}
if (LayoutVersion.supports(Feature.FILE_ACCESS_TIME, logVersion)) { if (LayoutVersion.supports(Feature.FILE_ACCESS_TIME, logVersion)) {
this.atime = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.atime = FSImageSerialization.readLong(in);
} else {
this.atime = readLong(in);
}
} else { } else {
this.atime = 0; this.atime = 0;
} }
if (logVersion < -7) { if (logVersion < -7) {
this.blockSize = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.blockSize = FSImageSerialization.readLong(in);
} else {
this.blockSize = readLong(in);
}
} else { } else {
this.blockSize = 0; this.blockSize = 0;
} }
@ -335,15 +348,19 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
new DeprecatedUTF8(path).write(out); FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(Short.toString(replication)).write(out); FSImageSerialization.writeShort(replication, out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.path = FSImageSerialization.readString(in); this.path = FSImageSerialization.readString(in);
this.replication = readShort(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.replication = FSImageSerialization.readShort(in);
} else {
this.replication = readShort(in);
}
} }
} }
@ -379,32 +396,45 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
int size = 1 + srcs.length + 1; // trg, srcs, timestamp FSImageSerialization.writeString(trg, out);
DeprecatedUTF8 info[] = new DeprecatedUTF8[size];
DeprecatedUTF8 info[] = new DeprecatedUTF8[srcs.length];
int idx = 0; int idx = 0;
info[idx++] = new DeprecatedUTF8(trg);
for(int i=0; i<srcs.length; i++) { for(int i=0; i<srcs.length; i++) {
info[idx++] = new DeprecatedUTF8(srcs[i]); info[idx++] = new DeprecatedUTF8(srcs[i]);
} }
info[idx] = toLogLong(timestamp);
new ArrayWritable(DeprecatedUTF8.class, info).write(out); new ArrayWritable(DeprecatedUTF8.class, info).write(out);
FSImageSerialization.writeLong(timestamp, out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
if (length < 3) { // trg, srcs.., timestam this.length = in.readInt();
throw new IOException("Incorrect data format. " if (length < 3) { // trg, srcs.., timestamp
+ "Concat delete operation."); throw new IOException("Incorrect data format. "
+ "Concat delete operation.");
}
} }
this.trg = FSImageSerialization.readString(in); this.trg = FSImageSerialization.readString(in);
int srcSize = this.length - 1 - 1; //trg and timestamp int srcSize = 0;
if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
srcSize = in.readInt();
} else {
srcSize = this.length - 1 - 1; // trg and timestamp
}
this.srcs = new String [srcSize]; this.srcs = new String [srcSize];
for(int i=0; i<srcSize;i++) { for(int i=0; i<srcSize;i++) {
srcs[i]= FSImageSerialization.readString(in); srcs[i]= FSImageSerialization.readString(in);
} }
this.timestamp = readLong(in);
if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.timestamp = FSImageSerialization.readLong(in);
} else {
this.timestamp = readLong(in);
}
} }
} }
@ -440,24 +470,28 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 info[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(src, out);
new DeprecatedUTF8(src), FSImageSerialization.writeString(dst, out);
new DeprecatedUTF8(dst), FSImageSerialization.writeLong(timestamp, out);
toLogLong(timestamp)};
new ArrayWritable(DeprecatedUTF8.class, info).write(out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
if (this.length != 3) { this.length = in.readInt();
throw new IOException("Incorrect data format. " if (this.length != 3) {
+ "Old rename operation."); throw new IOException("Incorrect data format. "
+ "Old rename operation.");
}
} }
this.src = FSImageSerialization.readString(in); this.src = FSImageSerialization.readString(in);
this.dst = FSImageSerialization.readString(in); this.dst = FSImageSerialization.readString(in);
this.timestamp = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.timestamp = FSImageSerialization.readLong(in);
} else {
this.timestamp = readLong(in);
}
} }
} }
@ -487,22 +521,25 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 info[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(path), FSImageSerialization.writeLong(timestamp, out);
toLogLong(timestamp)};
new ArrayWritable(DeprecatedUTF8.class, info).write(out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
if (this.length != 2) { this.length = in.readInt();
throw new IOException("Incorrect data format. " if (this.length != 2) {
+ "delete operation."); throw new IOException("Incorrect data format. " + "delete operation.");
}
} }
this.path = FSImageSerialization.readString(in); this.path = FSImageSerialization.readString(in);
this.timestamp = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.timestamp = FSImageSerialization.readLong(in);
} else {
this.timestamp = readLong(in);
}
} }
} }
@ -538,12 +575,9 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 info[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(path), FSImageSerialization.writeLong(timestamp, out); // mtime
toLogLong(timestamp), // mtime FSImageSerialization.writeLong(timestamp, out); // atime, unused at this
toLogLong(timestamp) // atime, unused at this time
};
new ArrayWritable(DeprecatedUTF8.class, info).write(out);
permissions.write(out); permissions.write(out);
} }
@ -551,20 +585,32 @@ public abstract class FSEditLogOp {
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.length = in.readInt();
}
if (-17 < logVersion && length != 2 || if (-17 < logVersion && length != 2 ||
logVersion <= -17 && length != 3) { logVersion <= -17 && length != 3
&& !LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
throw new IOException("Incorrect data format. " throw new IOException("Incorrect data format. "
+ "Mkdir operation."); + "Mkdir operation.");
} }
this.path = FSImageSerialization.readString(in); this.path = FSImageSerialization.readString(in);
this.timestamp = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.timestamp = FSImageSerialization.readLong(in);
} else {
this.timestamp = readLong(in);
}
// The disk format stores atimes for directories as well. // The disk format stores atimes for directories as well.
// However, currently this is not being updated/used because of // However, currently this is not being updated/used because of
// performance reasons. // performance reasons.
if (LayoutVersion.supports(Feature.FILE_ACCESS_TIME, logVersion)) { if (LayoutVersion.supports(Feature.FILE_ACCESS_TIME, logVersion)) {
/*unused this.atime = */readLong(in); /* unused this.atime = */
if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
FSImageSerialization.readLong(in);
} else {
readLong(in);
}
} }
if (logVersion <= -11) { if (logVersion <= -11) {
@ -594,13 +640,13 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
new LongWritable(genStamp).write(out); FSImageSerialization.writeLong(genStamp, out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.genStamp = in.readLong(); this.genStamp = FSImageSerialization.readLong(in);
} }
} }
@ -678,7 +724,7 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
new DeprecatedUTF8(src).write(out); FSImageSerialization.writeString(src, out);
permissions.write(out); permissions.write(out);
} }
@ -721,11 +767,9 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 u = new DeprecatedUTF8(username == null? "": username); FSImageSerialization.writeString(src, out);
DeprecatedUTF8 g = new DeprecatedUTF8(groupname == null? "": groupname); FSImageSerialization.writeString(username == null ? "" : username, out);
new DeprecatedUTF8(src).write(out); FSImageSerialization.writeString(groupname == null ? "" : groupname, out);
u.write(out);
g.write(out);
} }
@Override @Override
@ -759,7 +803,7 @@ public abstract class FSEditLogOp {
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.src = FSImageSerialization.readString(in); this.src = FSImageSerialization.readString(in);
this.nsQuota = readLongWritable(in); this.nsQuota = FSImageSerialization.readLong(in);
} }
} }
@ -818,17 +862,17 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
new DeprecatedUTF8(src).write(out); FSImageSerialization.writeString(src, out);
new LongWritable(nsQuota).write(out); FSImageSerialization.writeLong(nsQuota, out);
new LongWritable(dsQuota).write(out); FSImageSerialization.writeLong(dsQuota, out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.src = FSImageSerialization.readString(in); this.src = FSImageSerialization.readString(in);
this.nsQuota = readLongWritable(in); this.nsQuota = FSImageSerialization.readLong(in);
this.dsQuota = readLongWritable(in); this.dsQuota = FSImageSerialization.readLong(in);
} }
} }
@ -864,24 +908,29 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 info[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(path), FSImageSerialization.writeLong(mtime, out);
toLogLong(mtime), FSImageSerialization.writeLong(atime, out);
toLogLong(atime)};
new ArrayWritable(DeprecatedUTF8.class, info).write(out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
if (length != 3) { this.length = in.readInt();
throw new IOException("Incorrect data format. " if (length != 3) {
+ "times operation."); throw new IOException("Incorrect data format. " + "times operation.");
}
} }
this.path = FSImageSerialization.readString(in); this.path = FSImageSerialization.readString(in);
this.mtime = readLong(in);
this.atime = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.mtime = FSImageSerialization.readLong(in);
this.atime = FSImageSerialization.readLong(in);
} else {
this.mtime = readLong(in);
this.atime = readLong(in);
}
} }
} }
@ -929,28 +978,33 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 info[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(path), FSImageSerialization.writeString(value, out);
new DeprecatedUTF8(value), FSImageSerialization.writeLong(mtime, out);
toLogLong(mtime), FSImageSerialization.writeLong(atime, out);
toLogLong(atime)};
new ArrayWritable(DeprecatedUTF8.class, info).write(out);
permissionStatus.write(out); permissionStatus.write(out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.length = in.readInt(); this.length = in.readInt();
if (this.length != 4) { if (this.length != 4) {
throw new IOException("Incorrect data format. " throw new IOException("Incorrect data format. "
+ "symlink operation."); + "symlink operation.");
}
} }
this.path = FSImageSerialization.readString(in); this.path = FSImageSerialization.readString(in);
this.value = FSImageSerialization.readString(in); this.value = FSImageSerialization.readString(in);
this.mtime = readLong(in);
this.atime = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.mtime = FSImageSerialization.readLong(in);
this.atime = FSImageSerialization.readLong(in);
} else {
this.mtime = readLong(in);
this.atime = readLong(in);
}
this.permissionStatus = PermissionStatus.read(in); this.permissionStatus = PermissionStatus.read(in);
} }
} }
@ -993,25 +1047,29 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
DeprecatedUTF8 info[] = new DeprecatedUTF8[] { FSImageSerialization.writeString(src, out);
new DeprecatedUTF8(src), FSImageSerialization.writeString(dst, out);
new DeprecatedUTF8(dst), FSImageSerialization.writeLong(timestamp, out);
toLogLong(timestamp)};
new ArrayWritable(DeprecatedUTF8.class, info).write(out);
toBytesWritable(options).write(out); toBytesWritable(options).write(out);
} }
@Override @Override
void readFields(DataInputStream in, int logVersion) void readFields(DataInputStream in, int logVersion)
throws IOException { throws IOException {
this.length = in.readInt(); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
if (this.length != 3) { this.length = in.readInt();
throw new IOException("Incorrect data format. " if (this.length != 3) {
+ "Rename operation."); throw new IOException("Incorrect data format. " + "Rename operation.");
}
} }
this.src = FSImageSerialization.readString(in); this.src = FSImageSerialization.readString(in);
this.dst = FSImageSerialization.readString(in); this.dst = FSImageSerialization.readString(in);
this.timestamp = readLong(in);
if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.timestamp = FSImageSerialization.readLong(in);
} else {
this.timestamp = readLong(in);
}
this.options = readRenameOptions(in); this.options = readRenameOptions(in);
} }
@ -1068,9 +1126,9 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
new DeprecatedUTF8(leaseHolder).write(out); FSImageSerialization.writeString(leaseHolder, out);
new DeprecatedUTF8(path).write(out); FSImageSerialization.writeString(path, out);
new DeprecatedUTF8(newHolder).write(out); FSImageSerialization.writeString(newHolder, out);
} }
@Override @Override
@ -1109,7 +1167,7 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
token.write(out); token.write(out);
toLogLong(expiryTime).write(out); FSImageSerialization.writeLong(expiryTime, out);
} }
@Override @Override
@ -1117,7 +1175,11 @@ public abstract class FSEditLogOp {
throws IOException { throws IOException {
this.token = new DelegationTokenIdentifier(); this.token = new DelegationTokenIdentifier();
this.token.readFields(in); this.token.readFields(in);
this.expiryTime = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.expiryTime = FSImageSerialization.readLong(in);
} else {
this.expiryTime = readLong(in);
}
} }
} }
@ -1148,7 +1210,7 @@ public abstract class FSEditLogOp {
@Override @Override
void writeFields(DataOutputStream out) throws IOException { void writeFields(DataOutputStream out) throws IOException {
token.write(out); token.write(out);
toLogLong(expiryTime).write(out); FSImageSerialization.writeLong(expiryTime, out);
} }
@Override @Override
@ -1156,7 +1218,11 @@ public abstract class FSEditLogOp {
throws IOException { throws IOException {
this.token = new DelegationTokenIdentifier(); this.token = new DelegationTokenIdentifier();
this.token.readFields(in); this.token.readFields(in);
this.expiryTime = readLong(in); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
this.expiryTime = FSImageSerialization.readLong(in);
} else {
this.expiryTime = readLong(in);
}
} }
} }
@ -1271,14 +1337,6 @@ public abstract class FSEditLogOp {
return Long.parseLong(FSImageSerialization.readString(in)); return Long.parseLong(FSImageSerialization.readString(in));
} }
static private DeprecatedUTF8 toLogReplication(short replication) {
return new DeprecatedUTF8(Short.toString(replication));
}
static private DeprecatedUTF8 toLogLong(long timestamp) {
return new DeprecatedUTF8(Long.toString(timestamp));
}
/** /**
* A class to read in blocks stored in the old format. The only two * A class to read in blocks stored in the old format. The only two
* fields in the block were blockid and length. * fields in the block were blockid and length.
@ -1314,17 +1372,6 @@ public abstract class FSEditLogOp {
} }
} }
// a place holder for reading a long
private static final LongWritable longWritable = new LongWritable();
/** Read an integer from an input stream */
private static long readLongWritable(DataInputStream in) throws IOException {
synchronized (longWritable) {
longWritable.readFields(in);
return longWritable.get();
}
}
/** /**
* Class for writing editlog ops * Class for writing editlog ops
*/ */

View File

@ -36,6 +36,8 @@ import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.ShortWritable;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.Writable;
@ -72,6 +74,8 @@ public class FSImageSerialization {
*/ */
static private final class TLData { static private final class TLData {
final DeprecatedUTF8 U_STR = new DeprecatedUTF8(); final DeprecatedUTF8 U_STR = new DeprecatedUTF8();
final ShortWritable U_SHORT = new ShortWritable();
final LongWritable U_LONG = new LongWritable();
final FsPermission FILE_PERM = new FsPermission((short) 0); final FsPermission FILE_PERM = new FsPermission((short) 0);
} }
@ -215,7 +219,35 @@ public class FSImageSerialization {
ustr.write(out); ustr.write(out);
} }
/** read the long value */
static long readLong(DataInputStream in) throws IOException {
LongWritable ustr = TL_DATA.get().U_LONG;
ustr.readFields(in);
return ustr.get();
}
/** write the long value */
static void writeLong(long value, DataOutputStream out) throws IOException {
LongWritable uLong = TL_DATA.get().U_LONG;
uLong.set(value);
uLong.write(out);
}
/** read short value */
static short readShort(DataInputStream in) throws IOException {
ShortWritable uShort = TL_DATA.get().U_SHORT;
uShort.readFields(in);
return uShort.get();
}
/** write short value */
static void writeShort(short value, DataOutputStream out) throws IOException {
ShortWritable uShort = TL_DATA.get().U_SHORT;
uShort.set(value);
uShort.write(out);
}
// Same comments apply for this method as for readString() // Same comments apply for this method as for readString()
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static byte[] readBytes(DataInputStream in) throws IOException { public static byte[] readBytes(DataInputStream in) throws IOException {

View File

@ -41,7 +41,7 @@ import static org.apache.hadoop.hdfs.tools.offlineEditsViewer.Tokenizer.VIntToke
class EditsLoaderCurrent implements EditsLoader { class EditsLoaderCurrent implements EditsLoader {
private static int[] supportedVersions = { -18, -19, -20, -21, -22, -23, -24, private static int[] supportedVersions = { -18, -19, -20, -21, -22, -23, -24,
-25, -26, -27, -28, -30, -31, -32, -33, -34, -35, -36, -37, -38}; -25, -26, -27, -28, -30, -31, -32, -33, -34, -35, -36, -37, -38, -39};
private EditsVisitor v; private EditsVisitor v;
private int editsVersion = 0; private int editsVersion = 0;
@ -102,20 +102,29 @@ class EditsLoaderCurrent implements EditsLoader {
private void visit_OP_ADD_or_OP_CLOSE(FSEditLogOpCodes editsOpCode) private void visit_OP_ADD_or_OP_CLOSE(FSEditLogOpCodes editsOpCode)
throws IOException { throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
IntToken opAddLength = v.visitInt(EditsElement.LENGTH); IntToken opAddLength = v.visitInt(EditsElement.LENGTH);
// this happens if the edits is not properly ended (-1 op code), // this happens if the edits is not properly ended (-1 op code),
// it is padded at the end with all zeros, OP_ADD is zero so // it is padded at the end with all zeros, OP_ADD is zero so
// without this check we would treat all zeros as empty OP_ADD) // without this check we would treat all zeros as empty OP_ADD)
if(opAddLength.value == 0) { if (opAddLength.value == 0) {
throw new IOException("OpCode " + editsOpCode + throw new IOException("OpCode " + editsOpCode
" has zero length (corrupted edits)"); + " has zero length (corrupted edits)");
}
} }
v.visitStringUTF8(EditsElement.PATH); v.visitStringUTF8(EditsElement.PATH);
v.visitStringUTF8(EditsElement.REPLICATION); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitStringUTF8(EditsElement.MTIME); v.visitShort(EditsElement.REPLICATION);
v.visitStringUTF8(EditsElement.ATIME); v.visitLong(EditsElement.MTIME);
v.visitStringUTF8(EditsElement.BLOCKSIZE); v.visitLong(EditsElement.ATIME);
v.visitLong(EditsElement.BLOCKSIZE);
} else {
v.visitStringUTF8(EditsElement.REPLICATION);
v.visitStringUTF8(EditsElement.MTIME);
v.visitStringUTF8(EditsElement.ATIME);
v.visitStringUTF8(EditsElement.BLOCKSIZE);
}
// now read blocks // now read blocks
IntToken numBlocksToken = v.visitInt(EditsElement.NUMBLOCKS); IntToken numBlocksToken = v.visitInt(EditsElement.NUMBLOCKS);
for (int i = 0; i < numBlocksToken.value; i++) { for (int i = 0; i < numBlocksToken.value; i++) {
@ -146,11 +155,16 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_RENAME_OLD() throws IOException { private void visit_OP_RENAME_OLD() throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitInt( EditsElement.LENGTH); v.visitInt(EditsElement.LENGTH);
}
v.visitStringUTF8( EditsElement.SOURCE); v.visitStringUTF8( EditsElement.SOURCE);
v.visitStringUTF8( EditsElement.DESTINATION); v.visitStringUTF8( EditsElement.DESTINATION);
v.visitStringUTF8( EditsElement.TIMESTAMP); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitLong(EditsElement.TIMESTAMP);
} else {
v.visitStringUTF8(EditsElement.TIMESTAMP);
}
} }
/** /**
@ -158,10 +172,15 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_DELETE() throws IOException { private void visit_OP_DELETE() throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitInt( EditsElement.LENGTH); v.visitInt(EditsElement.LENGTH);
}
v.visitStringUTF8( EditsElement.PATH); v.visitStringUTF8( EditsElement.PATH);
v.visitStringUTF8( EditsElement.TIMESTAMP); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitLong(EditsElement.TIMESTAMP);
} else {
v.visitStringUTF8(EditsElement.TIMESTAMP);
}
} }
/** /**
@ -169,11 +188,17 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_MKDIR() throws IOException { private void visit_OP_MKDIR() throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitInt( EditsElement.LENGTH); v.visitInt(EditsElement.LENGTH);
}
v.visitStringUTF8( EditsElement.PATH); v.visitStringUTF8( EditsElement.PATH);
v.visitStringUTF8( EditsElement.TIMESTAMP); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitStringUTF8( EditsElement.ATIME); v.visitLong(EditsElement.TIMESTAMP);
v.visitLong(EditsElement.ATIME);
} else {
v.visitStringUTF8(EditsElement.TIMESTAMP);
v.visitStringUTF8(EditsElement.ATIME);
}
// PERMISSION_STATUS // PERMISSION_STATUS
v.visitEnclosingElement( EditsElement.PERMISSION_STATUS); v.visitEnclosingElement( EditsElement.PERMISSION_STATUS);
@ -191,7 +216,11 @@ class EditsLoaderCurrent implements EditsLoader {
visitTxId(); visitTxId();
v.visitStringUTF8(EditsElement.PATH); v.visitStringUTF8(EditsElement.PATH);
v.visitStringUTF8(EditsElement.REPLICATION); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitShort(EditsElement.REPLICATION);
} else {
v.visitStringUTF8(EditsElement.REPLICATION);
}
} }
/** /**
@ -229,11 +258,17 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_TIMES() throws IOException { private void visit_OP_TIMES() throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitInt( EditsElement.LENGTH); v.visitInt(EditsElement.LENGTH);
}
v.visitStringUTF8( EditsElement.PATH); v.visitStringUTF8( EditsElement.PATH);
v.visitStringUTF8( EditsElement.MTIME); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitStringUTF8( EditsElement.ATIME); v.visitLong(EditsElement.MTIME);
v.visitLong(EditsElement.ATIME);
} else {
v.visitStringUTF8(EditsElement.MTIME);
v.visitStringUTF8(EditsElement.ATIME);
}
} }
/** /**
@ -252,11 +287,16 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_RENAME() throws IOException { private void visit_OP_RENAME() throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitInt( EditsElement.LENGTH); v.visitInt(EditsElement.LENGTH);
}
v.visitStringUTF8( EditsElement.SOURCE); v.visitStringUTF8( EditsElement.SOURCE);
v.visitStringUTF8( EditsElement.DESTINATION); v.visitStringUTF8( EditsElement.DESTINATION);
v.visitStringUTF8( EditsElement.TIMESTAMP); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitLong(EditsElement.TIMESTAMP);
} else {
v.visitStringUTF8(EditsElement.TIMESTAMP);
}
v.visitBytesWritable( EditsElement.RENAME_OPTIONS); v.visitBytesWritable( EditsElement.RENAME_OPTIONS);
} }
@ -265,15 +305,25 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_CONCAT_DELETE() throws IOException { private void visit_OP_CONCAT_DELETE() throws IOException {
visitTxId(); visitTxId();
int sourceCount = 0;
IntToken lengthToken = v.visitInt(EditsElement.LENGTH); if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
IntToken lengthToken = v.visitInt(EditsElement.LENGTH);
sourceCount = lengthToken.value - 2;
}
v.visitStringUTF8(EditsElement.CONCAT_TARGET); v.visitStringUTF8(EditsElement.CONCAT_TARGET);
// all except of CONCAT_TARGET and TIMESTAMP // all except of CONCAT_TARGET and TIMESTAMP
int sourceCount = lengthToken.value - 2; if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
IntToken lengthToken = v.visitInt(EditsElement.LENGTH);
sourceCount = lengthToken.value;
}
for(int i = 0; i < sourceCount; i++) { for(int i = 0; i < sourceCount; i++) {
v.visitStringUTF8(EditsElement.CONCAT_SOURCE); v.visitStringUTF8(EditsElement.CONCAT_SOURCE);
} }
v.visitStringUTF8(EditsElement.TIMESTAMP); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitLong(EditsElement.TIMESTAMP);
} else {
v.visitStringUTF8(EditsElement.TIMESTAMP);
}
} }
/** /**
@ -281,12 +331,18 @@ class EditsLoaderCurrent implements EditsLoader {
*/ */
private void visit_OP_SYMLINK() throws IOException { private void visit_OP_SYMLINK() throws IOException {
visitTxId(); visitTxId();
if (!LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitInt( EditsElement.LENGTH); v.visitInt(EditsElement.LENGTH);
}
v.visitStringUTF8( EditsElement.SOURCE); v.visitStringUTF8( EditsElement.SOURCE);
v.visitStringUTF8( EditsElement.DESTINATION); v.visitStringUTF8( EditsElement.DESTINATION);
v.visitStringUTF8( EditsElement.MTIME); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitStringUTF8( EditsElement.ATIME); v.visitLong(EditsElement.MTIME);
v.visitLong(EditsElement.ATIME);
} else {
v.visitStringUTF8(EditsElement.MTIME);
v.visitStringUTF8(EditsElement.ATIME);
}
// PERMISSION_STATUS // PERMISSION_STATUS
v.visitEnclosingElement(EditsElement.PERMISSION_STATUS); v.visitEnclosingElement(EditsElement.PERMISSION_STATUS);
@ -303,15 +359,19 @@ class EditsLoaderCurrent implements EditsLoader {
private void visit_OP_GET_DELEGATION_TOKEN() throws IOException { private void visit_OP_GET_DELEGATION_TOKEN() throws IOException {
visitTxId(); visitTxId();
v.visitByte( EditsElement.T_VERSION); v.visitByte(EditsElement.T_VERSION);
v.visitStringText( EditsElement.T_OWNER); v.visitStringText(EditsElement.T_OWNER);
v.visitStringText( EditsElement.T_RENEWER); v.visitStringText(EditsElement.T_RENEWER);
v.visitStringText( EditsElement.T_REAL_USER); v.visitStringText(EditsElement.T_REAL_USER);
v.visitVLong( EditsElement.T_ISSUE_DATE); v.visitVLong(EditsElement.T_ISSUE_DATE);
v.visitVLong( EditsElement.T_MAX_DATE); v.visitVLong(EditsElement.T_MAX_DATE);
v.visitVInt( EditsElement.T_SEQUENCE_NUMBER); v.visitVInt(EditsElement.T_SEQUENCE_NUMBER);
v.visitVInt( EditsElement.T_MASTER_KEY_ID); v.visitVInt(EditsElement.T_MASTER_KEY_ID);
v.visitStringUTF8( EditsElement.T_EXPIRY_TIME); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitLong(EditsElement.T_EXPIRY_TIME);
} else {
v.visitStringUTF8(EditsElement.T_EXPIRY_TIME);
}
} }
/** /**
@ -321,15 +381,19 @@ class EditsLoaderCurrent implements EditsLoader {
throws IOException { throws IOException {
visitTxId(); visitTxId();
v.visitByte( EditsElement.T_VERSION); v.visitByte(EditsElement.T_VERSION);
v.visitStringText( EditsElement.T_OWNER); v.visitStringText(EditsElement.T_OWNER);
v.visitStringText( EditsElement.T_RENEWER); v.visitStringText(EditsElement.T_RENEWER);
v.visitStringText( EditsElement.T_REAL_USER); v.visitStringText(EditsElement.T_REAL_USER);
v.visitVLong( EditsElement.T_ISSUE_DATE); v.visitVLong(EditsElement.T_ISSUE_DATE);
v.visitVLong( EditsElement.T_MAX_DATE); v.visitVLong(EditsElement.T_MAX_DATE);
v.visitVInt( EditsElement.T_SEQUENCE_NUMBER); v.visitVInt(EditsElement.T_SEQUENCE_NUMBER);
v.visitVInt( EditsElement.T_MASTER_KEY_ID); v.visitVInt(EditsElement.T_MASTER_KEY_ID);
v.visitStringUTF8( EditsElement.T_EXPIRY_TIME); if (LayoutVersion.supports(Feature.EDITLOG_OP_OPTIMIZATION, editsVersion)) {
v.visitLong(EditsElement.T_EXPIRY_TIME);
} else {
v.visitStringUTF8(EditsElement.T_EXPIRY_TIME);
}
} }
/** /**

View File

@ -122,7 +122,7 @@ class ImageLoaderCurrent implements ImageLoader {
protected final DateFormat dateFormat = protected final DateFormat dateFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm"); new SimpleDateFormat("yyyy-MM-dd HH:mm");
private static int[] versions = { -16, -17, -18, -19, -20, -21, -22, -23, private static int[] versions = { -16, -17, -18, -19, -20, -21, -22, -23,
-24, -25, -26, -27, -28, -30, -31, -32, -33, -34, -35, -36, -37, -38}; -24, -25, -26, -27, -28, -30, -31, -32, -33, -34, -35, -36, -37, -38, -39};
private int imageVersion = 0; private int imageVersion = 0;
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -17,7 +17,10 @@
*/ */
package org.apache.hadoop.hdfs.server.namenode; package org.apache.hadoop.hdfs.server.namenode;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -29,7 +32,6 @@ import java.util.SortedMap;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;

View File

@ -41,7 +41,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.hdfs.tools.DFSAdmin;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;