Skip to content

Refreshable materialized views improvements#58934

Merged
al13n321 merged 51 commits intomasterfrom
mv4
Aug 16, 2024
Merged

Refreshable materialized views improvements#58934
al13n321 merged 51 commits intomasterfrom
mv4

Conversation

@al13n321
Copy link
Member

@al13n321 al13n321 commented Jan 18, 2024

Changelog category (leave one):

  • Improvement

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

Refreshable materialized view improvements: append mode (... REFRESH EVERY 1 MINUTE APPEND ...) to add rows to existing table instead of overwriting the whole table, retries (disabled by default, configured in SETTINGS section of the query), SYSTEM WAIT VIEW <name> query that waits for the currently running refresh, some fixes.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

A few things:

  • Append mode: ... REFRESH EVERY 1 MINUTE APPEND ... will add rows to existing table instead of overwriting the whole table. Can be used to write logs.
  • Retries (disabled by default, configured in SETTINGS section of the query).
  • SYSTEM WAIT VIEW <name> query that waits for the currently running refresh, rethrowing exception if it failed.
  • Fixed out-of-schedule refreshes advancing the schedule.
  • Fixed leaving temp table if source table is dropped.
  • Removed usage of weak_ptr<IStorage> because that's not allowed, and wasn't needed anyway.

(Still no support for DatabaseReplicated.)

Closes #59095

@robot-ch-test-poll robot-ch-test-poll added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jan 18, 2024
@robot-ch-test-poll
Copy link
Contributor

robot-ch-test-poll commented Jan 18, 2024

This is an automated comment for commit 4b9a299 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@al13n321 al13n321 force-pushed the mv4 branch 2 times, most recently from 65d6960 to b41b770 Compare January 24, 2024 01:47
@aodiwei
Copy link

aodiwei commented Jan 29, 2024

Hi, thx for your work, it's really useful, When will this feature be released?

@al13n321 al13n321 force-pushed the mv4 branch 2 times, most recently from fe15caa to c9cfcc3 Compare February 21, 2024 12:51
@al13n321 al13n321 force-pushed the mv4 branch 2 times, most recently from 809a43d to 1f7c7c5 Compare March 9, 2024 02:18
Copy link
Member

@jkartseva jkartseva left a comment

Choose a reason for hiding this comment

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

Looks great, as usual. Sorry I haven't looked at it earlier – I should start treating my backlog as a queue, not a stack.
Do you think it should be categorized as "Not for changelog" ? This PR has quite a few user-facing changes, such as new MV settings, IMO it should be classified as "improvement" and be reflected in the changelog.

Comment on lines 448 to 444
/// Drop the old table (outside the try-catch so we don't try to drop the other table if this fails).
InterpreterDropQuery::executeDropQuery(ASTDropQuery::Kind::Drop, view->getContext(), refresh_context, stale_table, /*sync*/ true, /*ignore_sync_setting*/ true);
if (table_to_drop.has_value())
view->dropTempTable(table_to_drop.value(), refresh_context);
Copy link
Member

Choose a reason for hiding this comment

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

dropTempTable doesn't throw due to the internal try-catch block, yet the previous executeDropQuery may throw. Is this the intention? Also, I think the comment "(outside the try-catch..." is outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing outdated comment, leaving the inner try-catch, the idea is that it's better to consider the refresh successful in this case to avoid retries.

executeRefreshUnlocked(append);
refreshed = true;
}
catch (...)
Copy link
Member

@jkartseva jkartseva Jun 7, 2024

Choose a reason for hiding this comment

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

Wdyt about logging exponential backoff information (possibly, with the delay duration) in addition to "Refresh failed"?

@robot-ch-test-poll robot-ch-test-poll added pr-improvement Pull request with some product improvements and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Jun 11, 2024
@al13n321
Copy link
Member Author

Wait, this makes another incompatible change: CREATE MATERIALIZED VIEW ... AS SELECT FROM foo is now rejected if table foo doesn't exist (when the MV is created). I don't remember whether this was intended and what the idea was...

Guess I'll add a compatibility setting for it.

@al13n321
Copy link
Member Author

al13n321 commented Aug 12, 2024

The integration test failure is probably unrelated to this PR. It's probably the thing @nikitamikhaylov explained to me where integration test flaky check reuses test fixture across tests, so if you touch an integration test that doesn't support fixture reuse you have to modify the test to support it. I can't easily do it here because I couldn't run the test locally:

    def _exec_run(self, cmd, **kwargs):                                                                                                                                                                                                                                               
        container = self._ensure_container()                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                      
        handle = self._docker_client.api.exec_create(container.id, cmd, **kwargs)                                                                                                                                                                                                     
        output = self._docker_client.api.exec_start(handle).decode("utf8")                                                                                                                                                                                                            
        exit_code = self._docker_client.api.exec_inspect(handle)["ExitCode"]                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                      
        logging.debug(                                                                                                                                                                                                                                                                
            "[network] %s: %s (%s): %s", container.id, cmd, exit_code, output.strip()                                                                                                                                                                                                 
        )                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                      
        if exit_code != 0:                                                                                                                                                                                                                                                            
            print(output)                                                                                                                                                                                                                                                             
>           raise subprocess.CalledProcessError(exit_code, cmd)                                                                                                                                                                                                                       
E           subprocess.CalledProcessError: Command '['iptables', '--wait', '-I', 'DOCKER-USER', '1', '-p', 'tcp', '-s', '192.168.144.10', '--dport', '2181', '-j', 'DROP']' returned non-zero exit status 1.                                                                          
                                                                                                                                                                                                                                                                                      
../tests/integration/helpers/network.py:314: CalledProcessError                                                                                                                                                                                                                       
------------------------------------------------------------------------------------------------------------------------------- Captured stdout setup --------------------------------------------------------------------------------------------------------------------------------
Copy common default production configuration from /etc/clickhouse-server. Files: config.xml, users.xml                                                                                                                                                                                
Copy common default production configuration from /etc/clickhouse-server. Files: config.xml, users.xml                                                                                                                                                                                
Copy common default production configuration from /etc/clickhouse-server. Files: config.xml, users.xml                                                                                                                                                                                
Copy common default production configuration from /etc/clickhouse-server. Files: config.xml, users.xml                                                                                                                                                                                
Copy common default production configuration from /etc/clickhouse-server. Files: config.xml, users.xml                                                                                                                                                                                
Copy common default production configuration from /etc/clickhouse-server. Files: config.xml, users.xml                                                                                                                                                                                
--------------------------------------------------------------------------------------------------------------------------------- Captured log setup ---------------------------------------------------------------------------------------------------------------------------------

(return code 1 and empty std...out? err? idk what self._docker_client.api.exec_start() captures) and last time I tried to figure out what's the problem with iptables in integration tests I failed (there are two incompatible versions of iptables, and updating ubuntu switches from one to the other, and integration tests require a specific one; you can switch the version with some command, but tests still won't work because there's some additional hidden state, not just the version?).

So I'll undo the allow_materialized_view_with_bad_select change so that this PR doesn't need to modify the integration test, so that somebody else has to modify it and not me.

@al13n321 al13n321 added this pull request to the merge queue Aug 16, 2024
Merged via the queue into master with commit cb3468f Aug 16, 2024
@al13n321 al13n321 deleted the mv4 branch August 16, 2024 18:15
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 16, 2024
@fm4v
Copy link
Member

fm4v commented Aug 16, 2024

The bugs from #68154 have not been addressed

@al13n321
Copy link
Member Author

I know, just this was very difficult to get past CI, so I merged it at first opportunity, fixes should be easier to merge.

{"use_hive_partitioning", false, false, "Allows to use hive partitioning for File, URL, S3, AzureBlobStorage and HDFS engines."},
{"allow_experimental_kafka_offsets_storage_in_keeper", false, false, "Allow the usage of experimental Kafka storage engine that stores the committed offsets in ClickHouse Keeper"},
{"allow_archive_path_syntax", true, true, "Added new setting to allow disabling archive path syntax."},
{"allow_materialized_view_with_bad_select", true, true, "Support (but not enable yet) stricter validation in CREATE MATERIALIZED VIEW"},
Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot for the clear descriptions. It helps a lot, seriously.

@MikhailBurdukov
Copy link
Contributor

Hi! @al13n321

Are we expecting such behaviour? https://fiddle.clickhouse.com/b58974e0-089b-4c1d-81ca-5695da3f040c
For ver<24.9 works fine looks like backward-incompatible changes by now.
Should we handle this case with allow_materialized_view_with_bad_select?

@al13n321
Copy link
Member Author

Yes, this PR added this sanity check, and it's not disabled by allow_materialized_view_with_bad_select. Previously such MV could be created, but wouldn't insert any rows into the target table:

create table src (x Int8) engine Memory;
create materialized view dst (y Int8) engine Memory as select x from src;
insert into src values (10);

select * from dst;

SELECT *
FROM dst

Query id: 20708ba0-186c-4a82-b3da-15daf3d2301a

Ok.

0 rows in set. Elapsed: 0.001 sec.

The correct query is select x as y from src.

@MikhailBurdukov
Copy link
Contributor

Wow, thank you!

zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 6, 2025
Refreshable materialized views improvements
zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 6, 2025
Refreshable materialized views improvements
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Oct 9, 2025
24.8.14 Stable Backport of ClickHouse#58934: Refreshable materialized views improvements
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.

[Umbrella] Refreshable Materialized View

9 participants