HDFS-10264. Logging improvements in FSImageFormatProtobuf.Saver. (Contributed by Xiaobing Zhou)

This commit is contained in:
Arpit Agarwal 2016-04-19 11:26:30 -07:00
parent 90d1af1416
commit af9bdbe447

View File

@ -18,6 +18,8 @@
package org.apache.hadoop.hdfs.server.namenode; package org.apache.hadoop.hdfs.server.namenode;
import static org.apache.hadoop.util.Time.monotonicNow;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -38,8 +40,8 @@
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.Log; import org.slf4j.Logger;
import org.apache.commons.logging.LogFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CacheDirectiveInfoProto; import org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.CacheDirectiveInfoProto;
@ -74,7 +76,8 @@
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public final class FSImageFormatProtobuf { public final class FSImageFormatProtobuf {
private static final Log LOG = LogFactory.getLog(FSImageFormatProtobuf.class); private static final Logger LOG = LoggerFactory
.getLogger(FSImageFormatProtobuf.class);
public static final class LoaderContext { public static final class LoaderContext {
private String[] stringTable; private String[] stringTable;
@ -179,7 +182,7 @@ void load(File file) throws IOException {
try { try {
loadInternal(raFile, fin); loadInternal(raFile, fin);
long end = Time.monotonicNow(); long end = Time.monotonicNow();
LOG.info("Loaded FSImage in " + (end - start) / 1000 + " seconds."); LOG.info("Loaded FSImage in {} seconds.", (end - start) / 1000);
} finally { } finally {
fin.close(); fin.close();
raFile.close(); raFile.close();
@ -285,7 +288,7 @@ public int compare(FileSummary.Section s1, FileSummary.Section s2) {
} }
break; break;
default: default:
LOG.warn("Unrecognized section " + n); LOG.warn("Unrecognized section {}", n);
break; break;
} }
} }
@ -423,7 +426,11 @@ void save(File file, FSImageCompression compression) throws IOException {
FileOutputStream fout = new FileOutputStream(file); FileOutputStream fout = new FileOutputStream(file);
fileChannel = fout.getChannel(); fileChannel = fout.getChannel();
try { try {
LOG.info("Saving image file {} using {}", file, compression);
long startTime = monotonicNow();
saveInternal(fout, compression, file.getAbsolutePath()); saveInternal(fout, compression, file.getAbsolutePath());
LOG.info("Image file {} of size {} bytes saved in {} seconds.", file,
file.length(), (monotonicNow() - startTime) / 1000);
} finally { } finally {
fout.close(); fout.close();
} }