From 4df8618b229e1491db384e6a63b1cd229948cb1d Mon Sep 17 00:00:00 2001 From: vintmd Date: Tue, 20 Aug 2024 19:14:04 +0800 Subject: [PATCH] support the client request time control (#154) update update --- .../java/org/apache/hadoop/fs/CosNConfigKeys.java | 8 ++++++++ .../apache/hadoop/fs/CosNativeFileSystemStore.java | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java b/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java index 5924548..2d0aab0 100644 --- a/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java +++ b/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java @@ -186,6 +186,14 @@ public class CosNConfigKeys extends CommonConfigurationKeys { public static final int DEFAULT_COSN_IDLE_CONNECTION_ALIVE = 60000; + // request time out enable then request timeout and client thread size config work + public static final String COSN_CLIENT_USE_REQUEST_TIMEOUT = "fs.cosn.client.use.request.timeout"; + public static final boolean DEFAULT_COSN_CLIENT_USE_REQUEST_TIMEOUT = false; + public static final String COSN_CLIENT_REQUEST_TIMEOUT = "fs.cosn.client.request.timeout"; + public static final int DEFAULT_COSN_CLIENT_REQUEST_TIMEOUT = 5 * 60 * 1000; //5min + public static final String COSN_CLIENT_REQUEST_TIMEOUT_THREAD_SIZE = "fs.cosn.client.request.timeout.thread.size"; + public static final int DEFAULT_COSN_CLIENT_REQUEST_TIMEOUT_THREAD_SIZE = Runtime.getRuntime().availableProcessors() * 5; + public static final String CUSTOMER_DOMAIN = "fs.cosn.customer.domain"; public static final String COSN_SERVER_SIDE_ENCRYPTION_ALGORITHM = "fs.cosn.server-side-encryption.algorithm"; public static final String COSN_SERVER_SIDE_ENCRYPTION_KEY = "fs.cosn.server-side-encryption.key"; diff --git a/src/main/java/org/apache/hadoop/fs/CosNativeFileSystemStore.java b/src/main/java/org/apache/hadoop/fs/CosNativeFileSystemStore.java index a1d404f..038a2c8 100644 --- a/src/main/java/org/apache/hadoop/fs/CosNativeFileSystemStore.java +++ b/src/main/java/org/apache/hadoop/fs/CosNativeFileSystemStore.java @@ -364,6 +364,19 @@ private void initCOSClient(URI uri, Configuration conf) throws IOException { config.setShortConnection(); } + if (conf.getBoolean(CosNConfigKeys.COSN_CLIENT_USE_REQUEST_TIMEOUT, + CosNConfigKeys.DEFAULT_COSN_CLIENT_USE_REQUEST_TIMEOUT)) { + config.setRequestTimeOutEnable(true); + config.setRequestTimeout( + conf.getInt( + CosNConfigKeys.COSN_CLIENT_REQUEST_TIMEOUT, + CosNConfigKeys.DEFAULT_COSN_CLIENT_REQUEST_TIMEOUT)); + config.setTimeoutClientThreadSize( + conf.getInt( + CosNConfigKeys.COSN_CLIENT_REQUEST_TIMEOUT_THREAD_SIZE, + CosNConfigKeys.DEFAULT_COSN_CLIENT_REQUEST_TIMEOUT_THREAD_SIZE)); + } + config.setMaxConnectionsCount( conf.getInt( CosNConfigKeys.MAX_CONNECTION_NUM,