Repository navigation
Keeper log s3 - #123451
Keeper log s3#123451alexey-milovidov wants to merge 104 commits into
Conversation
# Conflicts: # src/Coordination/Changelog.cpp # src/Coordination/CoordinationSettings.cpp # src/Coordination/KeeperContext.h # src/Server/KeeperTCPHandler.cpp
# Conflicts: # src/Coordination/KeeperContext.h
The previous declaration had `false` in the default position and `500` in the flags position, which is wrong. Default value is `500` and flags are `0`. Also clarified that units are microseconds in the description. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
These were added during development of the S3 changelog feature and got left in. They sit on the hot path of every Keeper request and would materially increase log volume on busy nodes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The S3 changelog code resolved its disk via a literal string `some_s3_plain`, which would fail in any deployment that didn't happen to define a disk by that exact name. Add a configuration option `keeper_server.coordination_settings.s3_log_disk` and resolve through it, throwing `BAD_ARGUMENTS` if the feature is enabled but no disk is configured. Update the integration test config accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The previous code reconstructed a reader as \`ReadBufferFromMemory(write_buffer->buffer().begin(), write_buffer->count())\` when moving a flushed changelog to a path that reflects the actual range of written indices. This combines a pointer into the current in-memory write chunk with the cumulative byte count of everything ever written through the buffer. For an S3 multipart upload most of those bytes have already been streamed out and are no longer addressable in process memory, so this would read out of bounds. Finalize the write at the original path first, then copy from the old path to the new path via the disk's reader/writer, then remove the file at the old path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The merge of master into the PR branch pulled in updates to `.github/workflows/...`, but the OAuth token used to push lacks the `workflow` scope, so the push is rejected by GitHub. PR CI uses workflow files from the base branch (master), not the head branch, so reverting these on the head has no functional effect. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ClickHouse style requires opening braces on a new line. The PR's added code in `Changelog.cpp` and `KeeperContext.cpp` used K&R style throughout, which made the Style check (cpp) job fail. Also switch \`#include \"base/types.h\"\` to \`#include <base/types.h>\` for the same reason. See: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=79991&sha=fcf915708cc86ed112e356e79315c6677c571a5e&name_0=PR&name_1=Style%20check Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`std::chrono` and `std::thread` are not used anywhere in this file. The file uses `ThreadFromGlobalPool` from `Common/ThreadPool.h` instead of `std::thread`, and has no `<chrono>` symbols at all. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
# Conflicts: # .github/workflows/master.yml # .github/workflows/pull_request.yml
# Conflicts: # .github/workflows/pull_request.yml
The merge of master into the PR branch pulled in updates to `.github/workflows/...`, but the OAuth token used to push lacks the `workflow` scope, so the push is rejected by GitHub. PR CI uses workflow files from the base branch (master), not the head branch, so reverting these on the head has no functional effect. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Workflow files in this branch were stale or had been deleted as a workaround for GitHub's workflow-scope check. Restoring them to match `master` so the PR diff no longer contains those unrelated changes.
Three issues from the Bugbot review on commit fddb3be: 1. **High severity**: `s3CompactionThread` held `writer_mutex` across all the slow S3 I/O (`writeFile`, `readFile`, `copyData`, `sync`, `finalize`, `removeFile`) because the `std::lock_guard` was declared *outside* the inner braces that were supposed to scope it. The write thread also acquires `writer_mutex` to call `appendRecord` and `flush`, so it was completely stalled during a merge, which can take seconds for large segments and is enough to trigger Raft leadership timeouts. Split the critical section in two: one short region for the planning pass that picks the changelogs to merge, then unlock for the S3 I/O, then re-lock for the publish step (`existing_changelogs.erase`/insert and `last_merged_index` update). The `removeFile` calls run unlocked — they only delete files that are already unlisted from `existing_changelogs`. 2. **Medium severity**: `S3ChangelogWriter::finalize` unconditionally called `flush`, which dereferences `last_index_written` via `*last_index_written + 1`. When no records were ever appended (e.g. immediate shutdown after startup), the optional is empty and this is undefined behavior. The local `ChangelogWriter::finalize` is guarded by `isFileSet() && prealloc_done`; mirror that and only flush when `last_index_written.has_value()`. 3. **Low severity**: `KeeperContext::s3_flush_interval` was declared without a default initializer, while the adjacent `s3_experimental_changelog{false}` has one. Initialize to `500` to match the config default.
The previous workflow restore commit (fddb3be) only touched `.github/workflows/*`. These two files were also affected by the master merge and need to match master: - `.github/dependabot.yaml`: re-add the cargo entries for `/rust/chcache` and `/rust/workspace` that suppress Rust crate Dependabot updates (those crates must be refreshed manually with `vendor.sh`, so the suppression is intentional). This addresses the Cursor Bugbot review on commit 706b0fb. - `.github/PULL_REQUEST_TEMPLATE.md`: drop the extra "Documentation entry" section that no longer exists on master.
Address the long-standing review comment that the integration test silently relies on the static config to enable `s3_experimental_changelog` and never explicitly verifies that any changelog data actually reaches S3. The commented-out blocks below the existing scenario were drafts for local-to-S3 and S3-to-local migration, which are not part of the planned experimental feature — drop them per the maintainer ask, and instead list the MinIO bucket under the configured changelog prefix and assert that at least one `changelog_*` segment landed there after the `RaftInstance: commit upto 33` checkpoint.
`KeeperContext::initialize` reads `keeper_server.coordination_settings.s3_log_disk` directly from the XML config, but the strict `CoordinationSettings::loadFromConfig` iterates every child of `<coordination_settings>` and calls `BaseSettings::set`, which rejects keys that are not declared in `LIST_OF_COORDINATION_SETTINGS`. With `s3_experimental_changelog=true`, the test config places `<s3_log_disk>` under `<coordination_settings>` alongside the two already-declared `s3_experimental_changelog` and `s3_flush_interval` settings. `loadFromConfig` then threw `UNKNOWN_SETTING` at boot, preventing the `node_logs` container from starting and producing the five `test_keeper_s3_changelog/test.py::test_correctness` failures in the `amd_asan_ubsan`, `amd_asan_ubsan db disk old analyzer`, `amd_tsan`, `amd_msan`, and `amd_llvm_coverage` integration runs. Declare `s3_log_disk` as a `String` setting (and add `String` to `COORDINATION_SETTINGS_SUPPORTED_TYPES`) so the existing direct `config.getString` lookup in `KeeperContext` keeps working and the strict loader accepts the element. CI report: #79991
These changes to CI workflow / infrastructure files were unrelated to the purpose of this pull request and were introduced accidentally (stale base branch). Restoring them to match `master`.
…3_log_disk` - Every upload of the S3 changelog writer and of the compaction thread now stages under its own `s3_in_progress_<n>_` key, and the writer keeps the key it chose until `flushImpl` publishes it. With a shared key, a merge still uploading into `s3_in_progress_changelog_1_16.bin` could finalize after a foreground rewrite of `changelog_1_16.bin` finalized, and the foreground flush would publish the old merge payload as durable. - `s3_log_disk` must now have `Plain` metadata (`s3_plain`). An `s3` disk locates files through local metadata files that are truncated and rewritten in place without a sync, so an atomic upload does not make publication crash-safe there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
When `writeAt` reopens a published segment and the rewrite keeps its range (`changelog_1_16.bin` rewritten from index 16), `flushImpl` copied the new version onto the same key. A failed `copyFile` rolls back by removing its destination, which deleted the only durable copy of the segment, and a `s3_plain` disk with `object_metadata_cache_size` kept the size of the replaced object, so reads past the old end returned EOF. Publish such a rewrite under the same range with an extra `rewrite` name component instead (and the next rewrite without it again). The name parser already ignores the components after the range, and startup keeps the larger of two objects with the same start index, which is the new version. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fresh segment `S3ChangelogWriter::flushImpl` installed the next segment but kept `last_index_written` from the previous one. After `compact` rotated the active segment to `up_to_log_index + 1` on snapshot recovery, an empty `flush` called `flushImpl(*last_index_written + 1)` and moved the start back to the old frontier, so the next append was published under a stale range such as `changelog_51_1000001.bin`. Reset `last_index_written` once the fresh object is open, so an empty `flush` is a no-op as intended. The "nothing appended" branch of `flushImpl` is now an ordinary path (e.g. `rotate` right after a flush), so log it at trace level instead of as a warning. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| && current_writer->getCurrentFileDescription() && current_writer->getStartIndex() <= up_to_log_index) | ||
| { | ||
| LOG_INFO(log, "Rotating the active S3 changelog segment because this node recovers from snapshot"); | ||
| need_rotate = true; |
There was a problem hiding this comment.
[P1] Discard buffered records when rotating past an installed snapshot
This rotation can still publish records that compact has just discarded. The S3 active segment is unlisted, so when it contains buffered entries 1..5 and a leader snapshot compacts through 100, the removal loop misses it. After entry_storage.cleanUpTo(101), rotate calls flushImpl, which publishes changelog_1_5.bin and queues those five locations again. The next refreshCache restores getStartIndex to 1 although the next slot is 101; the retained interval now has missing locations 6..100, so reads and subsequent cleanup encounter exceptions.
NuRaft's snapshot-install path calls compact without draining the asynchronous append writer, so it does not guarantee an empty active buffer. A compiled probe using the current writer and compact bodies with a mocked disk/cache reproduced the start changing from 101 to 1 after refresh.
Please cancel/discard the superseded buffer and its pending locations before opening the post-snapshot segment, and fence queued pre-snapshot writes as necessary. Cover snapshot installation with buffered, unflushed records, followed by cache refresh and another compaction.
There was a problem hiding this comment.
🕵 Fixed in 805a4dd. On snapshot recovery (remove_all_logs), compact now calls discardAndRotate on the S3 writer instead of rotate. It cancels the open upload, drops unflushed_indices_with_log_location and last_index_written, and opens the new segment at up_to_log_index + 1, so the superseded records are never published or re-added to entry_storage. Appends queued before the snapshot are fenced in S3ChangelogWriter::appendRecord: a record below the start of the current segment is skipped, because the snapshot covers it. No automated test covers this yet. The S3 changelog has no unit-test harness, and reproducing it needs a race between snapshot installation and the async write queue, which an integration test can only hit probabilistically.
There was a problem hiding this comment.
[Blocker] The fix still skips snapshot installation at the current log tip. In src/Coordination/Changelog.cpp:5759 and :5769, both rotation and discarding require remove_all_logs, but :5720 sets it only when the snapshot index is greater than max_log_id. NuRaft's handle_snapshot_sync.cxx also installs snapshots whose index equals the local tip, provided it exceeds quick_commit_index_; it does not drain the append writer first.
For example, let max_log_id = 55 and leave entries 51..55 buffered in the unlisted S3 segment. Installing snapshot 55 calls compact(55): need_rotate stays false and cleanUpTo(56) removes the entries and their term metadata, but the buffer survives. The next flush publishes changelog_51_55.bin. After restart with the default retained-log window, startup reads those records again because their last index equals the snapshot index. If the buffered entries came from an older, conflicting leader term, term_for_log(55) now advertises that stale term in election requests instead of the installed snapshot's term. A subsequent cache refresh before restart also restores start_index = 51 while term_at(55) = 0.
Please fence buffered/queued records and pending locations against the installed snapshot frontier even when it does not exceed max_log_id, preserving any suffix beyond that frontier.
…gister S3 merges without allocating When `compact` installs a snapshot from the leader, the S3 writer's active segment may still buffer records that the snapshot superseded, because NuRaft does not drain the write queue first. `rotate` published them, re-adding their locations after `entry_storage.cleanUpTo`, so the retained range restarted at the first buffered index with the indices up to the snapshot missing. Now `compact` calls `discardAndRotate`, which cancels the open upload and drops its pending locations, and `appendRecord` skips queued records below the start of the current segment. The S3 compaction unlisted the merge sources before `scheduleRelink` and `relinked_sources.push_back`, both of which allocate. A failure there left the merged object listed with no cleanup registration, so its sources could survive on S3 and replay over a rewrite of the merged object on the next startup. The bookkeeping is now allocated before the map changes: the relink is passed as a pre-allocated `std::list` node that is spliced, `relinked_sources` capacity is reserved, and the merged object replaces the value of the first source's existing map node instead of inserting a new one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
|
🕵 The only failure on f19ad9d was |
|
🕵 Merged |
The `arm_tidy` build failed with `modernize-use-nodiscard` on `isFileSet`, `getStartIndex` and `getCurrentFileDescription` in `src/Coordination/Changelog.cpp`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123451&sha=3b15375fab6f518e1611d516c8ebbb0ac7de08b8&name_0=PR&name_1=Build%20%28arm_tidy%2C%204%2F4%29 #123451 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 The only failure on |
Experimental support for storing the Keeper changelog directly on object storage (S3) instead of a local disk, gated behind the coordination setting
s3_experimental_changelog. Enables running Keeper without a local data volume.This supersedes #79991 by @trololo23 and keeps the original commits. The branch had to be moved into the main repository because merging
mastertouches files under.github/workflows, which could not be pushed to the fork.Configuration:
keeper_server.coordination_settings.s3_experimental_changelog— enable the experimental path.keeper_server.coordination_settings.s3_log_disk— name of the disk from<storage_configuration>to use for the changelog.A background compaction thread merges adjacent S3 changelog objects. The active segment is uploaded under the
s3_in_progress_prefix (ignored and removed on startup) and published under its finalchangelog_*name on flush.Known open limitations (from the review of the original PR): merging removes the source objects while
LogEntryStoragecan still holdLogLocations pointing into them, and the compaction trigger is based onrotate_log_storage_intervalrather than the object backlog; both need anentry_storageAPI to rewrite locations.Related: #79991
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Experimental: support storing the Keeper changelog on S3, gated behind the coordination setting
s3_experimental_changelog.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123451]