Repository navigation
Keeper: fix Create2 response serialization - #108909
Merged
Merged
Conversation
Contributor
|
Workflow [PR], commit [6eb18ab] Summary: ✅
AI ReviewSummaryThis PR now scopes back to the two Final Verdict
|
…ngth stat - `src/Common/ZooKeeper/tests/gtest_zookeeper.cpp`: add `Create2ResponseWireRoundTrip` test that serializes a `ZooKeeperCreate2Response` via `writeImpl`, deserializes via `readImpl`, and asserts the `path_created` and all `Stat` fields (including `dataLength`) survive the round trip. - `src/Coordination/tests/gtest_coordination_storage.cpp`: add `TestCreate2ResponseDataLength` test that runs a `Create2` request through `KeeperStorage::preprocessRequest` / `processRequest` and asserts the returned `ZooKeeperCreate2Response::zstat.dataLength` equals the size of the data written to the node.
`WriteBufferFromOwnString` is defined in `IO/WriteBufferFromString.h`, not in a separate `IO/WriteBufferFromOwnString.h` header that does not exist. The wrong include caused a fatal compile error in the `build_arm_tidy` CI job. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`CREATE_WITH_STATS` is now enabled by default, so it appears in the `enabled_feature_flags` column of `system.zookeeper_connection`. Update the reference for `02735_system_zookeeper_connection` accordingly. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`CREATE_WITH_STATS` is now enabled by default in real Keeper (`KeeperContext`). `TestKeeper` must advertise the same set of capabilities so that code using `isFeatureEnabled` against a `TestKeeper` instance sees consistent behaviour. `TestKeeperCreateRequest` already populates all `Stat` fields internally; the only missing piece was the feature-flag advertisement. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Now that `CREATE_WITH_STATS` is advertised by `TestKeeper`, it must deliver the promised semantics. - Add `Create2Response` to `IKeeper.h` (inherits `CreateResponse`, adds `Stat stat`) so callers can retrieve the node stat after a create without going through the ZooKeeper wire layer. - `TestKeeperCreateRequest::process` already computed all `Stat` fields for the newly created node; now it returns them in a `Create2Response` instead of the bare `CreateResponse`. - `TestKeeperCreateRequest::createResponse` (used for the error-fill path in multi-transactions) likewise returns `Create2Response`. - Add `TestKeeperTest/Create2ResponseHasStatInMulti` regression test that verifies the response type and that `dataLength` is correct when a `CreateRequest` with `include_stats = true` is issued through the `multi` path. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…nclude_ttl Previously TestKeeperCreateRequest::process always returned Create2Response, exposing stat fields even for plain CreateRequest (include_stats == false). This violated the real Keeper contract where ZooKeeperCreateRequest::makeResponse returns a bare CreateResponse unless the opcode is Create2 or CreateTTL. Now the condition mirrors production: - include_stats || include_ttl → Create2Response (stat populated from container) - otherwise → plain CreateResponse createResponse (used for the failed-subrequest placeholder in multi transactions) follows the same condition. Extend the regression test to assert both sides of the contract: a plain create sub-request must NOT be dynamic_cast-able to Create2Response. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…on duplicate
When not_exists=true and the node already exists, TestKeeperCreateRequest::process
returns error=ZOK but leaves path_created empty (the node was not created).
The previous stat-lookup guarded on error==ZOK, so container.at("") threw.
Guard on !path_created.empty() instead: stat is only meaningful when a node
was actually inserted into the container.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
`TestKeeperCreateRequest::process` was treating `not_exists=true` as a
blanket "always succeed on duplicate" flag regardless of the effective
opcode, so a `Create2` request on an already-existing node returned
`ZOK` instead of `ZNODEEXISTS`.
Real Keeper (and `ZooKeeperCreateRequest::getOpNum`) have a clear
precedence: `Create2` and `CreateTTL` win over `CreateIfNotExists`,
meaning a duplicate is always rejected with `ZNODEEXISTS` when
`include_stats` or `include_ttl` is set.
Apply the same precedence in `TestKeeper`:
```cpp
if (not_exists && !include_stats && !include_ttl)
base_response.error = Error::ZOK; // pure CreateIfNotExists
else
base_response.error = Error::ZNODEEXISTS;
```
Also add `Create2DuplicateReturnsZNodeExists` regression test that
exercises both `not_exists=false` and `not_exists=true` with
`include_stats=true`, and the `include_ttl=true` variant.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Addresses the two remaining TestKeeper divergences flagged by the AI review on the PR: - A duplicate `CreateIfNotExists` (`not_exists`, no stats/ttl) now reports the requested path in `path_created`, matching `KeeperStorage::process`. Previously it returned `ZOK` with an empty `path_created`, so consumers reading `CreateResponse::path_created` (e.g. from `multi`) behaved differently under `implementation=testkeeper` than against real Keeper. - TTL creates now undergo the same preflight validation as `KeeperStorage::preprocess`: creating under a TTL parent, combining `include_ttl` with an ephemeral node, and a non-positive or out-of-range `ttl` are all rejected with `ZBADARGUMENTS`. Previously TestKeeper accepted TTL creates that real Keeper rejects. The TTL bound `MAX_TESTKEEPER_TTL_MS` mirrors `MAX_KEEPER_TTL_MS`; it is duplicated in the Common/ZooKeeper layer because TestKeeper must not depend on the Coordination layer. Adds two focused regressions in `gtest_testkeeper.cpp`: duplicate `CreateIfNotExists` asserts `path_created == path`, and invalid TTL requests return `ZBADARGUMENTS` without creating a node (while a valid TTL create at the maximum bound succeeds). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
unintended
force-pushed
the
fix_create2_method
branch
from
July 7, 2026 17:30
f88925c to
794419d
Compare
`ZooKeeperCreateRequest::getOpNum` maps `not_exists` to `CreateIfNotExists`, and `KeeperStorage::preprocess` rejects a sequential `CreateIfNotExists` with `ZBADARGUMENTS` before the node-existence lookup. TestKeeper had no such check, so a request built via `zkutil::makeCreateRequest(path, data, CreateMode::PersistentSequential, /*ignore_if_exists=*/ true)` fell through to the normal create path (or the duplicate `ZOK` branch) under `implementation=testkeeper` instead of failing closed, letting tests pass against TestKeeper where real Keeper would reject the same multi request. Restructure `TestKeeperCreateRequest::process` to mirror the check order of `KeeperStorage::preprocess` (parent existence/kind, then `is_sequential` with `not_exists`, then node existence, then TTL validation) so the same request yields the same error code, and add a focused regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…efix KeeperStorage::preprocess appends the sequence suffix to path_created before checking whether the node already exists, so a legal CreateMode::PersistentSequential create still succeeds even when the unsuffixed prefix is already present. TestKeeper's duplicate check still probed container.contains(path) (the raw prefix), so a sequential create on a prefix that already existed as a literal node wrongly returned ZNODEEXISTS instead of creating the suffixed path like real Keeper. Move the existence check to the final path_created (after appending the sequence suffix), and add a focused regression test for the prefix-collision case.
Don't enable `CREATE_WITH_STATS` by default and drop the `TestKeeper` work that existed only to keep it consistent with real Keeper once default-enabled (feature-flag advertisement, `Create2Response` support, and the duplicate/TTL/sequential-create contract fixes). Keep the `ZooKeeperCreate2Response::readImpl` fix and the `stat.dataLength` fix in `KeeperStorage::preprocess`, which are the actual serialization bugs this PR is about.
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 48/48 (100.00%) · Uncovered code |
antonio2368
approved these changes
Jul 9, 2026
This was referenced Jul 17, 2026
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
Keeper: fix Create2 response serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keeper: fix Create2 response serialization
Create2(OpNum::Create2) is the ZooKeeper opcode that returns the created node'sStatas part of the create response. It was already implemented in Keeper, but two issues prevented it from working correctly:1.
dataLengthmissing from the create response stat.In
preprocessfor create requests, theCoordination::Statpassed toprepareCreateNodehaddataLengthleft at zero. TheCreate2response was therefore always returningdataLength = 0regardless of the actual node data size.2.
ZooKeeperCreate2ResponsemissingreadImpl.ZooKeeperCreate2ResponseoverrodewriteImpl(writingpath_created+zstat) but notreadImpl, so it inheritedZooKeeperCreateResponse::readImpl, which only readspath_created. Any code path that reads aCreate2response (e.g. a ClickHouse ZooKeeper client receiving a response from Keeper) would silently leavezstatuninitialized. This is now made symmetric.Changelog category (leave one):
Changelog entry:
Fixed ClickHouse Keeper returning incorrect
dataLength = 0in theStatofCreate2responses, and missing deserialization ofzstatinZooKeeperCreate2Response::readImpl.Version info
26.7.1.706(included in26.7and later)