HDFS-3487. offlineimageviewer should give byte offset information when it encounters an exception. Contributed by Colin Patrick McCabe

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1344972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2012-06-01 02:37:09 +00:00
parent 4eb6d65eef
commit f343419055
3 changed files with 28 additions and 12 deletions

View File

@ -276,6 +276,9 @@ Release 2.0.1-alpha - UNRELEASED
HDFS-3486. offlineimageviewer can't read fsimage files that contain HDFS-3486. offlineimageviewer can't read fsimage files that contain
persistent delegation tokens. (Colin Patrick McCabe via eli) persistent delegation tokens. (Colin Patrick McCabe via eli)
HDFS-3487. offlineimageviewer should give byte offset information
when it encounters an exception. (Colin Patrick McCabe via eli)
Release 2.0.0-alpha - UNRELEASED Release 2.0.0-alpha - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -145,6 +145,7 @@ public boolean canLoadVersion(int version) {
@Override @Override
public void loadImage(DataInputStream in, ImageVisitor v, public void loadImage(DataInputStream in, ImageVisitor v,
boolean skipBlocks) throws IOException { boolean skipBlocks) throws IOException {
boolean done = false;
try { try {
v.start(); v.start();
v.visitEnclosingElement(ImageElement.FS_IMAGE); v.visitEnclosingElement(ImageElement.FS_IMAGE);
@ -189,11 +190,13 @@ public void loadImage(DataInputStream in, ImageVisitor v,
} }
v.leaveEnclosingElement(); // FSImage v.leaveEnclosingElement(); // FSImage
done = true;
} finally {
if (done) {
v.finish(); v.finish();
} catch(IOException e) { } else {
// Tell the visitor to clean up, then re-throw the exception
v.finishAbnormally(); v.finishAbnormally();
throw e; }
} }
} }

View File

@ -30,8 +30,12 @@
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser; import org.apache.commons.cli.PosixParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogLoader.PositionTrackingInputStream;
/** /**
* OfflineImageViewer to dump the contents of an Hadoop image file to XML * OfflineImageViewer to dump the contents of an Hadoop image file to XML
@ -40,6 +44,8 @@
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public class OfflineImageViewer { public class OfflineImageViewer {
public static final Log LOG = LogFactory.getLog(OfflineImageViewer.class);
private final static String usage = private final static String usage =
"Usage: bin/hdfs oiv [OPTIONS] -i INPUTFILE -o OUTPUTFILE\n" + "Usage: bin/hdfs oiv [OPTIONS] -i INPUTFILE -o OUTPUTFILE\n" +
"Offline Image Viewer\n" + "Offline Image Viewer\n" +
@ -112,24 +118,28 @@ public OfflineImageViewer(String inputFile, ImageVisitor processor,
*/ */
public void go() throws IOException { public void go() throws IOException {
DataInputStream in = null; DataInputStream in = null;
PositionTrackingInputStream tracker = null;
ImageLoader fsip = null;
boolean done = false;
try { try {
in = new DataInputStream(new BufferedInputStream( tracker = new PositionTrackingInputStream(new BufferedInputStream(
new FileInputStream(new File(inputFile)))); new FileInputStream(new File(inputFile))));
in = new DataInputStream(tracker);
int imageVersionFile = findImageVersion(in); int imageVersionFile = findImageVersion(in);
ImageLoader fsip = fsip = ImageLoader.LoaderFactory.getLoader(imageVersionFile);
ImageLoader.LoaderFactory.getLoader(imageVersionFile);
if(fsip == null) if(fsip == null)
throw new IOException("No image processor to read version " + throw new IOException("No image processor to read version " +
imageVersionFile + " is available."); imageVersionFile + " is available.");
fsip.loadImage(in, processor, skipBlocks); fsip.loadImage(in, processor, skipBlocks);
done = true;
} finally { } finally {
if(in != null) in.close(); if (!done) {
LOG.error("image loading failed at offset " + tracker.getPos());
}
IOUtils.cleanup(LOG, in, tracker);
} }
} }