|
@@ -32,9 +32,12 @@ import javax.servlet.http.HttpServletResponse;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.http.HttpConfig;
|
|
import org.apache.hadoop.http.HttpConfig;
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
import org.apache.hadoop.util.Time;
|
|
import org.apache.hadoop.util.Time;
|
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
|
+import org.apache.hadoop.hdfs.HdfsConfiguration;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
import org.apache.hadoop.hdfs.server.common.StorageErrorReporter;
|
|
import org.apache.hadoop.hdfs.server.common.StorageErrorReporter;
|
|
import org.apache.hadoop.hdfs.server.common.Storage;
|
|
import org.apache.hadoop.hdfs.server.common.Storage;
|
|
@@ -43,6 +46,7 @@ import org.apache.hadoop.hdfs.server.protocol.RemoteEditLog;
|
|
import org.apache.hadoop.hdfs.util.DataTransferThrottler;
|
|
import org.apache.hadoop.hdfs.util.DataTransferThrottler;
|
|
import org.apache.hadoop.io.MD5Hash;
|
|
import org.apache.hadoop.io.MD5Hash;
|
|
|
|
|
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
|
|
@@ -54,6 +58,8 @@ public class TransferFsImage {
|
|
|
|
|
|
public final static String CONTENT_LENGTH = "Content-Length";
|
|
public final static String CONTENT_LENGTH = "Content-Length";
|
|
public final static String MD5_HEADER = "X-MD5-Digest";
|
|
public final static String MD5_HEADER = "X-MD5-Digest";
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ static int timeout = 0;
|
|
|
|
|
|
private static final Log LOG = LogFactory.getLog(TransferFsImage.class);
|
|
private static final Log LOG = LogFactory.getLog(TransferFsImage.class);
|
|
|
|
|
|
@@ -222,6 +228,18 @@ public class TransferFsImage {
|
|
HttpURLConnection connection = (HttpURLConnection)
|
|
HttpURLConnection connection = (HttpURLConnection)
|
|
SecurityUtil.openSecureHttpConnection(url);
|
|
SecurityUtil.openSecureHttpConnection(url);
|
|
|
|
|
|
|
|
+ if (timeout <= 0) {
|
|
|
|
+ // Set the ping interval as timeout
|
|
|
|
+ Configuration conf = new HdfsConfiguration();
|
|
|
|
+ timeout = conf.getInt(DFSConfigKeys.DFS_IMAGE_TRANSFER_TIMEOUT_KEY,
|
|
|
|
+ DFSConfigKeys.DFS_IMAGE_TRANSFER_TIMEOUT_DEFAULT);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (timeout > 0) {
|
|
|
|
+ connection.setConnectTimeout(timeout);
|
|
|
|
+ connection.setReadTimeout(timeout);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
throw new HttpGetFailedException(
|
|
throw new HttpGetFailedException(
|
|
"Image transfer servlet at " + url +
|
|
"Image transfer servlet at " + url +
|