HDFS-8179. DFSClient#getServerDefaults returns null within 1 hour of system start. (Contributed by Xiaoyu Yao)

This commit is contained in:
Arpit Agarwal 2015-04-20 15:42:42 -07:00
parent b493ec28a8
commit cc42ad03d9
5 changed files with 28 additions and 3 deletions

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.fs;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -33,6 +34,9 @@ import org.apache.hadoop.conf.Configured;
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Stable @InterfaceStability.Stable
public class Trash extends Configured { public class Trash extends Configured {
private static final org.apache.commons.logging.Log LOG =
LogFactory.getLog(Trash.class);
private TrashPolicy trashPolicy; // configured trash policy instance private TrashPolicy trashPolicy; // configured trash policy instance
/** /**
@ -84,6 +88,7 @@ public class Trash extends Configured {
} catch (Exception e) { } catch (Exception e) {
// If we can not determine that trash is enabled server side then // If we can not determine that trash is enabled server side then
// bail rather than potentially deleting a file when trash is enabled. // bail rather than potentially deleting a file when trash is enabled.
LOG.warn("Failed to get server trash configuration", e);
throw new IOException("Failed to get server trash configuration", e); throw new IOException("Failed to get server trash configuration", e);
} }
Trash trash = new Trash(fullyResolvedFs, conf); Trash trash = new Trash(fullyResolvedFs, conf);

View File

@ -134,11 +134,11 @@ public class TrashPolicyDefault extends TrashPolicy {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
try { try {
if (!fs.mkdirs(baseTrashPath, PERMISSION)) { // create current if (!fs.mkdirs(baseTrashPath, PERMISSION)) { // create current
LOG.warn("Can't create(mkdir) trash directory: "+baseTrashPath); LOG.warn("Can't create(mkdir) trash directory: " + baseTrashPath);
return false; return false;
} }
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Can't create trash directory: "+baseTrashPath); LOG.warn("Can't create trash directory: " + baseTrashPath, e);
cause = e; cause = e;
break; break;
} }

View File

@ -32,6 +32,9 @@ Release 2.7.1 - UNRELEASED
HDFS-8153. Error Message points to wrong parent directory in case of HDFS-8153. Error Message points to wrong parent directory in case of
path component name length error (Anu Engineer via jitendra) path component name length error (Anu Engineer via jitendra)
HDFS-8179. DFSClient#getServerDefaults returns null within 1
hour of system start. (Xiaoyu Yao via Arpit Agarwal)
Release 2.7.0 - UNRELEASED Release 2.7.0 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -1012,10 +1012,12 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory,
*/ */
public FsServerDefaults getServerDefaults() throws IOException { public FsServerDefaults getServerDefaults() throws IOException {
long now = Time.monotonicNow(); long now = Time.monotonicNow();
if (now - serverDefaultsLastUpdate > SERVER_DEFAULTS_VALIDITY_PERIOD) { if ((serverDefaults == null) ||
(now - serverDefaultsLastUpdate > SERVER_DEFAULTS_VALIDITY_PERIOD)) {
serverDefaults = namenode.getServerDefaults(); serverDefaults = namenode.getServerDefaults();
serverDefaultsLastUpdate = now; serverDefaultsLastUpdate = now;
} }
assert serverDefaults != null;
return serverDefaults; return serverDefaults;
} }

View File

@ -52,6 +52,7 @@ import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FsServerDefaults;
import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.fs.FileChecksum;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -1028,4 +1029,18 @@ public class TestDistributedFileSystem {
cluster.shutdown(); cluster.shutdown();
} }
} }
@Test(timeout=60000)
public void testGetServerDefaults() throws IOException {
Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
try {
cluster.waitActive();
DistributedFileSystem dfs = cluster.getFileSystem();
FsServerDefaults fsServerDefaults = dfs.getServerDefaults();
Assert.assertNotNull(fsServerDefaults);
} finally {
cluster.shutdown();
}
}
} }