Skip to content

Skip back up of refreshable materialized view targets - #93076

Merged
jkartseva merged 17 commits into
ClickHouse:masterfrom
jkartseva:dont-backup-mv-data
Jan 6, 2026
Merged

jkartseva merged 17 commits into
ClickHouse:masterfrom
jkartseva:dont-backup-mv-data

Conversation

@jkartseva

@jkartseva jkartseva commented Dec 25, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

During BACKUP, if a table is a target of one or more refreshable materialized views and the setting backup_data_from_refreshable_materialized_view_targets is set to false, the table’s data is not copied into the backup. The exception is RMVs with APPEND refresh strategy which are always backed up.

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Introduced the backup_data_from_refreshable_materialized_view_targets backup setting to skip back up of refreshable materialized views. RMVs with APPEND refresh strategy which are always backed up.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@jkartseva jkartseva added the can be tested Allows running workflows for external contributors label Dec 25, 2025
@clickhouse-gh

clickhouse-gh Bot commented Dec 25, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f99d268]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan, targeted) failure
02980_s3_plain_DROP_TABLE_ReplicatedMergeTree FAIL cidb
02428_parameterized_view FAIL cidb
01169_old_alter_partition_isolation_stress FAIL cidb
02907_backup_restore_default_nullable FAIL cidb
02907_backup_mv_with_no_source_table FAIL cidb
Stateless tests (amd_binary, ParallelReplicas, s3 storage, parallel) failure
01287_max_execution_speed FAIL cidb, issue

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Dec 25, 2025
@nikitamikhaylov

nikitamikhaylov commented Dec 29, 2025 •

Copy link
Copy Markdown
Member

We need to skip backing up the data only for target tables of refreshable views. And only for those that replace the target table entirely (defined without an APPEND mode).

The idea is: a target table of a regular MV or a RMV with APPEND mode contains historical data. To recalculate it the user has to do some manual work, when a target for a regular RMV contains an intermediate data that lives not that long (for about a refresh period).

@nikitamikhaylov nikitamikhaylov self-assigned this Dec 29, 2025
@jkartseva jkartseva changed the title Skip back up of materialized view target data Skip back up of refreshable materialized view targets Dec 30, 2025
@jkartseva

Copy link
Copy Markdown
Member Author

It's ready for another look btw.
backup_restore_* test failures look irrelevant to this PR; they are happening because of ZK fault injection. I'll take a look at what can be done there in a separate fix.

2025-12-29 20:48:07 Reason: having stderror:  
2025-12-29 20:48:07 [21809f084b25] 2025.12.30 07:45:17.857848 [ 4518 ] {770bee6b-fbd7-4728-b6c8-82e4801969fa} <Error> RestoreCoordinationOnCluster: Caught exception while watching: Code: 999. Coordination::Exception: Coordination error: Connection loss, path /clickhouse/backups/restore-9bd074e7-a045-49dd-b493-8af67d30dc5e/stage/alive|. (KEEPER_EXCEPTION), Stack trace (when copying this message, always include the lines below):
2025-12-29 20:48:07 
2025-12-29 20:48:07 0. ./contrib/llvm-project/libcxx/include/__exception/exception.h:0: Poco::Exception::Exception(String const&, int) @ 0x000000003f82ae60
2025-12-29 20:48:07 1. ./ci/tmp/build/./src/Common/Exception.cpp:136: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000001e011cfc
2025-12-29 20:48:07 2. ./src/Common/Exception.h:172: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000f363adc
2025-12-29 20:48:07 3. ./src/Common/Exception.h:58: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000f362dc8
2025-12-29 20:48:07 4. ./src/Common/Exception.h:190: Coordination::Exception::Exception<char const*, String const&>(Coordination::Error, FormatStringHelperImpl<std::type_identity<char const*>::type, std::type_identity<String const&>::type>, char const*&&, String const&) @ 0x0000000013e64f50
2025-12-29 20:48:07 5. ./src/Common/ZooKeeper/KeeperException.h:51: Coordination::Exception::fromPath(Coordination::Error, String const&) @ 0x0000000013e64dac
2025-12-29 20:48:07 6. ./ci/tmp/build/./src/Common/ZooKeeper/ZooKeeper.cpp:563: zkutil::ZooKeeper::existsWatch(String const&, Coordination::Stat*, Coordination::WatchCallbackPtrOrEventPtr) @ 0x0000000034fa92cc
2025-12-29 20:48:07 7. ./ci/tmp/build/./src/Common/ZooKeeper/ZooKeeper.cpp:544: zkutil::ZooKeeper::exists(String const&, Coordination::Stat*, std::shared_ptr<Poco::Event> const&) @ 0x0000000034fa4514
2025-12-29 20:48:07 8. ./ci/tmp/build/./src/Common/ZooKeeper/ZooKeeperWithFaultInjection.cpp:260: DB::ZooKeeperWithFaultInjection::exists(String const&, Coordination::Stat*, std::shared_ptr<Poco::Event> const&) @ 0x0000000035087e54
2025-12-29 20:48:07 9. ./ci/tmp/build/./src/Backups/BackupCoordinationStageSync.cpp:512: DB::BackupCoordinationStageSync::createAliveNode(std::shared_ptr<DB::ZooKeeperWithFaultInjection>) @ 0x0000000028cb7964
2025-12-29 20:48:07 10. ./ci/tmp/build/./src/Backups/BackupCoordinationStageSync.cpp:478: DB::BackupCoordinationStageSync::watchingThread() @ 0x0000000028cb6f70
2025-12-29 20:48:07 11. ./contrib/llvm-project/libcxx/include/__functional/function.h:508: ? @ 0x0000000021756b00
2025-12-29 20:48:07 12. ./contrib/llvm-project/libcxx/include/future:1601: std::packaged_task<void ()>::operator()() @ 0x0000000021757050
2025-12-29 20:48:07 13. ./contrib/llvm-project/libcxx/include/__functional/function.h:508: ? @ 0x000000001e2b7fc0
2025-12-29 20:48:07 14. ./contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: ThreadFromGlobalPoolImpl<false, true>::ThreadFromGlobalPoolImpl<void (ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::ThreadFromThreadPool::*)(), ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::ThreadFromThreadPool*>(void (ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::ThreadFromThreadPool::*&&)(), ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::ThreadFromThreadPool*&&)::'lambda'()::operator()() @ 0x000000001e2c391c
2025-12-29 20:48:07 15. ./contrib/llvm-project/libcxx/include/__functional/function.h:508: ? @ 0x000000001e2b2e3c
2025-12-29 20:48:07 16. ./contrib/llvm-project/libcxx/include/__type_traits/invoke.h:0: void* std::__thread_proxy[abi:ne210105]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, void (ThreadPoolImpl<std::thread>::ThreadFromThreadPool::*)(), ThreadPoolImpl<std::thread>::ThreadFromThreadPool*>>(void*) @ 0x000000001e2bfd30
2025-12-29 20:48:07 17. asan_thread_start(void*) @ 0x000000000f311628
2025-12-29 20:48:07 18. ? @ 0x0000000000080398
2025-12-29 20:48:07 19. ? @ 0x00000000000e9e9c
2025-12-29 20:48:07  (version 26.1.1.197)

Comment thread src/Backups/BackupEntriesCollector.cpp Outdated
if (!table || table->getName() != "MaterializedView")
return false;

const auto * mv = dynamic_cast<const StorageMaterializedView *>(table.get());

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.

Why dynamic_cast here? Should we throw an exception in case if this case returns nullptr?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

isRefreshable and getTargetTable is not a part of IStorage interface:

bool isRefreshable() const { return refresher.ptr != nullptr; }

StoragePtr getTargetTable() const;

Sure, I think a mismatch should be a LOGICAL_ERRROR

@jkartseva
jkartseva force-pushed the dont-backup-mv-data branch from cb76bf0 to 9160aa5 Compare January 6, 2026 00:20
@jkartseva
jkartseva force-pushed the dont-backup-mv-data branch from 9160aa5 to f99d268 Compare January 6, 2026 01:46
@jkartseva
jkartseva enabled auto-merge January 6, 2026 05:20
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 6, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jan 6, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jan 7, 2026
@vitlibar

vitlibar commented Jan 8, 2026

Copy link
Copy Markdown
Member

This PR added caused a new segmentation fault (see #93673), so it seems right that this PR was reverted.

@jkartseva

Copy link
Copy Markdown
Member Author

I fixed it here, also, I moved the logic determining whether to back up data or not to an earlier stage.
@nikitamikhaylov @vitlibar Please review the resubmitted #93658

github-merge-queue Bot pushed a commit that referenced this pull request Jan 14, 2026
Resubmit 'Skip back up of refreshable materialized view targets' #93076
robot-clickhouse added a commit that referenced this pull request Jan 16, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jan 16, 2026
Backport #93658 to 25.12: Resubmit 'Skip back up of refreshable materialized view targets' #93076
robot-clickhouse added a commit that referenced this pull request Jan 17, 2026
jkartseva added a commit that referenced this pull request Jan 18, 2026
Backport #93658 to 25.11: Resubmit 'Skip back up of refreshable materialized view targets' #93076
robot-clickhouse added a commit that referenced this pull request Jan 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jan 19, 2026
Backport #93658 to 25.10: Resubmit 'Skip back up of refreshable materialized view targets' #93076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants