This is an automated email from the ASF dual-hosted git repository.
errose28 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 39845902a2b HDDS-17140. Refresh cached OM version on demand after
finalization (#11789)
39845902a2b is described below
commit 39845902a2b5d0d71031a1a05be949a39416156d
Author: Andy Huang <[email protected]>
AuthorDate: Wed Nov 4 02:26:14 2026 +0800
HDDS-17140. Refresh cached OM version on demand after finalization (#11789)
---
.../org/apache/hadoop/ozone/OzoneConfigKeys.java | 4 +
.../common/src/main/resources/ozone-default.xml | 12 +
.../apache/hadoop/ozone/client/rpc/RpcClient.java | 123 ++++++----
.../hadoop/ozone/client/rpc/TestRpcClient.java | 253 ++++++++++++++++++++-
4 files changed, 350 insertions(+), 42 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
index 0627c776fed..62cebd7d552 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
@@ -607,6 +607,10 @@ public final class OzoneConfigKeys {
public static final boolean OZONE_CLIENT_KEY_LATEST_VERSION_LOCATION_DEFAULT
=
true;
+ public static final String OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL =
+ "ozone.client.om.version.refresh.interval";
+ public static final long OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL_DEFAULT =
TimeUnit.MINUTES.toMillis(10);
+
public static final String OZONE_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS =
"ozone.client.server-defaults.validity.period.ms";
diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml
b/hadoop-hdds/common/src/main/resources/ozone-default.xml
index 4a6146afa29..7a681646847 100644
--- a/hadoop-hdds/common/src/main/resources/ozone-default.xml
+++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml
@@ -4008,6 +4008,18 @@
</description>
</property>
+ <property>
+ <name>ozone.client.om.version.refresh.interval</name>
+ <value>10m</value>
+ <tag>OZONE, CLIENT</tag>
+ <description>
+ The interval after which the cached OM version is refreshed on the next
version check.
+ Clients do not poll in the background. Failed refreshes retain the
cached version and wait
+ for this interval before retrying. Supports time unit suffixes;
milliseconds are assumed
+ if no unit is specified.
+ </description>
+ </property>
+
<property>
<name>ozone.client.server-defaults.validity.period.ms</name>
<tag>OZONE, CLIENT, SECURITY</tag>
diff --git
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
index 116edc2f99e..f6c4c31d1fa 100644
---
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
+++
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
@@ -22,6 +22,8 @@
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_ELASTIC_BYTE_BUFFER_POOL_MAX_SIZE_DEFAULT;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_KEY_PROVIDER_CACHE_EXPIRY;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_KEY_PROVIDER_CACHE_EXPIRY_DEFAULT;
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL;
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL_DEFAULT;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_REQUIRED_OM_VERSION_MIN_KEY;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_SERVER_DEFAULTS_VALIDITY_PERIOD_MS_DEFAULT;
@@ -43,6 +45,7 @@
import java.net.URI;
import java.security.InvalidKeyException;
import java.security.PrivilegedExceptionAction;
+import java.time.Clock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -59,6 +62,7 @@
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
@@ -93,6 +97,7 @@
import
org.apache.hadoop.hdds.security.x509.certificate.client.CACertificateProvider;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.hdds.utils.IOUtils;
+import org.apache.hadoop.hdds.utils.SlidingWindow.MonotonicClock;
import org.apache.hadoop.io.ByteBufferPool;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.ozone.OzoneAcl;
@@ -234,8 +239,12 @@ public class RpcClient implements ClientProtocol {
private final boolean getLatestVersionLocation;
private final ByteBufferPool byteBufferPool;
private final BlockInputStreamFactory blockInputStreamFactory;
- private final OzoneManagerVersion omVersion;
- private final boolean resolveS3VolumeOnOm;
+ private final long omVersionRefreshInterval;
+ private final Clock clock;
+ private static final long OM_VERSION_REFRESHING = -1L;
+ private volatile OzoneManagerVersion omVersion;
+ private final AtomicLong omVersionLastUpdate = new AtomicLong();
+ private final boolean s3AuthCheck;
private final MemoizedSupplier<ExecutorService> ecReconstructExecutor;
private final MemoizedSupplier<ExecutorService> ecParallelReadExecutor;
private final ContainerClientMetrics.Handle clientMetricsHandle;
@@ -254,8 +263,17 @@ public class RpcClient implements ClientProtocol {
*/
public RpcClient(ConfigurationSource conf, String omServiceId)
throws IOException {
+ this(conf, omServiceId, new MonotonicClock());
+ }
+
+ @VisibleForTesting
+ RpcClient(ConfigurationSource conf, String omServiceId, Clock clock) throws
IOException {
+ this.clock = Objects.requireNonNull(clock, "clock == null");
Objects.requireNonNull(conf, "conf == null");
this.conf = conf;
+ this.omVersionRefreshInterval = conf.getTimeDuration(
+ OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL,
OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL_DEFAULT,
+ TimeUnit.MILLISECONDS);
TracingUtil.initTracing("client", conf);
this.ugi = UserGroupInformation.getCurrentUser();
replicationConfigValidator =
@@ -284,9 +302,8 @@ public RpcClient(ConfigurationSource conf, String
omServiceId)
dtService = omTransport.getDelegationTokenService();
ServiceInfoEx serviceInfoEx = ozoneManagerClient.getServiceInfo();
omVersion = getOmVersion(serviceInfoEx);
- resolveS3VolumeOnOm = conf.getBoolean(S3Auth.S3_AUTH_CHECK, false)
- && OzoneManagerVersion.S3_VOLUME_CONTEXT_RESOLUTION
- .isSupportedBy(omVersion);
+ omVersionLastUpdate.set(clock.millis());
+ s3AuthCheck = conf.getBoolean(S3Auth.S3_AUTH_CHECK, false);
if (OzoneSecurityUtil.isSecurityEnabled(conf)) {
// If the client is authenticating using S3 style auth, all future
// requests serviced by this client will need S3 Auth set.
@@ -367,15 +384,24 @@ public XceiverClientFactory getXceiverClientManager() {
}
public static OzoneManagerVersion getOmVersion(ServiceInfoEx info) {
+ return getOmVersion(info, OzoneManagerVersion.SOFTWARE_VERSION);
+ }
+
+ private static OzoneManagerVersion getOmVersion(ServiceInfoEx info,
OzoneManagerVersion fallback) {
OzoneManagerVersion minOMVersion = OzoneManagerVersion.SOFTWARE_VERSION;
+ boolean hasOm = false;
for (ServiceInfo si : info.getServiceInfoList()) {
if (si.getNodeType() == HddsProtos.NodeType.OM) {
+ hasOm = true;
OzoneManagerVersion omVersion =
OzoneManagerVersion.deserialize(si.getProtobuf().getOMVersion());
if (!minOMVersion.isSupportedBy(omVersion)) {
minOMVersion = omVersion;
}
}
}
+ if (!hasOm) {
+ minOMVersion = fallback;
+ }
LOG.trace("Ozone Manager version is {}", minOMVersion);
return minOMVersion;
}
@@ -631,7 +657,7 @@ public void createBucket(
Objects.requireNonNull(bucketArgs, "bucketArgs == null");
verifyCountsQuota(bucketArgs.getQuotaInNamespace());
verifySpaceQuota(bucketArgs.getQuotaInBytes());
- if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(getOmVersion()))
{
if (bucketArgs.getDefaultReplicationConfig() != null &&
bucketArgs.getDefaultReplicationConfig().getType()
== ReplicationType.EC) {
@@ -1307,7 +1333,7 @@ public void setReplicationConfig(
verifyVolumeName(volumeName);
verifyBucketName(bucketName);
Objects.requireNonNull(replicationConfig, "replicationConfig == null");
- if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(getOmVersion()))
{
if (replicationConfig.getReplicationType()
== HddsProtos.ReplicationType.EC) {
throw new IOException("Can not set the default replication of the"
@@ -1450,7 +1476,7 @@ public OzoneOutputStream createKey(
public OzoneOutputStream rewriteKey(String volumeName, String bucketName,
String keyName,
long size, long existingKeyGeneration, ReplicationConfig
replicationConfig,
Map<String, String> metadata) throws IOException {
- if (!OzoneManagerVersion.ATOMIC_REWRITE_KEY.isSupportedBy(omVersion)) {
+ if (!OzoneManagerVersion.ATOMIC_REWRITE_KEY.isSupportedBy(getOmVersion()))
{
throw new IOException("OzoneManager does not support atomic key
rewrite.");
}
Preconditions.checkArgument(existingKeyGeneration > 0,
@@ -1477,7 +1503,7 @@ public OzoneOutputStream createKeyIfNotExists(String
volumeName,
String bucketName, String keyName, long size,
ReplicationConfig replicationConfig, Map<String, String> metadata,
Map<String, String> tags, boolean derivedKeyPiggyBacking) throws
IOException {
- if
(!OzoneManagerVersion.ATOMIC_CREATE_IF_NOT_EXISTS.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ATOMIC_CREATE_IF_NOT_EXISTS.isSupportedBy(getOmVersion()))
{
throw new IOException(
"OzoneManager does not support atomic key creation.");
}
@@ -1504,7 +1530,7 @@ public OzoneOutputStream rewriteKeyIfMatch(String
volumeName,
String bucketName, String keyName, long size, String expectedETag,
ReplicationConfig replicationConfig, Map<String, String> metadata,
Map<String, String> tags, boolean derivedKeyPiggyBacking) throws
IOException {
- if (!OzoneManagerVersion.ATOMIC_REWRITE_KEY.isSupportedBy(omVersion)) {
+ if (!OzoneManagerVersion.ATOMIC_REWRITE_KEY.isSupportedBy(getOmVersion()))
{
throw new IOException(
"OzoneManager does not support conditional key rewrite.");
}
@@ -1540,7 +1566,7 @@ public OzoneDataStreamOutput
createStreamKeyIfNoneMatch(String volumeName, Strin
}
private void checkIfNoneMatchETagSupport() throws IOException {
- if (omVersion.compareTo(OzoneManagerVersion.S3_IF_NONE_MATCH_ETAG) < 0) {
+ if (getOmVersion().compareTo(OzoneManagerVersion.S3_IF_NONE_MATCH_ETAG) <
0) {
throw new IOException("OzoneManager does not support If-None-Match
entity ETags for writes.");
}
}
@@ -1563,12 +1589,12 @@ private OzoneOutputStream openOutputStream(OmKeyArgs
keyArgs, long size)
}
private boolean shouldPiggybackDerivedKey(boolean requested) {
- return requested &&
OzoneManagerVersion.S3_DERIVED_KEY.isSupportedBy(omVersion);
+ return requested &&
OzoneManagerVersion.S3_DERIVED_KEY.isSupportedBy(getOmVersion());
}
private void validateObjectTagsSupport(Map<String, String> tags)
throws IOException {
- if (!OzoneManagerVersion.OBJECT_TAG.isSupportedBy(omVersion)) {
+ if (!OzoneManagerVersion.OBJECT_TAG.isSupportedBy(getOmVersion())) {
if (tags != null && !tags.isEmpty()) {
throw new IOException("OzoneManager does not support object tags");
}
@@ -1583,7 +1609,7 @@ private void createKeyPreChecks(String volumeName, String
bucketName, String key
HddsClientUtils.verifyKeyName(keyName);
}
HddsClientUtils.checkNotNull(keyName);
- if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(getOmVersion()))
{
if (replicationConfig != null &&
replicationConfig.getReplicationType()
== HddsProtos.ReplicationType.EC) {
@@ -1644,7 +1670,7 @@ public OzoneDataStreamOutput
createStreamKeyIfNotExists(String volumeName,
String bucketName, String keyName, long size,
ReplicationConfig replicationConfig, Map<String, String> metadata,
Map<String, String> tags, boolean derivedKeyPiggyBacking) throws
IOException {
- if
(!OzoneManagerVersion.ATOMIC_CREATE_IF_NOT_EXISTS.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ATOMIC_CREATE_IF_NOT_EXISTS.isSupportedBy(getOmVersion()))
{
throw new IOException(
"OzoneManager does not support atomic key creation.");
}
@@ -1672,7 +1698,7 @@ public OzoneDataStreamOutput
rewriteStreamKeyIfMatch(String volumeName,
String bucketName, String keyName, long size, String expectedETag,
ReplicationConfig replicationConfig, Map<String, String> metadata,
Map<String, String> tags, boolean derivedKeyPiggyBacking) throws
IOException {
- if (!OzoneManagerVersion.ATOMIC_REWRITE_KEY.isSupportedBy(omVersion)) {
+ if (!OzoneManagerVersion.ATOMIC_REWRITE_KEY.isSupportedBy(getOmVersion()))
{
throw new IOException(
"OzoneManager does not support conditional key rewrite.");
}
@@ -1907,7 +1933,7 @@ public List<OzoneKey> listKeys(String volumeName, String
bucketName,
int maxListResult)
throws IOException {
- if (OzoneManagerVersion.LIGHTWEIGHT_LIST_KEYS.isSupportedBy(omVersion)) {
+ if
(OzoneManagerVersion.LIGHTWEIGHT_LIST_KEYS.isSupportedBy(getOmVersion())) {
List<BasicOmKeyInfo> keys = ozoneManagerClient.listKeysLight(
volumeName, bucketName, prevKey, keyPrefix, maxListResult).getKeys();
@@ -2021,7 +2047,7 @@ public S3HeadObjectAttributes
headS3ObjectAttributes(String bucketName, String k
private OmKeyInfo getS3PartOmKeyInfo(String bucketName, String keyName,
int partNumber, boolean isHeadOp) throws IOException {
OmKeyInfo keyInfo;
- if (OzoneManagerVersion.S3_PART_AWARE_GET.isSupportedBy(omVersion)) {
+ if (OzoneManagerVersion.S3_PART_AWARE_GET.isSupportedBy(getOmVersion())) {
keyInfo = getS3PartKeyInfo(bucketName, keyName, partNumber, isHeadOp);
} else {
keyInfo = getS3KeyInfo(bucketName, keyName, isHeadOp);
@@ -2118,7 +2144,7 @@ private OmKeyInfo getKeyInfo(String volumeName, String
bucketName, String keyNam
private OmKeyInfo getKeyInfo(OmKeyArgs keyArgs) throws IOException {
final OmKeyInfo keyInfo;
- if (OzoneManagerVersion.OPTIMIZED_GET_KEY_INFO.isSupportedBy(omVersion)) {
+ if
(OzoneManagerVersion.OPTIMIZED_GET_KEY_INFO.isSupportedBy(getOmVersion())) {
keyInfo = ozoneManagerClient.getKeyInfo(keyArgs, false)
.getKeyInfo();
} else {
@@ -2191,7 +2217,7 @@ public OmMultipartInfo initiateMultipartUpload(String
volumeName,
verifyBucketName(bucketName);
HddsClientUtils.checkNotNull(keyName);
String ownerName = getRealUserInfo().getShortUserName();
- if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(getOmVersion()))
{
if (replicationConfig != null && replicationConfig.getReplicationType()
== HddsProtos.ReplicationType.EC) {
throw new IOException("Can not set the replication of the file to"
@@ -2200,7 +2226,7 @@ public OmMultipartInfo initiateMultipartUpload(String
volumeName,
}
}
- if (!OzoneManagerVersion.OBJECT_TAG.isSupportedBy(omVersion)) {
+ if (!OzoneManagerVersion.OBJECT_TAG.isSupportedBy(getOmVersion())) {
if (tags != null && !tags.isEmpty()) {
throw new IOException("OzoneManager does not support object tags");
}
@@ -2407,7 +2433,7 @@ public OmMultipartUploadCompleteInfo
completeMultipartUpload(String volumeName,
@Override
public void abortS3MultipartUpload(String bucketName, String keyName, String
uploadID) throws IOException {
- if
(!OzoneManagerVersion.S3_VOLUME_CONTEXT_RESOLUTION.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.S3_VOLUME_CONTEXT_RESOLUTION.isSupportedBy(getOmVersion()))
{
abortMultipartUpload(getS3VolumeContext().getOmVolumeArgs().getVolume(),
bucketName, keyName, uploadID);
return;
}
@@ -2477,7 +2503,7 @@ public OzoneMultipartUploadList
listMultipartUploads(String volumeName,
verifyBucketName(bucketName);
OmMultipartUploadList omMultipartUploadList;
- if
(OzoneManagerVersion.S3_LIST_MULTIPART_UPLOADS_PAGINATION.isSupportedBy(omVersion))
{
+ if
(OzoneManagerVersion.S3_LIST_MULTIPART_UPLOADS_PAGINATION.isSupportedBy(getOmVersion()))
{
omMultipartUploadList =
ozoneManagerClient.listMultipartUploads(volumeName, bucketName, prefix,
keyMarker,
uploadIdMarker, maxUploads, true);
} else {
@@ -2544,7 +2570,7 @@ public OzoneInputStream readFile(String volumeName,
String bucketName,
.setRequireFileSystemLayout(requireFileSystemLayout)
.build();
final OmKeyInfo keyInfo;
- if (OzoneManagerVersion.OPTIMIZED_GET_KEY_INFO.isSupportedBy(omVersion)) {
+ if
(OzoneManagerVersion.OPTIMIZED_GET_KEY_INFO.isSupportedBy(getOmVersion())) {
keyInfo = ozoneManagerClient.getKeyInfo(keyArgs, false)
.getKeyInfo();
if (!keyInfo.isFile()) {
@@ -2595,7 +2621,7 @@ private OzoneInputStream getInputStreamWithRetryFunction(
public OzoneOutputStream createFile(String volumeName, String bucketName,
String keyName, long size, ReplicationConfig replicationConfig,
boolean overWrite, boolean recursive) throws IOException {
- if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.ERASURE_CODED_STORAGE_SUPPORT.isSupportedBy(getOmVersion()))
{
if (replicationConfig.getReplicationType()
== HddsProtos.ReplicationType.EC) {
throw new IOException("Can not set the replication of the file to"
@@ -2705,7 +2731,7 @@ public List<OzoneFileStatusLight>
listStatusLight(ListStatusLightOptions options
public ListStatusResult<OzoneFileStatusLight>
listStatusLightPage(ListStatusLightOptions options)
throws IOException {
final OmKeyArgs keyArgs = prepareListStatusKeyArgs(options);
- if (OzoneManagerVersion.LIGHTWEIGHT_LIST_STATUS.isSupportedBy(omVersion)) {
+ if
(OzoneManagerVersion.LIGHTWEIGHT_LIST_STATUS.isSupportedBy(getOmVersion())) {
return ozoneManagerClient.listStatusLightPage(
keyArgs, options.isRecursive(), options.getStartKey(),
options.getNumEntries(),
options.isAllowPartialPrefixes());
@@ -2965,7 +2991,7 @@ private KeyOutputStream.Builder createKeyOutputStream(
.setClientMetrics(clientMetrics)
.setExecutorServiceSupplier(writeExecutor)
.setStreamBufferArgs(streamBufferArgs)
- .setOmVersion(omVersion);
+ .setOmVersion(getOmVersion());
}
@Override
@@ -2990,6 +3016,20 @@ public KeyProvider call() throws Exception {
@Override
public OzoneManagerVersion getOmVersion() {
+ long lastUpdate = omVersionLastUpdate.get();
+ if (lastUpdate == OM_VERSION_REFRESHING || clock.millis() - lastUpdate <
omVersionRefreshInterval) {
+ return omVersion;
+ }
+ if (omVersionLastUpdate.compareAndSet(lastUpdate, OM_VERSION_REFRESHING)) {
+ try {
+ omVersion = getOmVersion(ozoneManagerClient.getServiceInfo(),
omVersion);
+ } catch (Exception e) {
+ LOG.warn("Could not refresh OM version; retaining {}.", omVersion, e);
+ } finally {
+ // Throttle retries after failures as well as successful refreshes.
+ omVersionLastUpdate.set(clock.millis());
+ }
+ }
return omVersion;
}
@@ -3138,32 +3178,35 @@ public void setVerifyChecksum(boolean verifyChecksum) {
public LeaseKeyInfo recoverLease(String volumeName, String bucketName,
String keyName, boolean force)
throws IOException {
- if (!OzoneManagerVersion.HBASE_SUPPORT.isSupportedBy(omVersion)) {
+ OzoneManagerVersion version = getOmVersion();
+ if (!OzoneManagerVersion.HBASE_SUPPORT.isSupportedBy(version)) {
throw new UnsupportedOperationException("Lease recovery API requires OM
version "
+ OzoneManagerVersion.HBASE_SUPPORT + " or later. Current OM version
"
- + omVersion);
+ + version);
}
return ozoneManagerClient.recoverLease(volumeName, bucketName, keyName,
force);
}
@Override
public void recoverKey(OmKeyArgs args, long clientID) throws IOException {
- if (!OzoneManagerVersion.HBASE_SUPPORT.isSupportedBy(omVersion)) {
+ OzoneManagerVersion version = getOmVersion();
+ if (!OzoneManagerVersion.HBASE_SUPPORT.isSupportedBy(version)) {
throw new UnsupportedOperationException("Lease recovery API requires OM
version "
+ OzoneManagerVersion.HBASE_SUPPORT + " or later. Current OM version
"
- + omVersion);
+ + version);
}
ozoneManagerClient.recoverKey(args, clientID);
}
@Override
- public Map<String, String> getObjectTagging(
- String volumeName, String bucketName, String keyName) throws IOException
{
- if (!OzoneManagerVersion.S3_OBJECT_TAGGING_API.isSupportedBy(omVersion)) {
+ public Map<String, String> getObjectTagging(String volumeName, String
bucketName, String keyName)
+ throws IOException {
+ if
(!OzoneManagerVersion.S3_OBJECT_TAGGING_API.isSupportedBy(getOmVersion())) {
throw new IOException("OzoneManager does not support S3 object tagging
API");
}
- boolean assumeS3Context = volumeName == null && resolveS3VolumeOnOm;
+ boolean assumeS3Context = volumeName == null && s3AuthCheck
+ &&
OzoneManagerVersion.S3_VOLUME_CONTEXT_RESOLUTION.isSupportedBy(getOmVersion());
if (assumeS3Context) {
volumeName = OzoneConfigKeys.OZONE_S3_VOLUME_NAME_DEFAULT;
}
@@ -3182,7 +3225,7 @@ public Map<String, String> getObjectTagging(
@Override
public void putObjectTagging(String volumeName, String bucketName,
String keyName, Map<String, String> tags)
throws IOException {
- if (!OzoneManagerVersion.S3_OBJECT_TAGGING_API.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.S3_OBJECT_TAGGING_API.isSupportedBy(getOmVersion())) {
throw new IOException("OzoneManager does not support S3 object tagging
API");
}
@@ -3201,7 +3244,7 @@ public void putObjectTagging(String volumeName, String
bucketName,
@Override
public void deleteObjectTagging(String volumeName, String bucketName,
String keyName) throws IOException {
- if (!OzoneManagerVersion.S3_OBJECT_TAGGING_API.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.S3_OBJECT_TAGGING_API.isSupportedBy(getOmVersion())) {
throw new IOException("OzoneManager does not support S3 object tagging
API");
}
@@ -3267,7 +3310,7 @@ public void deleteLifecycleConfiguration(String
volumeName, String bucketName) t
@Override
public Map<String, String> getBucketTagging(String volumeName, String
bucketName)
throws IOException {
- if (!OzoneManagerVersion.S3_BUCKET_TAGGING_API.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.S3_BUCKET_TAGGING_API.isSupportedBy(getOmVersion())) {
throw new IOException("OzoneManager does not support S3 bucket tagging
API");
}
@@ -3283,7 +3326,7 @@ public Map<String, String> getBucketTagging(String
volumeName, String bucketName
@Override
public void putBucketTagging(String volumeName, String bucketName,
Map<String, String> tags) throws IOException {
- if (!OzoneManagerVersion.S3_BUCKET_TAGGING_API.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.S3_BUCKET_TAGGING_API.isSupportedBy(getOmVersion())) {
throw new IOException("OzoneManager does not support S3 bucket tagging
API");
}
@@ -3300,7 +3343,7 @@ public void putBucketTagging(String volumeName, String
bucketName,
@Override
public void deleteBucketTagging(String volumeName, String bucketName)
throws IOException {
- if (!OzoneManagerVersion.S3_BUCKET_TAGGING_API.isSupportedBy(omVersion)) {
+ if
(!OzoneManagerVersion.S3_BUCKET_TAGGING_API.isSupportedBy(getOmVersion())) {
throw new IOException("OzoneManager does not support S3 bucket tagging
API");
}
diff --git
a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
index 45dcb1c4e9f..419131bdcdc 100644
---
a/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
+++
b/hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java
@@ -17,6 +17,8 @@
package org.apache.hadoop.ozone.client.rpc;
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL;
+import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL_DEFAULT;
import static org.apache.hadoop.ozone.client.rpc.RpcClient.getOmVersion;
import static org.apache.hadoop.ozone.client.rpc.RpcClient.validateOmVersion;
import static org.assertj.core.api.Assertions.assertThat;
@@ -26,6 +28,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -35,12 +38,17 @@
import java.io.IOException;
import java.nio.file.Path;
+import java.time.Clock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
@@ -52,6 +60,7 @@
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.XceiverClientFactory;
import org.apache.hadoop.hdds.scm.storage.TestClientThreadShutdown;
+import org.apache.hadoop.hdds.utils.SlidingWindow.MonotonicClock;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.OzoneManagerVersion;
import org.apache.hadoop.ozone.client.MockOmTransport;
@@ -76,6 +85,7 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ozone.test.GenericTestUtils.LogCapturer;
+import org.apache.ozone.test.MockClock;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.io.TempDir;
@@ -84,6 +94,7 @@
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.slf4j.event.Level;
@@ -362,6 +373,230 @@ public void testGetOmVersionWithFutureOM() {
om(OzoneManagerVersion.UNKNOWN_VERSION))));
}
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testOmVersionRefreshesOnDemandAfterExpiry(boolean customInterval)
throws Exception {
+ OzoneConfiguration config = new OzoneConfiguration();
+ if (customInterval) {
+ config.set(OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL, "37s");
+ }
+ long interval = config.getTimeDuration(
+ OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL,
OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL_DEFAULT,
+ TimeUnit.MILLISECONDS);
+ VersionedOmTransport transport = new VersionedOmTransport();
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, config, clock);
+ try {
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, client.getOmVersion());
+ transport.version = OzoneManagerVersion.SOFTWARE_VERSION;
+ clock.fastForward(interval - 1);
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, client.getOmVersion());
+ assertEquals(1, transport.serviceInfoCalls.get());
+
+ clock.fastForward(1);
+ // Idle clients do not poll, even when their cached version has expired.
+ assertEquals(1, transport.serviceInfoCalls.get());
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
client.getOmVersion());
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
client.getOmVersion());
+ assertEquals(2, transport.serviceInfoCalls.get());
+ } finally {
+ client.close();
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testOmVersionRefreshFailureRetainsVersionAndThrottlesRetries(boolean
unchecked) throws Exception {
+ VersionedOmTransport transport = new VersionedOmTransport();
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, new OzoneConfiguration(),
clock);
+ try {
+ transport.failRefresh = true;
+ transport.uncheckedFailure = unchecked;
+ clock.fastForward(omVersionRefreshInterval());
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, client.getOmVersion());
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, client.getOmVersion());
+ assertEquals(2, transport.serviceInfoCalls.get());
+
+ transport.failRefresh = false;
+ transport.version = OzoneManagerVersion.SOFTWARE_VERSION;
+ clock.fastForward(omVersionRefreshInterval());
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
client.getOmVersion());
+ assertEquals(3, transport.serviceInfoCalls.get());
+ } finally {
+ client.close();
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testOmVersionRefreshWithoutOmRetainsVersion(boolean nonOmService)
throws Exception {
+ VersionedOmTransport transport = new VersionedOmTransport();
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, new OzoneConfiguration(),
clock);
+ try {
+ transport.services = nonOmService
+ ?
Collections.singletonList(ServiceInfo.newBuilder().setNodeType(HddsProtos.NodeType.SCM)
+ .setHostname("scm").build()) : Collections.emptyList();
+ clock.fastForward(omVersionRefreshInterval());
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, client.getOmVersion());
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, client.getOmVersion());
+ assertEquals(2, transport.serviceInfoCalls.get());
+ transport.services = null;
+ transport.version = OzoneManagerVersion.SOFTWARE_VERSION;
+ clock.fastForward(omVersionRefreshInterval());
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
client.getOmVersion());
+ assertEquals(3, transport.serviceInfoCalls.get());
+ } finally {
+ client.close();
+ }
+ }
+
+ @Test
+ void testFeatureCheckDiscoversFinalizedOmVersion() throws Exception {
+ VersionedOmTransport transport = new VersionedOmTransport();
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, new OzoneConfiguration(),
clock);
+ try {
+ IOException unsupported = assertThrows(IOException.class,
+ () -> client.getObjectTagging("volume", "bucket", "key"));
+ assertThat(unsupported).hasMessageContaining("does not support S3 object
tagging API");
+ transport.version = OzoneManagerVersion.SOFTWARE_VERSION;
+ clock.fastForward(omVersionRefreshInterval());
+ IOException reachedOm = assertThrows(IOException.class,
+ () -> client.getObjectTagging("volume", "bucket", "key"));
+ assertThat(reachedOm).hasMessage("Reached OM after version check");
+ assertEquals(2, transport.serviceInfoCalls.get());
+ } finally {
+ client.close();
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testObjectTaggingDiscoversS3VolumeContextResolution(boolean
s3AuthCheck) throws Exception {
+ VersionedOmTransport transport = new VersionedOmTransport();
+ transport.version = OzoneManagerVersion.S3_OBJECT_TAGGING_API;
+ OzoneConfiguration conf = new OzoneConfiguration();
+ conf.setBoolean(S3Auth.S3_AUTH_CHECK, s3AuthCheck);
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, conf, clock);
+ try {
+ assertThrows(IOException.class, () -> client.getObjectTagging("volume",
"bucket", "key"));
+ assertFalse(transport.lastObjectTaggingRequest.getAssumeS3Context());
+
+ transport.version = OzoneManagerVersion.S3_VOLUME_CONTEXT_RESOLUTION;
+ clock.fastForward(omVersionRefreshInterval());
+ IOException reachedOm = assertThrows(IOException.class,
+ () -> client.getObjectTagging(s3AuthCheck ? null : "volume",
"bucket", "key"));
+ assertThat(reachedOm).hasMessage("Reached OM after version check");
+ assertEquals(s3AuthCheck,
transport.lastObjectTaggingRequest.getAssumeS3Context());
+ assertEquals(2, transport.serviceInfoCalls.get());
+ } finally {
+ client.close();
+ }
+ }
+
+ @Test
+ void testConcurrentOmVersionReadersShareRefresh() throws Exception {
+ VersionedOmTransport transport = new VersionedOmTransport();
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, new OzoneConfiguration(),
clock);
+ ExecutorService executor = Executors.newFixedThreadPool(8);
+ transport.refreshStarted = new CountDownLatch(1);
+ transport.releaseRefresh = new CountDownLatch(1);
+ try {
+ transport.version = OzoneManagerVersion.SOFTWARE_VERSION;
+ clock.fastForward(omVersionRefreshInterval());
+ Future<OzoneManagerVersion> refresh = executor.submit(() ->
client.getOmVersion());
+ assertTrue(transport.refreshStarted.await(10, TimeUnit.SECONDS));
+ List<Future<OzoneManagerVersion>> versions = new ArrayList<>();
+ for (int i = 0; i < 7; i++) {
+ versions.add(executor.submit(() -> client.getOmVersion()));
+ }
+ // Other readers must return the cached version while the refresh is
still in flight.
+ for (Future<OzoneManagerVersion> version : versions) {
+ assertEquals(OzoneManagerVersion.DEFAULT_VERSION, version.get(5,
TimeUnit.SECONDS));
+ }
+ assertEquals(2, transport.serviceInfoCalls.get());
+ transport.releaseRefresh.countDown();
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION, refresh.get(10,
TimeUnit.SECONDS));
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
client.getOmVersion());
+ assertEquals(2, transport.serviceInfoCalls.get());
+ } finally {
+ transport.releaseRefresh.countDown();
+ executor.shutdownNow();
+ client.close();
+ }
+ }
+
+ @Test
+ void testOmVersionRefreshUsesCallingThreadsS3Auth() throws Exception {
+ VersionedOmTransport transport = new VersionedOmTransport();
+ MockClock clock = MockClock.newInstance();
+ RpcClient client = createRpcClient(transport, new OzoneConfiguration(),
clock);
+ try {
+ client.setThreadLocalS3Auth(new S3Auth("stringToSign", "signature",
"alice", "alice"));
+ transport.version = OzoneManagerVersion.SOFTWARE_VERSION;
+ clock.fastForward(omVersionRefreshInterval());
+ assertEquals(OzoneManagerVersion.SOFTWARE_VERSION,
client.getOmVersion());
+ assertEquals("alice",
transport.lastServiceInfoRequest.getS3Authentication().getAccessId());
+ assertEquals("signature",
transport.lastServiceInfoRequest.getS3Authentication().getSignature());
+ } finally {
+ client.clearThreadLocalS3Auth();
+ client.close();
+ }
+ }
+
+ private static final class VersionedOmTransport extends MockOmTransport {
+ private OzoneManagerVersion version = OzoneManagerVersion.DEFAULT_VERSION;
+ private final AtomicInteger serviceInfoCalls = new AtomicInteger();
+ private CountDownLatch refreshStarted;
+ private CountDownLatch releaseRefresh;
+ private boolean failRefresh;
+ private boolean uncheckedFailure;
+ private List<ServiceInfo> services;
+ private OMRequest lastServiceInfoRequest;
+ private OMRequest lastObjectTaggingRequest;
+
+ @Override
+ public OMResponse submitRequest(OMRequest request) throws IOException {
+ if (request.getCmdType() == Type.ServiceList) {
+ int calls = serviceInfoCalls.incrementAndGet();
+ if (calls == 2 && refreshStarted != null) {
+ refreshStarted.countDown();
+ try {
+ if (!releaseRefresh.await(10, TimeUnit.SECONDS)) {
+ throw new IOException("Timed out waiting to release OM version
refresh");
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IOException("Interrupted while waiting to release OM
version refresh", e);
+ }
+ }
+ lastServiceInfoRequest = request;
+ if (failRefresh) {
+ if (uncheckedFailure) {
+ throw new IllegalStateException("Service info temporarily
unavailable");
+ }
+ throw new IOException("Service info temporarily unavailable");
+ }
+ ServiceListResponse.Builder response =
ServiceListResponse.newBuilder();
+ for (ServiceInfo service : services == null ?
Collections.singletonList(om(version)) : services) {
+ response.addServiceInfo(service.getProtobuf());
+ }
+ return super.submitRequest(request).toBuilder()
+ .setServiceListResponse(response)
+ .build();
+ }
+ if (request.getCmdType() == Type.GetObjectTagging) {
+ lastObjectTaggingRequest = request;
+ throw new IOException("Reached OM after version check");
+ }
+ return super.submitRequest(request);
+ }
+ }
+
@Test
public void testCloseTwiceDoesNotWarn() throws IOException {
RpcClient rpcClient = createRpcClient();
@@ -719,8 +954,22 @@ private static RpcClient createRpcClient() throws
IOException {
}
private static RpcClient createRpcClient(OmTransport transport) throws
IOException {
- OzoneConfiguration config = new OzoneConfiguration();
- return new RpcClient(config, null) {
+ return createRpcClient(transport, new OzoneConfiguration());
+ }
+
+ private static long omVersionRefreshInterval() {
+ return new OzoneConfiguration().getTimeDuration(
+ OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL,
OZONE_CLIENT_OM_VERSION_REFRESH_INTERVAL_DEFAULT,
+ TimeUnit.MILLISECONDS);
+ }
+
+ private static RpcClient createRpcClient(OmTransport transport,
OzoneConfiguration config) throws IOException {
+ return createRpcClient(transport, config, new MonotonicClock());
+ }
+
+ private static RpcClient createRpcClient(OmTransport transport,
OzoneConfiguration config, Clock clock)
+ throws IOException {
+ return new RpcClient(config, null, clock) {
@Override
protected OmTransport createOmTransport(String omServiceId) {
return transport;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]