Repository navigation
Conversation
Adds a `max_rows` setting for `Atomic` and `Ordinary` databases (issue ClickHouse#109355): a ceiling on the total active rows across the database's tables, enforced on INSERT and ATTACH. Also exposes the current count via the new `system.databases.rows` column. Default 0 keeps current (unlimited) behavior. The count is summed on demand from each table's active rows (MergeTree reports its rows, other engines contribute 0), mirroring how the sibling `max_tables` setting reads `tables.size()`. This avoids a maintained counter and its trade-offs (see PR description).
max_rows database setting for Atomic/Ordinary databases
max_rows database setting for Atomic/Ordinary databasesmax_rows database setting for Atomic/Ordinary
max_rows database setting for Atomic/Ordinarymax_rows setting for databases
Two gaps in the `max_rows` check (issue ClickHouse#109355): - `DatabaseOnDisk::createTable` counted rows before `waitDatabaseStarted`, so with `async_load_databases` still-loading tables were undercounted. Count after the wait. - `RENAME`/`EXCHANGE TABLES` across databases go through `DatabaseAtomic::renameTable`, not `createTable`, bypassing the limit. Enforce the destination's `max_rows` there, under the mutexes already held, via a new `getCurrentRowCountUnlocked`.
- Fix a self-deadlock on the cross-database RENAME/EXCHANGE limit check: the throw path called `getDatabaseName`, which locks the database mutex already held by `renameTable`. Read the `database_name` member directly, as the surrounding code does. Only the throwing path was affected. - Drop `issue ClickHouse#109355` from comments and condense or remove the obvious ones. - Dedup the repeated `getStorageID().getDatabaseName()` in the INSERT check. - Extend `04612_database_max_rows` with cross-database RENAME/EXCHANGE that exceed the destination's `max_rows` and are rejected.
# Conflicts: # src/Databases/DatabaseOrdinary.cpp
Throw `NOT_IMPLEMENTED` instead of `SUPPORT_IS_DISABLED` when `ALTER DATABASE ... MODIFY SETTING` targets an engine that does not support these settings. This matches the base `IDatabase` behavior and the semantics of the code: the operation is not implemented for that engine, rather than a feature disabled at build or configuration time. Also condense the `max_rows` setting description to match the concise style of the surrounding database metadata settings.
`DatabaseOnDisk::renameTable` moved a table into the destination database and only enforced `max_rows` inside the final `createTable` call, which runs after the data has been physically moved and the source table has been detached. A rejection there left the table orphaned. Check the destination's row limit up front, next to `checkMetadataFilenameAvailability` and before the move, so a rejection is rolled back by the existing catch. This covers the `Ordinary` and engine-conversion rename paths that go through `DatabaseOnDisk::renameTable`; the same-engine `Atomic` path already checked before moving. Word the limit message for both attach and rename, and add an `Ordinary` rename regression test.
|
Workflow [PR], commit [2c0ed6b] Summary: ✅
AI ReviewSummaryAdds the best-effort Missing context / blind spots
Final VerdictStatus: ✅ Approve |
In the ParallelReplicas lanes the table's single mark goes to whichever replica asks the in-order coordinator first. When a remote replica wins, the FileOpen/S3GetObject counts land in its own query_log row (is_initial_query = 0, current_database = 'default'), which the `current_database = currentDatabase()` filter drops, so the check read 0 (seen on PR ClickHouse#111166: FileOpen 0 instead of 6). Sum the counter over all rows whose initial_query_id is one of the test's queries, as done for the prewarm mark cache tests in ClickHouse#124942. Replicas without a range open nothing, so the sums are exact and the references are unchanged; without parallel replicas each group is the initiator row alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…EPLACE PARTITION FROM` Add a regression for `MergeTree` and `ReplicatedMergeTree`: with `max_rows = 100`, 60 filler rows and a 30-row destination partition, replacing it from a 50-row source must throw `TOO_MANY_ROWS` and leave the destination intact, while replacing it from a 40-row source must succeed and leave 100 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged the latest |
# Conflicts: # src/Interpreters/DatabaseCatalog.cpp
|
🕵 Public CI on |
|
🕵 Merged the latest |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111166&sha=e9c24a6f9cb490c1e516c948207114369ec359bd&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28arm_asan_ubsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The abort is an out-of-bounds |
|
This is the abort that #126768 fixes (my PR, open, waiting for review).
#126768 removes that fallback: every written column must have a field id in the latest schema (the check Parquet already did, now for every format), otherwise the INSERT fails with |
|
@alexey-milovidov can you please review? It's max_rows from your issue, similar approach as your max_tables PR. CI is green, threads resolved. |
|
🕵 Automated check on head |
# Conflicts: # src/Databases/DatabasesCommon.h
|
🕵 Merged the latest The red checks on the previous head were all six |
|
🕵 The only red check was |
Closes: #109355
Adds a
max_rowssetting forAtomicandOrdinarydatabases: a ceiling on active MergeTree rows counted toward the database limit. It is enforced onINSERT,ATTACH, and partition-import/move operations. A batchINSERTmay overshoot, and the nextINSERTthrowsTOO_MANY_ROWS.Enforcement is a best-effort snapshot check, not a reservation spanning the commit: concurrent operations may each observe free headroom and transiently overshoot the limit together; the next checked operation then fails. On replicated attach paths the limit is charged only for parts that ZooKeeper actually accepts: an
ATTACHdeduplicated by its block id stays a no-op even when the database is over the limit, and a partially duplicatedATTACH PARTITION FROMpays only for the accepted remainder. A multi-partATTACH PARTITIONis all-or-nothing: the rows of the parts ZooKeeper will accept are validated together before the first part is committed, so the command never leaves a partially attached partition behind.The counted total is exposed through the nullable
system.databases.rowscolumn. It intentionally excludes engines that do not participate inmax_rowsaccounting. The setting can be changed at runtime withALTER DATABASE ... MODIFY SETTING max_rows = N; its default value,0, is unlimited.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add the
max_rowssetting forAtomicandOrdinarydatabases, limiting active MergeTree rows counted across a database. It is enforced onINSERT,ATTACH, and partition imports as a best-effort snapshot check, is reconfigurable viaALTER DATABASE ... MODIFY SETTING, and is exposed throughsystem.databases.rows.Workflow [PR]
Sync PR [sync-upstream/pr/111166]