Skip to content

Add du and wc commands to clickhouse-disks - #106268

Merged
asya-ch merged 32 commits into
masterfrom
asya/du
Jun 25, 2026
Merged

asya-ch merged 32 commits into
masterfrom
asya/du

Conversation

@asya-ch

@asya-ch asya-ch commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

Changelog entry (a [user-readable short description]):

Add du and wc commands to clickhouse-disks. They, respectively, (a) print the total size in bytes for a given file or directory, and (b) list the number of bytes, lines, and words in a file.

Version info

  • Merged into: 26.7.1.80

@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1b6710e]

Summary: ❌

job_name test_name status info comment
Stress test (arm_debug) FAIL
Hung check failed, possible deadlock found FAIL cidb, issue ISSUE EXISTS
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/pr_body_check.py FAIL IGNORED

AI Review

Summary

This PR adds du and wc commands to clickhouse-disks, with docs and stateless coverage. The command shape is mostly aligned with the linked issue, but du still misses one object-storage case where a logical path is both an object and a prefix, so it can return an undercount instead of the promised recursive total.

Findings

⚠️ Majors

  • [programs/disks/CommandDiskUsage.cpp:63] du promises the total size below the requested path, but MetadataStorageFromPlainObjectStorage can expose one logical path as both a file and a directory prefix, for example S3 objects p and p/child. The traversal checks existsDirectory first and only calls getFileSize in the else branch, so du p and parent-directory totals skip the bytes stored in object p.
    Suggested fix: add the file size whenever existsFile(relative) is true, then also traverse children when existsDirectory(relative) is true.

💡 Nits

  • [tests/queries/0_stateless/04304_clickhouse_disks_wc.sh:2] The new wc test is still tagged no-fasttest, but this test only configures local object-storage metadata and does not document a strict Fast test blocker. Remove the tag or add the concrete reason it cannot run in Fast test.
Tests
  • ⚠️ Add a focused s3_plain regression where object p and object p/child both exist, and assert du p includes both the file bytes and child bytes.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: fix the du file-plus-prefix undercount and cover it with a focused s3_plain test.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 2, 2026
@asya-ch

asya-ch commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

The issue for this task is #105018. More commands will be added in follow-up PRs.

@Michicosun Michicosun self-assigned this Jun 2, 2026
@asya-ch asya-ch changed the title Add du command to clickhouse-disks Add du and wc command to clickhouse-disks Jun 8, 2026
@asya-ch asya-ch changed the title Add du and wc command to clickhouse-disks Add du and wc commands to clickhouse-disks Jun 8, 2026
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Tags: no-fasttest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This excludes the only new wc coverage from Fast test, while the adjacent du test uses the same local object_storage clickhouse-disks harness without no-fasttest. Repository policy is to avoid no-* tags unless they are strictly necessary; keeping this tag means regressions in the new command can pass the faster gating. Please remove it, or add a concrete reason if this test really cannot run in Fast test.

Comment thread programs/disks/CommandDiskUsage.cpp Resolved
Comment thread programs/disks/CommandDiskUsage.cpp Resolved
Comment thread programs/disks/CommandDiskUsage.cpp Resolved
Comment thread programs/disks/CommandDiskUsage.cpp Resolved
Comment thread programs/disks/CommandDiskUsage.cpp Resolved
Comment thread programs/disks/CommandDiskUsage.cpp Resolved
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 19, 2026
DatabaseCatalog::addUUIDMapping(uuid, db, table) threw a LOGICAL_ERROR when
the UUID was already mapped to a live table. During ATTACH DATABASE (and
server startup) tables are loaded via attachTable, which calls addUUIDMapping
directly with a real (database, table) pair and bypasses the empty "lock"
reservation. If two table metadata files in the loaded database declare the
same explicit UUID, the second table reaches that throw and the LOGICAL_ERROR
aborts the whole server in debug/sanitizer builds.

Two table .sql files sharing one UUID is user-controlled, external on-disk
state: it can be produced by manual edits, or by a leftover _tmp_replace_*
table from CREATE OR REPLACE TABLE ... UUID '...' that carries the same
explicit UUID as the live target table. That is a user error, not an internal
invariant violation, and the sibling branch already reports the same condition
as a non-fatal TABLE_ALREADY_EXISTS ("UUID collision, most likely because some
not random UUIDs were manually specified"). The runtime ATTACH TABLE path even
hits that friendly error today; only the load path aborts.

Report the collision as TABLE_ALREADY_EXISTS instead of LOGICAL_ERROR. The
conflicting table fails to load with a clear message, the rest of the database
attaches, and the server stays up. This covers both the ATTACH DATABASE async
load path and the server startup path.

Found by BuzzHouse (amd_tsan) on PR ClickHouse#105020 (STID 3178-4166); the family also
hit PRs ClickHouse#100047, ClickHouse#106268, ClickHouse#100703 (STID 3178-4504). New test
04340_attach_database_duplicate_uuid_no_crash reproduces the crash
deterministically and verifies the server survives.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread programs/disks/CommandDiskUsage.cpp Resolved
Comment thread programs/disks/CommandWordCount.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.30% -0.10%
Functions 92.60% 92.50% -0.10%
Branches 77.60% 77.50% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 94/99 (94.95%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@asya-ch
asya-ch requested a review from Michicosun June 24, 2026 21:56
Comment on lines +75 to +76
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this continue now is not needed

@asya-ch
asya-ch enabled auto-merge June 25, 2026 17:33
@asya-ch
asya-ch added this pull request to the merge queue Jun 25, 2026
@asya-ch
asya-ch removed this pull request from the merge queue due to a manual request Jun 25, 2026
@asya-ch
asya-ch added this pull request to the merge queue Jun 25, 2026
Merged via the queue into master with commit c5abf1c Jun 25, 2026
325 of 329 checks passed
@asya-ch
asya-ch deleted the asya/du branch June 25, 2026 18:12
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 25, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @asya-ch @Michicosun — a couple of suggestions to make this PR easier for reviewers and the changelog reader.

Description (currently incomplete):

  • Why: The body contains only the auto-generated version-info block and no explanation of the new commands, their flags (-h/--human-readable, -c/-l/-w), or behavior (Unix wc output order, recursive directory sizing). The docs diff covers this but the PR description itself is essentially empty.

  • Suggested addition:

    Adds du [--human-readable] [<path>] (recursive total size of a file/directory) and wc <path> [--bytes] [--lines] [--words] (byte/line/word counts, Unix order lines/words/bytes) to clickhouse-disks. Tested against local, plain, plain_rewritable and s3_plain metadata backends.

Ignore this if the current title/body is intentional.

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Add du and wc commands to clickhouse-disks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants