joshelser commented on a change in pull request #4014:
URL: https://github.com/apache/hbase/pull/4014#discussion_r781663879
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AbstractRpcBasedConnectionRegistry.java
##########
@@ -272,6 +272,11 @@ private static RegionLocations
transformMetaRegionLocations(GetMetaRegionLocatio
getClass().getSimpleName() + ".getActiveMaster");
}
+ @Override
+ public String getConnectionString() {
+ return "unimplemented";
Review comment:
Why override with "unimplemented" if this class is `abstract`?
##########
File path:
hbase-client/src/test/java/org/apache/hadoop/hbase/client/trace/hamcrest/TraceTestUtil.java
##########
@@ -0,0 +1,65 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.hbase.client.trace.hamcrest;
+
+import static
org.apache.hadoop.hbase.client.trace.hamcrest.AttributesMatchers.containsEntry;
+import static
org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasAttributes;
+import static org.hamcrest.Matchers.allOf;
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.AsyncConnectionImpl;
+import org.apache.hadoop.hbase.client.ConnectionImplementation;
+import org.hamcrest.Matcher;
+
+public final class TraceTestUtil {
+
+ private TraceTestUtil() { }
+
+ /**
+ * All {@link Span}s involving {@code conn} should include these attributes.
+ */
+ public static Matcher<SpanData>
buildConnectionAttributesMatcher(AsyncConnectionImpl conn) {
+ return hasAttributes(allOf(
+ containsEntry("db.system", "hbase"),
+ containsEntry("db.connection_string", "nothing"),
+ containsEntry("db.user", conn.getUser().toString())));
+ }
+
+ /**
+ * All {@link Span}s involving {@code conn} should include these attributes.
+ * @see #buildConnectionAttributesMatcher(AsyncConnectionImpl)
+ */
+ public static Matcher<SpanData>
buildConnectionAttributesMatcher(ConnectionImplementation conn) {
Review comment:
Is this usage why `ConnectionImplementation` was made public? I remember
when ConnectionImplementation was made package-private back in HBase 1.x. Do
you think this is sufficient to make it public again? (or maybe I've missed the
real reason)
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
##########
@@ -335,4 +335,14 @@ HRegionLocation getRegionLocation(TableName tableName,
byte[] row, boolean reloa
* Get the bootstrap node list of another region server.
*/
List<ServerName> getAllBootstrapNodes(ServerName regionServer) throws
IOException;
+
+ /**
+ * Get the {@link User} associated with this connection. Maybe be {@code
null}.
Review comment:
```suggestion
* Get the {@link User} associated with this connection. May be {@code
null}.
```
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/trace/TableSpanBuilder.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.hbase.client.trace;
+
+import static org.apache.hadoop.hbase.trace.HBaseSemanticAttributes.DB_NAME;
+import static
org.apache.hadoop.hbase.trace.HBaseSemanticAttributes.NAMESPACE_KEY;
+import static org.apache.hadoop.hbase.trace.HBaseSemanticAttributes.TABLE_KEY;
+import io.opentelemetry.api.common.AttributeKey;
+import io.opentelemetry.api.trace.Span;
+import io.opentelemetry.api.trace.SpanBuilder;
+import io.opentelemetry.api.trace.SpanKind;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.AsyncConnectionImpl;
+import org.apache.hadoop.hbase.client.ClusterConnection;
+import org.apache.hadoop.hbase.trace.TraceUtil;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Construct {@link Span} instances involving data tables.
+ */
[email protected]
+public class TableSpanBuilder implements Supplier<Span> {
Review comment:
Pretty similar to `ConnectionSpanBuilder`. Should they share a parent
class or some common utility methods?
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java
##########
@@ -122,6 +135,37 @@ public boolean visitInternal(Result result) throws
IOException {
}
};
MetaTableAccessor.scanMetaForTableRegions(connection, visitor, tableName);
- return regions;
+ return consolidate(regions);
+ }
+
+ private static RegionLocations consolidate(final List<RegionLocations>
locations) {
+ final HRegionLocation[] consolidated = locations.stream()
+ .filter(Objects::nonNull)
+ .flatMap(locs -> Arrays.stream(locs.getRegionLocations()))
+ .filter(Objects::nonNull)
+ .toArray(HRegionLocation[]::new);
Review comment:
Should this deduplicate any`RegionLocations`? I guess from above, the
answer is "no" (we're just massaging the results we got out of meta) and we
should just trust that meta is reasonable.
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocator.java
##########
@@ -116,18 +122,30 @@ private boolean isMeta(TableName tableName) {
}
}
- private List<String> getRegionName(RegionLocations locs) {
- List<String> names = new ArrayList<>();
- for (HRegionLocation loc : locs.getRegionLocations()) {
- if (loc != null) {
- names.add(loc.getRegion().getRegionNameAsString());
- }
+ static List<String> getRegionNames(RegionLocations locs) {
+ if (locs == null || locs.getRegionLocations() == null) {
+ return Collections.emptyList();
}
- return names;
+ return Arrays.stream(locs.getRegionLocations())
+ .filter(Objects::nonNull)
+ .map(HRegionLocation::getRegion)
+ .map(RegionInfo::getRegionNameAsString)
+ .collect(Collectors.toList());
+ }
+
+ static List<String> getRegionNames(HRegionLocation location) {
+ return Optional.ofNullable(location)
+ .map(HRegionLocation::getRegion)
+ .map(RegionInfo::getRegionNameAsString)
+ .map(Collections::singletonList)
Review comment:
This will net an immutable list whereas `Arrays.asList()` (as previously
used down below) was returning a mutable list. Hopefully we would not be
altering this List, but noting a change in implementation to make sure it was
intentional.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]