Skip to content

Commit

Permalink
HDFS-14256. Review Logging of NameNode Class. Contributed by David Mo…
Browse files Browse the repository at this point in the history
…llitor.
  • Loading branch information
Inigo Goiri committed Aug 29, 2019
1 parent ffca734 commit 3b22fcd
Showing 1 changed file with 20 additions and 30 deletions.
Expand Up @@ -111,6 +111,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.TreeSet;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -1034,7 +1035,7 @@ public void join() {
try {
rpcServer.join();
} catch (InterruptedException ie) {
LOG.info("Caught interrupted exception ", ie);
LOG.info("Caught interrupted exception", ie);
}
}

Expand All @@ -1052,7 +1053,7 @@ public void stop() {
state.exitState(haContext);
}
} catch (ServiceFailedException e) {
LOG.warn("Encountered exception while exiting state ", e);
LOG.warn("Encountered exception while exiting state", e);
} finally {
stopMetricsLogger();
stopCommonServices();
Expand Down Expand Up @@ -1211,7 +1212,8 @@ private static boolean format(Configuration conf, boolean force,
//Generate a new cluster id
clusterId = NNStorage.newClusterID();
}
System.out.println("Formatting using clusterid: " + clusterId);

LOG.info("Formatting using clusterid: {}", clusterId);

FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat);
try {
Expand Down Expand Up @@ -1239,7 +1241,7 @@ private static boolean format(Configuration conf, boolean force,

fsImage.format(fsn, clusterId, force);
} catch (IOException ioe) {
LOG.warn("Encountered exception during format: ", ioe);
LOG.warn("Encountered exception during format", ioe);
fsImage.close();
throw ioe;
}
Expand Down Expand Up @@ -1400,13 +1402,11 @@ private static void copyEditLogSegmentsToSharedDir(FSNamesystem fsns,

// Copy all edits after last CheckpointTxId to shared edits dir
for (EditLogInputStream stream : streams) {
LOG.debug("Beginning to copy stream " + stream + " to shared edits");
LOG.debug("Beginning to copy stream {} to shared edits", stream);
FSEditLogOp op;
boolean segmentOpen = false;
while ((op = stream.readOp()) != null) {
if (LOG.isTraceEnabled()) {
LOG.trace("copying op: " + op);
}
LOG.trace("copying op: {}", op);
if (!segmentOpen) {
newSharedEditLog.startLogSegment(op.txid, false,
fsns.getEffectiveLayoutVersion());
Expand All @@ -1417,14 +1417,15 @@ private static void copyEditLogSegmentsToSharedDir(FSNamesystem fsns,

if (op.opCode == FSEditLogOpCodes.OP_END_LOG_SEGMENT) {
newSharedEditLog.endCurrentLogSegment(false);
LOG.debug("ending log segment because of END_LOG_SEGMENT op in "
+ stream);
LOG.debug("ending log segment because of END_LOG_SEGMENT op in {}",
stream);
segmentOpen = false;
}
}

if (segmentOpen) {
LOG.debug("ending log segment because of end of stream in " + stream);
LOG.debug("ending log segment because of end of stream in {}",
stream);
newSharedEditLog.logSync();
newSharedEditLog.endCurrentLogSegment(false);
segmentOpen = false;
Expand Down Expand Up @@ -1541,7 +1542,7 @@ static StartupOption parseArguments(String args[]) {
i += 1;
}
} else {
LOG.error("Unknown upgrade flag " + flag);
LOG.error("Unknown upgrade flag: {}", flag);
return null;
}
}
Expand Down Expand Up @@ -1685,8 +1686,8 @@ public static NameNode createNameNode(String argv[], Configuration conf)
terminate(aborted ? 1 : 0);
return null; // avoid javac warning
case GENCLUSTERID:
System.err.println("Generating new cluster id:");
System.out.println(NNStorage.newClusterID());
String clusterID = NNStorage.newClusterID();
LOG.info("Generated new cluster id: {}", clusterID);
terminate(0);
return null;
case ROLLBACK:
Expand Down Expand Up @@ -1767,9 +1768,7 @@ public static void initializeGenericKeys(Configuration conf,
URI defaultUri = URI.create(HdfsConstants.HDFS_URI_SCHEME + "://"
+ conf.get(DFS_NAMENODE_RPC_ADDRESS_KEY));
conf.set(FS_DEFAULT_NAME_KEY, defaultUri.toString());
if (LOG.isDebugEnabled()) {
LOG.debug("Setting " + FS_DEFAULT_NAME_KEY + " to " + defaultUri.toString());
}
LOG.debug("Setting {} to {}", FS_DEFAULT_NAME_KEY, defaultUri);
}
}

Expand Down Expand Up @@ -1906,22 +1905,14 @@ private void registerNNSMXBean() {

@Override // NameNodeStatusMXBean
public String getNNRole() {
String roleStr = "";
NamenodeRole role = getRole();
if (null != role) {
roleStr = role.toString();
}
return roleStr;
return Objects.toString(role, "");
}

@Override // NameNodeStatusMXBean
public String getState() {
String servStateStr = "";
HAServiceState servState = getServiceState();
if (null != servState) {
servStateStr = servState.toString();
}
return servStateStr;
return Objects.toString(servState, "");
}

@Override // NameNodeStatusMXBean
Expand Down Expand Up @@ -1967,10 +1958,9 @@ public String getSlowDisksReport() {
*/
protected synchronized void doImmediateShutdown(Throwable t)
throws ExitException {
String message = "Error encountered requiring NN shutdown. " +
"Shutting down immediately.";
try {
LOG.error(message, t);
LOG.error("Error encountered requiring NN shutdown. " +
"Shutting down immediately.", t);
} catch (Throwable ignored) {
// This is unlikely to happen, but there's nothing we can do if it does.
}
Expand Down

0 comments on commit 3b22fcd

Please sign in to comment.