HDFS-2226. Clean up counting of operations in FSEditLogLoader. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1154098 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2011-08-05 06:03:19 +00:00
parent acd3ab521f
commit a61b24a6da
3 changed files with 67 additions and 54 deletions

View File

@ -638,6 +638,8 @@ Trunk (unreleased changes)
HDFS-2108. Move datanode heartbeat handling from namenode package to HDFS-2108. Move datanode heartbeat handling from namenode package to
blockmanagement package. (szetszwo) blockmanagement package. (szetszwo)
HDFS-2226. Clean up counting of operations in FSEditLogLoader (todd)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

View File

@ -19,15 +19,13 @@ package org.apache.hadoop.hdfs.server.namenode;
import static org.apache.hadoop.hdfs.server.common.Util.now; import static org.apache.hadoop.hdfs.server.common.Util.now;
import java.io.BufferedInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream; import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.zip.Checksum; import java.util.EnumMap;
import org.apache.hadoop.fs.permission.PermissionStatus; import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.hdfs.protocol.FSConstants; import org.apache.hadoop.hdfs.protocol.FSConstants;
@ -38,8 +36,6 @@ 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.common.Storage; import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.namenode.EditLogFileInputStream.LogHeaderCorruptException; import org.apache.hadoop.hdfs.server.namenode.EditLogFileInputStream.LogHeaderCorruptException;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogLoader.EditLogValidation;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.Reader;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.AddCloseOp; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.AddCloseOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.CancelDelegationTokenOp; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.CancelDelegationTokenOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.ClearNSQuotaOp; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.ClearNSQuotaOp;
@ -61,8 +57,11 @@ import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.SymlinkOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.TimesOp; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.TimesOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.UpdateMasterKeyOp; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.UpdateMasterKeyOp;
import org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease; import org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease;
import org.apache.hadoop.hdfs.util.Holder;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import com.google.common.base.Joiner;
public class FSEditLogLoader { public class FSEditLogLoader {
private final FSNamesystem fsNamesys; private final FSNamesystem fsNamesys;
@ -110,13 +109,8 @@ public class FSEditLogLoader {
FSDirectory fsDir = fsNamesys.dir; FSDirectory fsDir = fsNamesys.dir;
int numEdits = 0; int numEdits = 0;
int numOpAdd = 0, numOpClose = 0, numOpDelete = 0, EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts =
numOpRenameOld = 0, numOpSetRepl = 0, numOpMkDir = 0, new EnumMap<FSEditLogOpCodes, Holder<Integer>>(FSEditLogOpCodes.class);
numOpSetPerm = 0, numOpSetOwner = 0, numOpSetGenStamp = 0,
numOpTimes = 0, numOpRename = 0, numOpConcatDelete = 0,
numOpSymlink = 0, numOpGetDelegationToken = 0,
numOpRenewDelegationToken = 0, numOpCancelDelegationToken = 0,
numOpUpdateMasterKey = 0, numOpReassignLease = 0, numOpOther = 0;
fsNamesys.writeLock(); fsNamesys.writeLock();
fsDir.writeLock(); fsDir.writeLock();
@ -142,6 +136,7 @@ public class FSEditLogLoader {
} }
numEdits++; numEdits++;
incrOpCount(op.opCode, opCounts);
switch (op.opCode) { switch (op.opCode) {
case OP_ADD: case OP_ADD:
case OP_CLOSE: { case OP_CLOSE: {
@ -201,7 +196,6 @@ public class FSEditLogLoader {
blocks, replication, blocks, replication,
addCloseOp.mtime, addCloseOp.atime, blockSize); addCloseOp.mtime, addCloseOp.atime, blockSize);
if (addCloseOp.opCode == FSEditLogOpCodes.OP_ADD) { if (addCloseOp.opCode == FSEditLogOpCodes.OP_ADD) {
numOpAdd++;
// //
// Replace current node with a INodeUnderConstruction. // Replace current node with a INodeUnderConstruction.
// Recreate in-memory lease record. // Recreate in-memory lease record.
@ -223,7 +217,6 @@ public class FSEditLogLoader {
break; break;
} }
case OP_SET_REPLICATION: { case OP_SET_REPLICATION: {
numOpSetRepl++;
SetReplicationOp setReplicationOp = (SetReplicationOp)op; SetReplicationOp setReplicationOp = (SetReplicationOp)op;
short replication short replication
= fsNamesys.adjustReplication(setReplicationOp.replication); = fsNamesys.adjustReplication(setReplicationOp.replication);
@ -232,15 +225,12 @@ public class FSEditLogLoader {
break; break;
} }
case OP_CONCAT_DELETE: { case OP_CONCAT_DELETE: {
numOpConcatDelete++;
ConcatDeleteOp concatDeleteOp = (ConcatDeleteOp)op; ConcatDeleteOp concatDeleteOp = (ConcatDeleteOp)op;
fsDir.unprotectedConcat(concatDeleteOp.trg, concatDeleteOp.srcs, fsDir.unprotectedConcat(concatDeleteOp.trg, concatDeleteOp.srcs,
concatDeleteOp.timestamp); concatDeleteOp.timestamp);
break; break;
} }
case OP_RENAME_OLD: { case OP_RENAME_OLD: {
numOpRenameOld++;
RenameOldOp renameOp = (RenameOldOp)op; RenameOldOp renameOp = (RenameOldOp)op;
HdfsFileStatus dinfo = fsDir.getFileInfo(renameOp.dst, false); HdfsFileStatus dinfo = fsDir.getFileInfo(renameOp.dst, false);
fsDir.unprotectedRenameTo(renameOp.src, renameOp.dst, fsDir.unprotectedRenameTo(renameOp.src, renameOp.dst,
@ -249,14 +239,11 @@ public class FSEditLogLoader {
break; break;
} }
case OP_DELETE: { case OP_DELETE: {
numOpDelete++;
DeleteOp deleteOp = (DeleteOp)op; DeleteOp deleteOp = (DeleteOp)op;
fsDir.unprotectedDelete(deleteOp.path, deleteOp.timestamp); fsDir.unprotectedDelete(deleteOp.path, deleteOp.timestamp);
break; break;
} }
case OP_MKDIR: { case OP_MKDIR: {
numOpMkDir++;
MkdirOp mkdirOp = (MkdirOp)op; MkdirOp mkdirOp = (MkdirOp)op;
PermissionStatus permissions = fsNamesys.getUpgradePermission(); PermissionStatus permissions = fsNamesys.getUpgradePermission();
if (mkdirOp.permissions != null) { if (mkdirOp.permissions != null) {
@ -268,22 +255,17 @@ public class FSEditLogLoader {
break; break;
} }
case OP_SET_GENSTAMP: { case OP_SET_GENSTAMP: {
numOpSetGenStamp++;
SetGenstampOp setGenstampOp = (SetGenstampOp)op; SetGenstampOp setGenstampOp = (SetGenstampOp)op;
fsNamesys.setGenerationStamp(setGenstampOp.genStamp); fsNamesys.setGenerationStamp(setGenstampOp.genStamp);
break; break;
} }
case OP_SET_PERMISSIONS: { case OP_SET_PERMISSIONS: {
numOpSetPerm++;
SetPermissionsOp setPermissionsOp = (SetPermissionsOp)op; SetPermissionsOp setPermissionsOp = (SetPermissionsOp)op;
fsDir.unprotectedSetPermission(setPermissionsOp.src, fsDir.unprotectedSetPermission(setPermissionsOp.src,
setPermissionsOp.permissions); setPermissionsOp.permissions);
break; break;
} }
case OP_SET_OWNER: { case OP_SET_OWNER: {
numOpSetOwner++;
SetOwnerOp setOwnerOp = (SetOwnerOp)op; SetOwnerOp setOwnerOp = (SetOwnerOp)op;
fsDir.unprotectedSetOwner(setOwnerOp.src, setOwnerOp.username, fsDir.unprotectedSetOwner(setOwnerOp.src, setOwnerOp.username,
setOwnerOp.groupname); setOwnerOp.groupname);
@ -312,7 +294,6 @@ public class FSEditLogLoader {
break; break;
case OP_TIMES: { case OP_TIMES: {
numOpTimes++;
TimesOp timesOp = (TimesOp)op; TimesOp timesOp = (TimesOp)op;
fsDir.unprotectedSetTimes(timesOp.path, fsDir.unprotectedSetTimes(timesOp.path,
@ -321,8 +302,6 @@ public class FSEditLogLoader {
break; break;
} }
case OP_SYMLINK: { case OP_SYMLINK: {
numOpSymlink++;
SymlinkOp symlinkOp = (SymlinkOp)op; SymlinkOp symlinkOp = (SymlinkOp)op;
fsDir.unprotectedSymlink(symlinkOp.path, symlinkOp.value, fsDir.unprotectedSymlink(symlinkOp.path, symlinkOp.value,
symlinkOp.mtime, symlinkOp.atime, symlinkOp.mtime, symlinkOp.atime,
@ -330,7 +309,6 @@ public class FSEditLogLoader {
break; break;
} }
case OP_RENAME: { case OP_RENAME: {
numOpRename++;
RenameOp renameOp = (RenameOp)op; RenameOp renameOp = (RenameOp)op;
HdfsFileStatus dinfo = fsDir.getFileInfo(renameOp.dst, false); HdfsFileStatus dinfo = fsDir.getFileInfo(renameOp.dst, false);
@ -340,7 +318,6 @@ public class FSEditLogLoader {
break; break;
} }
case OP_GET_DELEGATION_TOKEN: { case OP_GET_DELEGATION_TOKEN: {
numOpGetDelegationToken++;
GetDelegationTokenOp getDelegationTokenOp GetDelegationTokenOp getDelegationTokenOp
= (GetDelegationTokenOp)op; = (GetDelegationTokenOp)op;
@ -350,8 +327,6 @@ public class FSEditLogLoader {
break; break;
} }
case OP_RENEW_DELEGATION_TOKEN: { case OP_RENEW_DELEGATION_TOKEN: {
numOpRenewDelegationToken++;
RenewDelegationTokenOp renewDelegationTokenOp RenewDelegationTokenOp renewDelegationTokenOp
= (RenewDelegationTokenOp)op; = (RenewDelegationTokenOp)op;
fsNamesys.getDelegationTokenSecretManager() fsNamesys.getDelegationTokenSecretManager()
@ -360,8 +335,6 @@ public class FSEditLogLoader {
break; break;
} }
case OP_CANCEL_DELEGATION_TOKEN: { case OP_CANCEL_DELEGATION_TOKEN: {
numOpCancelDelegationToken++;
CancelDelegationTokenOp cancelDelegationTokenOp CancelDelegationTokenOp cancelDelegationTokenOp
= (CancelDelegationTokenOp)op; = (CancelDelegationTokenOp)op;
fsNamesys.getDelegationTokenSecretManager() fsNamesys.getDelegationTokenSecretManager()
@ -370,14 +343,12 @@ public class FSEditLogLoader {
break; break;
} }
case OP_UPDATE_MASTER_KEY: { case OP_UPDATE_MASTER_KEY: {
numOpUpdateMasterKey++;
UpdateMasterKeyOp updateMasterKeyOp = (UpdateMasterKeyOp)op; UpdateMasterKeyOp updateMasterKeyOp = (UpdateMasterKeyOp)op;
fsNamesys.getDelegationTokenSecretManager() fsNamesys.getDelegationTokenSecretManager()
.updatePersistedMasterKey(updateMasterKeyOp.key); .updatePersistedMasterKey(updateMasterKeyOp.key);
break; break;
} }
case OP_REASSIGN_LEASE: { case OP_REASSIGN_LEASE: {
numOpReassignLease++;
ReassignLeaseOp reassignLeaseOp = (ReassignLeaseOp)op; ReassignLeaseOp reassignLeaseOp = (ReassignLeaseOp)op;
Lease lease = fsNamesys.leaseManager.getLease( Lease lease = fsNamesys.leaseManager.getLease(
@ -392,17 +363,16 @@ public class FSEditLogLoader {
case OP_START_LOG_SEGMENT: case OP_START_LOG_SEGMENT:
case OP_END_LOG_SEGMENT: { case OP_END_LOG_SEGMENT: {
// no data in here currently. // no data in here currently.
numOpOther++;
break; break;
} }
case OP_DATANODE_ADD: case OP_DATANODE_ADD:
case OP_DATANODE_REMOVE: case OP_DATANODE_REMOVE:
numOpOther++;
break; break;
default: default:
throw new IOException("Invalid operation read " + op.opCode); throw new IOException("Invalid operation read " + op.opCode);
} }
} }
} catch (IOException ex) { } catch (IOException ex) {
check203UpgradeFailure(logVersion, ex); check203UpgradeFailure(logVersion, ex);
} finally { } finally {
@ -431,26 +401,31 @@ public class FSEditLogLoader {
fsNamesys.writeUnlock(); fsNamesys.writeUnlock();
} }
if (FSImage.LOG.isDebugEnabled()) { if (FSImage.LOG.isDebugEnabled()) {
FSImage.LOG.debug("numOpAdd = " + numOpAdd + " numOpClose = " + numOpClose dumpOpCounts(opCounts);
+ " numOpDelete = " + numOpDelete
+ " numOpRenameOld = " + numOpRenameOld
+ " numOpSetRepl = " + numOpSetRepl + " numOpMkDir = " + numOpMkDir
+ " numOpSetPerm = " + numOpSetPerm
+ " numOpSetOwner = " + numOpSetOwner
+ " numOpSetGenStamp = " + numOpSetGenStamp
+ " numOpTimes = " + numOpTimes
+ " numOpConcatDelete = " + numOpConcatDelete
+ " numOpRename = " + numOpRename
+ " numOpGetDelegationToken = " + numOpGetDelegationToken
+ " numOpRenewDelegationToken = " + numOpRenewDelegationToken
+ " numOpCancelDelegationToken = " + numOpCancelDelegationToken
+ " numOpUpdateMasterKey = " + numOpUpdateMasterKey
+ " numOpReassignLease = " + numOpReassignLease
+ " numOpOther = " + numOpOther);
} }
return numEdits; return numEdits;
} }
private static void dumpOpCounts(
EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts) {
StringBuilder sb = new StringBuilder();
sb.append("Summary of operations loaded from edit log:\n ");
Joiner.on("\n ").withKeyValueSeparator("=").appendTo(sb, opCounts);
FSImage.LOG.debug(sb.toString());
}
private void incrOpCount(FSEditLogOpCodes opCode,
EnumMap<FSEditLogOpCodes, Holder<Integer>> opCounts) {
Holder<Integer> holder = opCounts.get(opCode);
if (holder == null) {
holder = new Holder<Integer>(1);
opCounts.put(opCode, holder);
} else {
holder.held++;
}
}
/** /**
* Throw appropriate exception during upgrade from 203, when editlog loading * Throw appropriate exception during upgrade from 203, when editlog loading
* could fail due to opcode conflicts. * could fail due to opcode conflicts.

View File

@ -0,0 +1,36 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdfs.util;
/**
* A Holder is simply a wrapper around some other object. This is useful
* in particular for storing immutable values like boxed Integers in a
* collection without having to do the &quot;lookup&quot; of the value twice.
*/
public class Holder<T> {
public T held;
public Holder(T held) {
this.held = held;
}
@Override
public String toString() {
return String.valueOf(held);
}
}