Skip to content

Commit

Permalink
HDFS-11696. Fix warnings from Spotbugs in hadoop-hdfs. Contributed by…
Browse files Browse the repository at this point in the history
… Yiqun Lin.
  • Loading branch information
aajisaka committed May 16, 2017
1 parent 9b90e52 commit 89a8edc
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2857,9 +2857,12 @@ private void initThreadsNumForStripedReads(int numThreads) {
}
synchronized (DFSClient.class) {
if (STRIPED_READ_THREAD_POOL == null) {
STRIPED_READ_THREAD_POOL = DFSUtilClient.getThreadPoolExecutor(1,
// Only after thread pool is fully constructed then save it to
// volatile field.
ThreadPoolExecutor threadPool = DFSUtilClient.getThreadPoolExecutor(1,
numThreads, 60, "StripedRead-", true);
STRIPED_READ_THREAD_POOL.allowCoreThreadTimeOut(true);
threadPool.allowCoreThreadTimeOut(true);
STRIPED_READ_THREAD_POOL = threadPool;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public boolean equals(Object o) {
}

boolean areEqual;
for (String disk : this.slowDisks.keySet()) {
if (!this.slowDisks.get(disk).equals(that.slowDisks.get(disk))) {
for (Map.Entry<String, Map<DiskOp, Double>> entry : this.slowDisks
.entrySet()) {
if (!entry.getValue().equals(that.slowDisks.get(entry.getKey()))) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,9 @@
<Class name="org.apache.hadoop.hdfs.server.datanode.checker.AbstractFuture" />
<Bug pattern="NS_DANGEROUS_NON_SHORT_CIRCUIT" />
</Match>
<Match>
<Class name="org.apache.hadoop.hdfs.server.namenode.NNUpgradeUtil$1" />
<Method name="visitFile" />
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,18 @@ public boolean accept(File file) {
return file.isDirectory();
}
});
for (File journalDir : journalDirs) {
String jid = journalDir.getName();
if (!status.containsKey(jid)) {
Map<String, String> jMap = new HashMap<String, String>();
jMap.put("Formatted", "true");
status.put(jid, jMap);

if (journalDirs != null) {
for (File journalDir : journalDirs) {
String jid = journalDir.getName();
if (!status.containsKey(jid)) {
Map<String, String> jMap = new HashMap<String, String>();
jMap.put("Formatted", "true");
status.put(jid, jMap);
}
}
}

return JSON.toString(status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ public NamenodeRole toNodeRole() {
return NamenodeRole.NAMENODE;
}
}

public void setClusterId(String cid) {
Preconditions.checkState(this == UPGRADE || this == UPGRADEONLY
|| this == FORMAT);
clusterId = cid;
}

Expand All @@ -214,6 +216,7 @@ public MetaRecoveryContext createRecoveryContext() {
}

public void setForce(int force) {
Preconditions.checkState(this == RECOVER);
this.force = force;
}

Expand All @@ -226,6 +229,7 @@ public boolean getForceFormat() {
}

public void setForceFormat(boolean force) {
Preconditions.checkState(this == FORMAT);
isForceFormat = force;
}

Expand All @@ -234,6 +238,7 @@ public boolean getInteractiveFormat() {
}

public void setInteractiveFormat(boolean interactive) {
Preconditions.checkState(this == FORMAT);
isInteractiveFormat = interactive;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,10 +1336,14 @@ public boolean accept(File dir, String name) {
return name.startsWith(BLOCK_SUBDIR_PREFIX);
}
});
for(int i = 0; i < otherNames.length; i++)
linkBlocksHelper(new File(from, otherNames[i]),
new File(to, otherNames[i]), oldLV, hl, upgradeToIdBasedLayout,
blockRoot, idBasedLayoutSingleLinks);

if (otherNames != null) {
for (int i = 0; i < otherNames.length; i++) {
linkBlocksHelper(new File(from, otherNames[i]),
new File(to, otherNames[i]), oldLV, hl, upgradeToIdBasedLayout,
blockRoot, idBasedLayoutSingleLinks);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,27 @@ public boolean accept(File dir, String name) {
});

// Check whether there is any work to do.
if (filesInStorage.length <= numCheckpointsToRetain) {
if (filesInStorage != null
&& filesInStorage.length <= numCheckpointsToRetain) {
return;
}

// Create a sorted list of txids from the file names.
TreeSet<Long> sortedTxIds = new TreeSet<Long>();
for (String fName : filesInStorage) {
// Extract the transaction id from the file name.
long fTxId;
try {
fTxId = Long.parseLong(fName.substring(oivImagePrefix.length() + 1));
} catch (NumberFormatException nfe) {
// This should not happen since we have already filtered it.
// Log and continue.
LOG.warn("Invalid file name. Skipping " + fName);
continue;
if (filesInStorage != null) {
for (String fName : filesInStorage) {
// Extract the transaction id from the file name.
long fTxId;
try {
fTxId = Long.parseLong(fName.substring(oivImagePrefix.length() + 1));
} catch (NumberFormatException nfe) {
// This should not happen since we have already filtered it.
// Log and continue.
LOG.warn("Invalid file name. Skipping " + fName);
continue;
}
sortedTxIds.add(Long.valueOf(fTxId));
}
sortedTxIds.add(Long.valueOf(fTxId));
}

int numFilesToDelete = sortedTxIds.size() - numCheckpointsToRetain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ public int run(String[] argv) throws Exception {
return exitCode;
}
} else if ("-report".equals(cmd)) {
if (argv.length < 1) {
if (argv.length > 4) {
printUsage(cmd);
return exitCode;
}
Expand Down Expand Up @@ -1947,7 +1947,7 @@ public int run(String[] argv) throws Exception {
return exitCode;
}
} else if (RollingUpgradeCommand.matches(cmd)) {
if (argv.length < 1 || argv.length > 2) {
if (argv.length > 2) {
printUsage(cmd);
return exitCode;
}
Expand Down Expand Up @@ -2022,7 +2022,7 @@ public int run(String[] argv) throws Exception {
return exitCode;
}
} else if ("-triggerBlockReport".equals(cmd)) {
if (argv.length < 1) {
if ((argv.length != 2) && (argv.length != 3)) {
printUsage(cmd);
return exitCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,13 @@ private void processINode(DataInputStream in, ImageVisitor v,
if (supportSnapshot && supportInodeId) {
dirNodeMap.put(inodeId, pathName);
}
v.visit(ImageElement.NS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
if (NameNodeLayoutVersion.supports(Feature.DISKSPACE_QUOTA, imageVersion))
v.visit(ImageElement.DS_QUOTA, numBlocks == -1 ? in.readLong() : -1);

v.visit(ImageElement.NS_QUOTA, in.readLong());
if (NameNodeLayoutVersion.supports(Feature.DISKSPACE_QUOTA,
imageVersion)) {
v.visit(ImageElement.DS_QUOTA, in.readLong());
}

if (supportSnapshot) {
boolean snapshottable = in.readBoolean();
if (!snapshottable) {
Expand Down

0 comments on commit 89a8edc

Please sign in to comment.