Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ if(GTest_FOUND)
tests/unit/PutIfAbsentTest.cpp
tests/unit/ReplaceTest.cpp
tests/unit/ContainsKeyTest.cpp
tests/unit/BulkOpsTest.cpp
tests/unit/HashAwareRoutingTest.cpp
tests/unit/ErrorHandlingTest.cpp
tests/unit/ServerSelectionTest.cpp
Expand Down Expand Up @@ -193,6 +194,11 @@ if(GTest_FOUND)
tests/integration/ErrorHandlingIntegrationTest.cpp
)

# Bulk operations (PUT_ALL / GET_ALL) end-to-end (single server)
add_executable(bulkops_integration_tests
tests/integration/BulkOpsIntegrationTest.cpp
)

# Hot Rod URI end-to-end (single server) — fromUri parse->connect->op chain
add_executable(fromuri_integration_tests
tests/integration/FromUriIntegrationTest.cpp
Expand Down Expand Up @@ -285,6 +291,13 @@ if(GTest_FOUND)
# Note: NOT gtest_main - we provide our own main()
)

target_link_libraries(bulkops_integration_tests
PRIVATE
hotrod-client
GTest::gtest
# Note: NOT gtest_main - we provide our own main()
)

target_link_libraries(topology_integration_tests
PRIVATE
hotrod-client
Expand Down Expand Up @@ -425,6 +438,7 @@ if(GTest_FOUND)
add_test(NAME ReplaceIntegrationTests COMMAND replace_integration_tests)
add_test(NAME ContainsKeyIntegrationTests COMMAND containskey_integration_tests)
add_test(NAME ErrorHandlingIntegrationTests COMMAND errorhandling_integration_tests)
add_test(NAME BulkOpsIntegrationTests COMMAND bulkops_integration_tests)
add_test(NAME FromUriIntegrationTests COMMAND fromuri_integration_tests)
add_test(NAME TopologyIntegrationTests COMMAND topology_integration_tests)
add_test(NAME ConcurrentClientsTests COMMAND concurrent_clients_tests)
Expand Down Expand Up @@ -479,6 +493,10 @@ if(GTest_FOUND)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker"
)
set_tests_properties(BulkOpsIntegrationTests PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker"
)
set_tests_properties(ErrorHandlingIntegrationTests PROPERTIES
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
LABELS "integration;docker"
Expand Down Expand Up @@ -538,7 +556,8 @@ if(GTest_FOUND)
PingIntegrationTests GetIntegrationTests GetWithMetadataIntegrationTests
PutIntegrationTests RemoveIntegrationTests RemoveWithVersionIntegrationTests
ReplaceWithVersionIntegrationTests PutIfAbsentIntegrationTests ReplaceIntegrationTests
ContainsKeyIntegrationTests ErrorHandlingIntegrationTests FromUriIntegrationTests
ContainsKeyIntegrationTests ErrorHandlingIntegrationTests BulkOpsIntegrationTests
FromUriIntegrationTests
TopologyIntegrationTests
ConcurrentClientsTests HashAwareRoutingIntegrationTests ConcurrentMultiServerTests
RetryViewIntegrationTests PingRetryIntegrationTests MultiSeedIntegrationTests
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ operation as a `std::future`.
- **Metadata and version-based (CAS) operations** — `getWithMetadata`,
`putIfAbsent`, `replace`, `containsKey`, `removeWithVersion`,
`replaceWithVersion`.
- **Bulk operations** — `putAll` / `getAll` store and fetch many entries in one
request.
- **Async API** — every operation returns a `std::future`; operations on a server
share one multiplexed connection.
- **Hash-aware routing and failover** — consistent hashing (MurmurHash3 x64_32),
Expand Down Expand Up @@ -147,6 +149,10 @@ if (auto entry = cache.getWithMetadata(key).get()) {
int64_t version = entry->metadata.version;
bool replaced = cache.replaceWithVersion(key, newValue, version).get();
}

// Bulk: store/fetch many entries in one request
cache.putAll({{k1, v1}, {k2, v2}}).get(); // std::map<ByteArray,ByteArray>
auto found = cache.getAll({k1, k2}).get(); // map of the keys that exist
```

Pass `previousValue = true` to `put`/`putIfAbsent`/`replace`/`remove` to receive
Expand Down
122 changes: 122 additions & 0 deletions docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1536,3 +1536,125 @@ parent directory, so running `coverage-diff` standalone (without first running
`coverage`, which does the mkdir) crashed with `FileNotFoundError: .../coverage/
patch.html`. Each coverage target must be independently runnable; the earlier smoke
tests masked this by always running `coverage` first.

## 2026-12-03 — Step 12 part 1: PUT_ALL + GET_ALL shipped; BULK_GET deferred

**What:** Implemented the two multi-key bulk operations `putAll` (0x2D→0x2E) and
`getAll` (0x2F→0x30) on `RemoteCache`, with `RetryView` forwarders, 10 unit tests
(`tests/unit/BulkOpsTest.cpp`, wire-layout regression vectors) and 5 end-to-end
Docker tests (`tests/integration/BulkOpsIntegrationTest.cpp`). Unit 284→294,
integration 107→112 (23→24 suites).

**API shape:** `putAll(std::map<ByteArray,ByteArray>, lifespan, maxIdle) →
future<void>`; `getAll(std::set<ByteArray>) → future<std::map<ByteArray,ByteArray>>`.
Map/set mirror Java's `Map`/`Set` signatures; `ByteArray` (`std::vector<uint8_t>`)
is ordered, so `std::map` keying is free. Missing keys are simply omitted from the
`getAll` result (not an error), matching Java `GetAllOperation`.

**Wire format (confirmed against Java + hotrod40.ksy, which agree here):**
- PUT_ALL request: `time_units(u1) + [lifespan vLong] + [maxIdle vLong] +
entry_count(vInt) + (key lp_bytes, value lp_bytes)*`. Expiration encoding is the
*same* shared encoder `put()` uses (Java `codec.writeExpirationParams`): lifespan
unit in the HIGH nibble, maxIdle in the LOW nibble. Response: status only (Void).
- GET_ALL request: `key_count(vInt) + (key lp_bytes)*`. Response:
`entry_count(vInt) + (key lp_bytes, value lp_bytes)*`.

**Routing decision:** bulk ops are dispatched like a *keyless* op via
`selectAnyServer` (same path as `ping`), NOT per-key hash routing. The whole
request goes to one server, which fans out to each key's owners — matching the
single-request structure of Java `GetAllOperation`/`PutAllOperation`. A future
optimization could split by segment and scatter/gather, but Java does not, so we
match it.

**Why BULK_GET was deferred (gotcha — STATUS.md was wrong):** the backlog listed
`BULK_GET (0x1F)`, but **0x1F is QUERY**; BULK_GET is actually **0x19→0x1A**. The
modern Java client has **no `BulkGetOperation`** (only `GetAll`/`PutAll` and the
streaming `GetAllBulk`/`PutAllBulk` publisher ops), and the `hotrod40.ksy`
`bulk_get_response` is under-specified (its `chunk` carries only a `value`, no
key). Per the AGENTS.md rule (sources disagree → stop), shipping it off that
schema would be guesswork. Deferred until a real use case justifies verifying the
live wire format against a running server. GET_ALL covers the "fetch many known
keys" need that BULK_GET's iterator style was the old answer to.

## 2026-12-03 — Bulk ops route by owner (scatter/gather), superseding the same-day single-server note

**Supersedes** the routing paragraph in the earlier 2026-12-03 Step 12 entry,
which claimed putAll/getAll send one request to a single server "matching Java".
**That was wrong** — it was based on reading only the leaf `GetAllOperation` /
`PutAllOperation` and missing the wrapper layer.

**What Java actually does:** `RemoteCacheImpl.getAllAsync`/`putAll` wrap the keys
in `GetAllBulkOperation` / `PutAllBulkOperation` (subclasses of
`HotRodBulkOperation`). `gatherOperations` resolves each key's **owner** via the
routing function and groups keys into `Map<SocketAddress, subset>`, issues one
`GetAllOperation`/`PutAllOperation` **per owner concurrently**, and `reduce`
merges the per-owner results. So each node only ever receives the keys it owns.

**What we now do (correctly):** `RemoteCache::groupKeysByConnection` routes every
key through the existing single-key selector `selectServerForKey` and groups keys
by the returned connection. In `HASH_DISTRIBUTION_AWARE` mode that yields one
group per primary owner (inheriting exclusion / proxy / seed fallback for free);
in BASIC / no-topology mode every key resolves to the bootstrap connection, so the
groups collapse to a single request (the natural fallback — nothing to partition
on without hash topology). `putAll`/`getAll` then scatter one sub-op per group via
`conn->execute` (concurrent on the wire, since execute dispatches immediately and
the multiplexed read loops handle responses) and a deferred future gathers them —
merging the maps for `getAll`, collapsing to void for `putAll`.

**Partial-failure semantics (follows D2, which diverges from Java):** this is the
one place bulk ops are deliberately NOT Java-equivalent.
- *Before send (automatic failover):* grouping routes each key via
`selectServerForKey`, so a key whose owner is unreachable at grouping time is
redirected to a reachable backup/proxy/seed. A bulk op only throws before sending
if the whole cluster is unreachable. (Same spirit as Java's routing fallback.)
- *After send (user-decided, NOT automatic):* if a sub-op is sent and then fails
(error status or dropped connection), the whole op fails — the first error is
rethrown, enriched with the union of nodes tried across all partitions (so the
failed node is in `e.triedNodes`); no partial map is returned. There is NO
automatic per-partition retry. The caller retries the whole op via `excluding(e)`,
which re-partitions the full key set minus `e.triedNodes` (coarser than Java's
per-sub-op retry, but safe — getAll is read-only, putAll re-writes idempotently).

Java differs: each partition sub-op goes through `executeOnSingleAddress`, which
auto-retries on another server (`RetryingHotRodOperation` + `addFailedServer`) up
to `maxRetries` before the aggregate fails. We intentionally do not — retry stays
user-decided (D2, `docs/ERROR_HANDLING_DESIGN.md:57,128`), exactly as for every
other op in this client. The "whole op fails if any partition fails, no partial
results" aggregate shape itself DOES match Java's `AggregateCompletionStage`.

**Why reuse selectServerForKey per key instead of a bespoke partitioner:** it
reuses the already-tested routing (owner ordering, `orderKeyCandidates`,
exclusion, proxy/seed fallback, connection pooling + lifetime) and automatically
gives the correct BASIC-mode single-group behavior. Cost is one `stateMutex_`
lock + candidate evaluation per key; acceptable for realistic bulk sizes, and
optimizable later if a hot path needs it.

**Verified:** `HashAwareRoutingIntegrationTest.BulkOpsPartitionAcrossOwners`
(60-key batch, asserts it spans ≥2 owners, then checks every entry round-trips via
putAll→get/getAll) and `BulkGetAllOmitsMissingAcrossOwners`, both against a real
3-node cluster. Integration 112→114 (still 24 suites); unit unchanged at 294.

## 2026-12-03 — Step 12 bulk-op test coverage completed to convention

**Context:** there is no numeric coverage gate or tooling in this repo (no gcov/
lcov/codecov, no CI threshold). The bar is the behavioral convention
(WORKFLOW.md: test vectors → unit tests → implementation, plus integration for
behavior, and an `excluding()` integration test per op as in
`RetryViewIntegrationTest`). A coverage review of the bulk feature found three
new-code paths no test exercised; all three are now closed:

1. **putAll non-default lifespan/maxIdle** — the expiration-encoding branches in
`putAllImpl` were only covered by a *mirror* of the logic in a unit test, never
the impl. Added `BulkOpsIntegrationTest.PutAllWithExpirationSetsMetadata`
(putAll with lifespan/maxIdle, verified via getWithMetadata).
2. **empty putAll** short-circuit — added `BulkOpsIntegrationTest.PutAllEmptyIsNoOp`.
3. **bulk + excluding() / user-decided retry** — added
`HashAwareRoutingIntegrationTest.BulkOpsExcludingRoutesAroundOwner` (cluster):
putAll/getAll via `excluding({owner})` still round-trips the full batch by
re-routing the excluded owner's partition to a backup/proxy. Exercises
`groupKeysByConnection` honoring `ctx.excludeNodes` and the RetryView forwarders.

**Still intentionally untested:** after-send partition failure via killing a node
mid-op (needs fault injection). The before-send re-route is covered by (3); the
after-send fail-the-whole-op path is simple and shared with every other op's
error handling. Final counts: unit 294, integration 117 (24 suites).
Loading
Loading