HDFS-10903. Replace config key literal strings with config key names II: hadoop hdfs. Contributed by Chen Liang

This commit is contained in:
Mingliang Liu 2016-10-11 16:29:30 -07:00
parent 61f0490a73
commit 3c9a01062e
6 changed files with 26 additions and 6 deletions

View File

@ -48,6 +48,9 @@
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import static org.apache.hadoop.hdfs.DFSConfigKeys.HTTPFS_BUFFER_SIZE_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.HTTP_BUFFER_SIZE_DEFAULT;
/** /**
* FileSystem operation executors used by {@link HttpFSServer}. * FileSystem operation executors used by {@link HttpFSServer}.
*/ */
@ -462,7 +465,8 @@ public Void execute(FileSystem fs) throws IOException {
blockSize = fs.getDefaultBlockSize(path); blockSize = fs.getDefaultBlockSize(path);
} }
FsPermission fsPermission = new FsPermission(permission); FsPermission fsPermission = new FsPermission(permission);
int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096); int bufferSize = fs.getConf().getInt(HTTPFS_BUFFER_SIZE_KEY,
HTTP_BUFFER_SIZE_DEFAULT);
OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication, blockSize, null); OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication, blockSize, null);
IOUtils.copyBytes(is, os, bufferSize, true); IOUtils.copyBytes(is, os, bufferSize, true);
os.close(); os.close();
@ -752,7 +756,8 @@ public FSOpen(String path) {
*/ */
@Override @Override
public InputStream execute(FileSystem fs) throws IOException { public InputStream execute(FileSystem fs) throws IOException {
int bufferSize = HttpFSServerWebApp.get().getConfig().getInt("httpfs.buffer.size", 4096); int bufferSize = HttpFSServerWebApp.get().getConfig().getInt(
HTTPFS_BUFFER_SIZE_KEY, HTTP_BUFFER_SIZE_DEFAULT);
return fs.open(path, bufferSize); return fs.open(path, bufferSize);
} }

View File

@ -50,6 +50,8 @@
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
@InterfaceAudience.Private @InterfaceAudience.Private
public class FileSystemAccessService extends BaseService implements FileSystemAccess { public class FileSystemAccessService extends BaseService implements FileSystemAccess {
private static final Logger LOG = LoggerFactory.getLogger(FileSystemAccessService.class); private static final Logger LOG = LoggerFactory.getLogger(FileSystemAccessService.class);
@ -159,7 +161,7 @@ protected void init() throws ServiceException {
throw new ServiceException(FileSystemAccessException.ERROR.H01, KERBEROS_PRINCIPAL); throw new ServiceException(FileSystemAccessException.ERROR.H01, KERBEROS_PRINCIPAL);
} }
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "kerberos"); conf.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos");
UserGroupInformation.setConfiguration(conf); UserGroupInformation.setConfiguration(conf);
try { try {
UserGroupInformation.loginUserFromKeytab(principal, keytab); UserGroupInformation.loginUserFromKeytab(principal, keytab);
@ -169,7 +171,7 @@ protected void init() throws ServiceException {
LOG.info("Using FileSystemAccess Kerberos authentication, principal [{}] keytab [{}]", principal, keytab); LOG.info("Using FileSystemAccess Kerberos authentication, principal [{}] keytab [{}]", principal, keytab);
} else if (security.equals("simple")) { } else if (security.equals("simple")) {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "simple"); conf.set(HADOOP_SECURITY_AUTHENTICATION, "simple");
UserGroupInformation.setConfiguration(conf); UserGroupInformation.setConfiguration(conf);
LOG.info("Using FileSystemAccess simple/pseudo authentication, principal [{}]", System.getProperty("user.name")); LOG.info("Using FileSystemAccess simple/pseudo authentication, principal [{}]", System.getProperty("user.name"));
} else { } else {

View File

@ -992,6 +992,9 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
"dfs.disk.balancer.plan.threshold.percent"; "dfs.disk.balancer.plan.threshold.percent";
public static final int DFS_DISK_BALANCER_PLAN_THRESHOLD_DEFAULT = 10; public static final int DFS_DISK_BALANCER_PLAN_THRESHOLD_DEFAULT = 10;
public static final String HTTPFS_BUFFER_SIZE_KEY =
"httpfs.buffer.size";
public static final int HTTP_BUFFER_SIZE_DEFAULT = 4096;
// dfs.client.retry confs are moved to HdfsClientConfigKeys.Retry // dfs.client.retry confs are moved to HdfsClientConfigKeys.Retry
@Deprecated @Deprecated

View File

@ -4273,4 +4273,12 @@
consecutive warnings within this interval.</description> consecutive warnings within this interval.</description>
</property> </property>
<property>
<name>httpfs.buffer.size</name>
<value>4096</value>
<description>
The size buffer to be used when creating or opening httpfs filesystem IO stream.
</description>
</property>
</configuration> </configuration>

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -89,7 +90,7 @@ public void setUp() throws Exception {
// handle failures in the DFSClient pipeline quickly // handle failures in the DFSClient pipeline quickly
// (for cluster.shutdown(); fs.close() idiom) // (for cluster.shutdown(); fs.close() idiom)
conf.setInt("ipc.client.connect.max.retries", 1); conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
} }
/* /*

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.hdfs.server.blockmanagement; package org.apache.hadoop.hdfs.server.blockmanagement;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -218,7 +219,7 @@ protected Configuration getConf(int numDataNodes) {
conf.setInt("io.bytes.per.checksum", BLOCK_SIZE); conf.setInt("io.bytes.per.checksum", BLOCK_SIZE);
conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1); conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1);
conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, numDataNodes); conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, numDataNodes);
conf.setInt("ipc.client.connect.max.retries", 0); conf.setInt(IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 0);
// Set short retry timeouts so this test runs faster // Set short retry timeouts so this test runs faster
conf.setInt(HdfsClientConfigKeys.Retry.WINDOW_BASE_KEY, 10); conf.setInt(HdfsClientConfigKeys.Retry.WINDOW_BASE_KEY, 10);
return conf; return conf;