krconv opened a new pull request, #7665:
URL: https://github.com/apache/hbase/pull/7665
## Summary
Adds `RequestAttributesFactory` to `AsyncTableBuilder` for generating
request attributes dynamically per-request.
## Motivation
It is possible to do this for the HBase 2 `Table` client by overriding the
`RpcControllerFactory` on the connection, but that doesn't work reliably with
`AsyncTable` because retries happen on Netty threads, losing thread-local
context. This change provides a hook that is guaranteed to be called on the
initiating thread.
## Changes
- Add `RequestAttributesFactory` interface with a single `create(Map<String,
byte[]>)` method
- Add `setRequestAttributesFactory()` to `AsyncTableBuilder`
- Factory is invoked at the start of each operation (`get`, `put`, `scan`,
`batch`, etc.)
- `getRequestAttributes()` returns static attributes; factory is only used
for actual requests
## Usage
```java
AsyncTable<?> table = conn.getTableBuilder(tableName)
.setRequestAttribute("static.key", value)
.setRequestAttributesFactory(attrs -> {
Map<String, byte[]> newAttrs = new HashMap<>(attrs);
newAttrs.put("dynamic.key", getValueFromThreadLocal());
return newAttrs;
})
.build();
```
--
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]