This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 ec5c51f HDDS-5335. Method not found: allocateBlock - when tracing is
enabled (#2330)
ec5c51f is described below
commit ec5c51f439b1e8619b17b1c4403e482fb0e952d9
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Wed Sep 15 12:21:34 2021 +0200
HDDS-5335. Method not found: allocateBlock - when tracing is enabled (#2330)
Co-Authored-By: Elek, Márton <[email protected]>
---
.../apache/hadoop/hdds/tracing/TraceAllMethod.java | 23 ++++----
.../apache/hadoop/hdds/tracing/TracingUtil.java | 6 +-
.../hadoop/hdds/tracing/TestTraceAllMethod.java | 68 ++++++++++++++++++++++
.../hadoop/hdds/tracing/TestTracingUtil.java | 49 ++++++++++++++++
.../hadoop/ozone/om/request/key/OMKeyRequest.java | 7 ++-
.../ozone/om/request/key/TestOMKeyRequest.java | 7 +--
6 files changed, 139 insertions(+), 21 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TraceAllMethod.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TraceAllMethod.java
index 2328094..87d3998 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TraceAllMethod.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TraceAllMethod.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -28,6 +28,8 @@ import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.util.GlobalTracer;
+import static java.util.Collections.emptyMap;
+
/**
* A Java proxy invocation handler to trace all the methods of the delegate
* class.
@@ -41,18 +43,19 @@ public class TraceAllMethod<T> implements InvocationHandler
{
*/
private final Map<String, Map<Class<?>[], Method>> methods = new HashMap<>();
- private T delegate;
+ private final T delegate;
- private String name;
+ private final String name;
public TraceAllMethod(T delegate, String name) {
this.delegate = delegate;
this.name = name;
- for (Method method : delegate.getClass().getDeclaredMethods()) {
- if (!methods.containsKey(method.getName())) {
- methods.put(method.getName(), new HashMap<>());
+ for (Method method : delegate.getClass().getMethods()) {
+ if (method.getDeclaringClass().equals(Object.class)) {
+ continue;
}
- methods.get(method.getName()).put(method.getParameterTypes(), method);
+ methods.computeIfAbsent(method.getName(), any -> new HashMap<>())
+ .put(method.getParameterTypes(), method);
}
}
@@ -68,7 +71,7 @@ public class TraceAllMethod<T> implements InvocationHandler {
Span span = GlobalTracer.get().buildSpan(
name + "." + method.getName())
.start();
- try (Scope scope = GlobalTracer.get().activateSpan(span)) {
+ try (Scope ignored = GlobalTracer.get().activateSpan(span)) {
try {
return delegateMethod.invoke(delegate, args);
} catch (Exception ex) {
@@ -84,8 +87,8 @@ public class TraceAllMethod<T> implements InvocationHandler {
}
private Method findDelegatedMethod(Method method) {
- for (Entry<Class<?>[], Method> entry : methods.get(method.getName())
- .entrySet()) {
+ for (Entry<Class<?>[], Method> entry : methods.getOrDefault(
+ method.getName(), emptyMap()).entrySet()) {
if (Arrays.equals(entry.getKey(), method.getParameterTypes())) {
return entry.getValue();
}
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
index 05928c2..4588f69 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
@@ -54,7 +54,7 @@ public final class TracingUtil {
.registerExtractor(StringCodec.FORMAT, new StringCodec())
.registerInjector(StringCodec.FORMAT, new StringCodec())
.build();
- GlobalTracer.register(tracer);
+ GlobalTracer.registerIfAbsent(tracer);
}
}
@@ -155,7 +155,7 @@ public final class TracingUtil {
Supplier<R> supplier) {
Span span = GlobalTracer.get()
.buildSpan(spanName).start();
- try (Scope scope = GlobalTracer.get().activateSpan(span)) {
+ try (Scope ignored = GlobalTracer.get().activateSpan(span)) {
return supplier.get();
} catch (Exception ex) {
span.setTag("failed", true);
@@ -170,7 +170,7 @@ public final class TracingUtil {
*/
private static <R> R executeInSpan(Span span,
SupplierWithIOException<R> supplier) throws IOException {
- try (Scope scope = GlobalTracer.get().activateSpan(span)) {
+ try (Scope ignored = GlobalTracer.get().activateSpan(span)) {
return supplier.get();
} catch (Exception ex) {
span.setTag("failed", true);
diff --git
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestTraceAllMethod.java
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestTraceAllMethod.java
new file mode 100644
index 0000000..36c7a6e
--- /dev/null
+++
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestTraceAllMethod.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.tracing;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+/**
+ * Test for {@link TraceAllMethod}.
+ */
+public class TestTraceAllMethod {
+
+ @Test
+ public void testUnknownMethod() {
+ TraceAllMethod<Service> subject = new TraceAllMethod<>(new ServiceImpl(),
+ "service");
+ assertThrows(NoSuchMethodException.class, () -> subject.invoke(null,
+ ServiceImpl.class.getMethod("no such method"), new Object[]{}));
+ }
+
+ @Test
+ public void testDefaultMethod() throws Throwable {
+ TraceAllMethod<Service> subject = new TraceAllMethod<>(new ServiceImpl(),
+ "service");
+
+ assertEquals("Hello default", subject.invoke(null,
+ ServiceImpl.class.getMethod("defaultMethod"), new Object[]{}));
+ }
+
+ /**
+ * Example interface for testing {@link TraceAllMethod}.
+ */
+ public interface Service {
+ default String defaultMethod() {
+ return otherMethod("default");
+ }
+
+ String otherMethod(String name);
+ }
+
+ /**
+ * Example implementation class for testing {@link TraceAllMethod}.
+ */
+ public static class ServiceImpl implements Service {
+
+ @Override
+ public String otherMethod(String name) {
+ return "Hello " + name;
+ }
+ }
+}
diff --git
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestTracingUtil.java
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestTracingUtil.java
new file mode 100644
index 0000000..135b237
--- /dev/null
+++
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestTracingUtil.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdds.tracing;
+
+import org.apache.hadoop.hdds.conf.InMemoryConfiguration;
+import org.apache.hadoop.hdds.conf.MutableConfigurationSource;
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.hdds.tracing.TestTraceAllMethod.Service;
+import org.apache.hadoop.hdds.tracing.TestTraceAllMethod.ServiceImpl;
+import org.junit.Test;
+
+import static org.apache.hadoop.hdds.tracing.TracingUtil.createProxy;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test for {@link TracingUtil}.
+ */
+public class TestTracingUtil {
+
+ @Test
+ public void testDefaultMethod() {
+ Service subject = createProxy(new ServiceImpl(), Service.class,
+ tracingEnabled());
+
+ assertEquals("Hello default", subject.defaultMethod());
+ }
+
+ private static MutableConfigurationSource tracingEnabled() {
+ MutableConfigurationSource config = new InMemoryConfiguration();
+ config.setBoolean(ScmConfigKeys.HDDS_TRACING_ENABLED, true);
+ return config;
+ }
+
+}
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
index 9f3aa5e..b4b084a 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
@@ -127,9 +127,10 @@ public abstract class OMKeyRequest extends OMClientRequest
{
String remoteUser = getRemoteUser().getShortUserName();
List<AllocatedBlock> allocatedBlocks;
try {
- allocatedBlocks = scmClient.getBlockClient()
- .allocateBlock(scmBlockSize, numBlocks, replicationType,
- replicationFactor, omID, excludeList);
+ allocatedBlocks = scmClient.getBlockClient().allocateBlock(scmBlockSize,
+ numBlocks, ReplicationConfig.fromTypeAndFactor(replicationType,
+ replicationFactor),
+ omID, excludeList);
} catch (SCMException ex) {
if (ex.getResult()
.equals(SCMException.ResultCodes.SAFE_MODE_EXCEPTION)) {
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyRequest.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyRequest.java
index 6bcf706..c21f52a 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyRequest.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyRequest.java
@@ -49,7 +49,6 @@ import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock;
-import org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol;
@@ -171,10 +170,8 @@ public class TestOMKeyRequest {
allocatedBlocks.add(allocatedBlock);
- when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(),
- any(HddsProtos.ReplicationType.class),
- any(HddsProtos.ReplicationFactor.class),
- anyString(), any(ExcludeList.class))).thenReturn(allocatedBlocks);
+ when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(),
+ anyString(), any())).thenReturn(allocatedBlocks);
volumeName = UUID.randomUUID().toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]