krconv commented on code in PR #7665:
URL: https://github.com/apache/hbase/pull/7665#discussion_r2745861500


##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableBuilder.java:
##########
@@ -138,10 +138,28 @@ default AsyncTableBuilder<C> setMaxRetries(int 
maxRetries) {
   AsyncTableBuilder<C> setStartLogErrorsCnt(int startLogErrorsCnt);
 
   /**
-   * Set a request attribute
+   * Sets a request attribute. Ignored if a factory is set via
+   * {@link #setRequestAttributesFactory(RequestAttributesFactory)}.
+   * @param key   the attribute key
+   * @param value the attribute value
+   * @deprecated Since 3.0.0, will be removed in 4.0.0. Please use

Review Comment:
   I think master is 4.0.0; should it get deprecated for a later version or 
should I remove it from master?



##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/RequestAttributesFactory.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.util.Map;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Factory for creating request attributes. Called each time a client call is 
started, allowing
+ * dynamic attributes per call. Useful for propagating {@link ThreadLocal} 
context as request
+ * attributes.
+ * <p>
+ * For a fixed set of attributes that does not change, use {@link 
FixedRequestAttributesFactory}.
+ * @see AsyncTableBuilder#setRequestAttributesFactory(RequestAttributesFactory)
+ */
[email protected]
+public interface RequestAttributesFactory {

Review Comment:
   I think it still makes sense to have this factory, mainly for documenting 
it's behavior; open to replacing with a `Supplier<String, byte[]>` though



##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/FixedRequestAttributesFactory.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * A {@link RequestAttributesFactory} that returns a fixed set of attributes 
for every call. Use
+ * this when attributes do not need to change for the lifetime of the {@link 
AsyncTable}.
+ * @see AsyncTableBuilder#setRequestAttributesFactory(RequestAttributesFactory)
+ */
[email protected]
+public final class FixedRequestAttributesFactory implements 
RequestAttributesFactory {

Review Comment:
   The other ideas I had were `ImmutableRequestAttributesFactory` or 
`StaticRequestAttributesFactory`, but I think `FixedRequestAttributesFactory` 
is most clear because `Immutable-` might be interpreted as "the returned 
collection is immutable" instead of that it will return the same collection 
every time; and `Static-` clashes with the reserved word in my opinion



##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/FixedRequestAttributesFactory.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * A {@link RequestAttributesFactory} that returns a fixed set of attributes 
for every call. Use
+ * this when attributes do not need to change for the lifetime of the {@link 
AsyncTable}.
+ * @see AsyncTableBuilder#setRequestAttributesFactory(RequestAttributesFactory)
+ */
[email protected]
+public final class FixedRequestAttributesFactory implements 
RequestAttributesFactory {
+
+  /**
+   * A factory that always returns an empty map.
+   */
+  public static final RequestAttributesFactory EMPTY = Collections::emptyMap;
+
+  /**
+   * Builder for creating {@link FixedRequestAttributesFactory} instances.
+   */
+  public static final class Builder {
+    private final Map<String, byte[]> requestAttributes = new HashMap<>();
+
+    /**
+     * Sets a request attribute. If value is null, the attribute is removed.

Review Comment:
   The underlying Protobuf `ByteString` will throw a NPE if value is null, so 
instead this factory removes the entry if it's null.



-- 
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]

Reply via email to