SpriCoder opened a new pull request, #17800:
URL: https://github.com/apache/iotdb/pull/17800
## Summary
This PR improves the C++ client (`iotdb-client/client-cpp`) along three axes
— concurrency, read/write performance, and safety/correctness. It is split into
four logically separate commits.
### 1. Thread-safe `SessionPool` (new feature)
A single `Session` is not safe to use from multiple threads concurrently (it
owns one Thrift transport/client). Previously the C++ client had no pooling,
forcing callers to either serialize all requests through one session or
hand-roll connection management.
- New `SessionPool` + `SessionPoolBuilder` lend each `Session` to exactly
one borrower at a time and reclaim it afterwards, so many application threads
can share a bounded set of connections without external locking.
- `getSession()` returns an RAII `PooledSession` handle that returns the
session to the pool on scope exit and works with any `Session` method; a
generic `execute([](Session&){...})` plus convenience wrappers (`insertTablet`,
`insertRecord`, `executeQueryStatement`, …) cover common operations.
- New sessions are constructed **outside** the pool lock so a handshake
never blocks other borrowers; `getSession()` blocks up to a configurable
timeout when the pool is exhausted.
- Query results are returned as a `PooledSessionDataSet` that keeps the
session leased until the result set is fully read — necessary because
`SessionDataSet` lazily fetches further blocks over the same connection.
Sessions that raise `IoTDBConnectionException` are evicted instead of recycled.
### 2. Enable RPC compression that was silently ignored (performance)
`Session::open(bool enableRPCCompression)` and the builder's
`enableRPCCompression` flag were never propagated to `SessionConnection`, whose
flag was hardcoded to `false`, so the compact Thrift protocol never took
effect. The flag is now threaded from the builder/`open()` into both the data
`SessionConnection` and the node-discovery `NodesSupplier` client, reducing
bytes on the wire for both reads and writes.
### 3. Safety / correctness hardening
- `Tablet::addValue` formatted out-of-range diagnostics with `sprintf` into
a fixed 100-byte stack buffer; switched to `snprintf` bounded by
`sizeof(buffer)` to remove the overflow risk.
- `MyStringBuffer::putOrderedByte` used `str.assign` on big-endian hosts,
which overwrote the whole buffer on every numeric write and corrupted
previously serialized content; changed to `str.append` to match the
little-endian path.
## Commits
1. Wire RPC compression flag through Session to its connections
2. Use snprintf for Tablet bounds-check error messages
3. Append big-endian bytes in MyStringBuffer instead of overwriting
4. Add thread-safe SessionPool to the C++ client
## Test plan
- [x] All changed/new sources compile cleanly against the project's
Thrift/Boost headers (`g++ -std=c++11 -fsyntax-only`, 0 errors); new code
conforms to the repo `.clang-format` (2-space, 100-col).
- [ ] Run the C++ client integration tests against a live IoTDB on
`127.0.0.1:6667` (`session_tests`), including the new `[sessionPool]` cases:
basic borrow/insert/query, concurrent writers, and exhaustion-timeout. These
require a running server and were not executed in the authoring environment.
--
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]