zhangshenghang opened a new pull request, #13766:
URL: https://github.com/apache/seatunnel/pull/13766

   Yes, I am contributing this change to Apache SeaTunnel.
   
   ## Problem
   
   `HbaseSinkWriter.convertRowToPut` rebuilds metadata that never changes for a 
writer, once per record:
   
   - **Payload column indexes.** Every row rebuilt the list of columns to store 
as cells with `IntStream.range(0, arity).boxed()`, two `filter` stages and 
`Collectors.toList()`. That boxes every column index, runs 
`rowkeyColumnIndexes.contains(index)` for every column and allocates a new list 
for every record.
   - **Family and qualifier bytes.** The column family and qualifier names are 
constants of the writer, but they were re-encoded with 
`Bytes.toBytes(familyName)` and `Bytes.toBytes(fieldName)` for every payload 
column of every row, in both the non-null and the `NULL_MODE=EMPTY` branch. 
`Bytes.toBytes(String)` allocates a new byte array and encodes UTF-8, so a 
20-column row allocated 38 byte arrays per record that were immediately 
discarded.
   - **Rowkey metadata.** The rowkey delimiter bytes were re-encoded per row, 
and the binary-rowkey check re-scanned the rowkey columns per row.
   
   The row type and the parameters of a writer are fixed for its lifetime; the 
constructor already resolved the written families from the same fixed row type.
   
   ## Change
   
   - Resolve the payload column indexes once in the constructor into an `int[]`.
   - Encode the family and qualifier bytes once per column in the constructor, 
and share one family array between columns that map to the same family.
   - Encode the rowkey delimiter bytes once and resolve the binary-rowkey flag 
once.
   
   No public API, configuration option, default value, serialization format or 
SPI change. For a given row the produced `Put` is identical: same families, 
qualifiers, values, timestamps and durability. Payload columns are now resolved 
from the writer's row type (the arity the constructor already used) instead of 
`row.getArity()`; a row always carries the writer's schema.
   
   **Acceptance criteria:** the emitted `Put` is unchanged, and the per-row 
cost and allocation of building it drop measurably. Both are checked below.
   
   ## Modules
   
   - `seatunnel-connectors-v2/connector-hbase` only: `HbaseSinkWriter` and its 
unit test.
   
   ## Verification
   
   Run locally with JDK 17:
   
   ```
   ./mvnw -pl seatunnel-connectors-v2/connector-hbase spotless:apply
   ./mvnw -pl seatunnel-connectors-v2/connector-hbase -DskipTests verify
   ./mvnw -pl seatunnel-connectors-v2/connector-hbase test
   ```
   
   Result: `spotless` and `verify` pass; 62 tests, 0 failures, 0 errors.
   
   Two tests are added to `HbaseSinkWriterTest`:
   
   - `testPutMapsEveryPayloadColumnToItsOwnFamilyAndQualifier`: with two mapped 
families, every payload column still lands in its own family and qualifier with 
its own value, and the rowkey column is not written as a cell.
   - `testNullPayloadWritesAnEmptyValueInTheMappedFamily`: a NULL payload with 
`NULL_MODE=EMPTY` still writes an empty value into the mapped family, and the 
other columns keep their values.
   
   ### Measurement
   
   A temporary harness (not committed, to keep the diff minimal) builds a 
20-column row (1 rowkey + 19 payload: 10 strings, 8 ints, 1 double), writes it 
through `HbaseSinkWriter` backed by a mocked client, and reports the median of 
9 rounds of 300k iterations after warmup. `convertRowToPut` is also invoked 
directly so that the mocked client call does not hide the change.
   
   | metric | before | after | delta |
   | --- | --- | --- | --- |
   | `convertRowToPut` (median) | 1898.6 ns/row | 887.8 ns/row | **-53.2%** |
   | `convertRowToPut` (min) | 1549.8 ns/row | 603.5 ns/row | **-61.1%** |
   | `write()` end to end (median) | 7044.5 ns/row | 5337.7 ns/row | **-24.2%** 
|
   | allocation per `write()` (`ThreadMXBean.getThreadAllocatedBytes`) | 9304 
B/row | 7624 B/row | **-1680 B/row (-18.1%)** |
   
   `write()` still spends most of its time inside the mocked 
`HbaseClient.mutate` call, which is identical in both runs; the real sink 
replaces it with `BufferedMutator.mutate`, so the row conversion is a larger 
share of the real write path than these end-to-end numbers show.
   
   ## Remaining risk and follow-up
   
   - The HBase E2E suite (`connector-hbase-e2e`) covers the sink write path 
(multiple families, DATE/TIME/DECIMAL, binary rowkey, DELETE rows). It was not 
run here because it needs Docker and an HBase container; the changed branches 
are covered by the unit tests above.
   - Follow-up, deliberately not part of this change: 
`HBaseDeserializationFormat` compiles a `DateTimeFormatter` for every 
DATE/TIME/TIMESTAMP cell it reads, and the ARRAY column conversion calls 
`String.replaceAll`, which compiles a pattern per value. Both are separate, 
self-contained changes.
   
   There is no tracking issue for this change; it is a self-contained 
improvement to the connector's write path.
   


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