feat: Allow ALTER TABLE to modify the skip_wal option dynamically#7550
feat: Allow ALTER TABLE to modify the skip_wal option dynamically#7550OmCheeLin wants to merge 11 commits intoGreptimeTeam:mainfrom
Conversation
Signed-off-by: OmCheeLin <19563671928@163.com>
Signed-off-by: OmCheeLin <19563671928@163.com>
Signed-off-by: OmCheeLin <19563671928@163.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for dynamically modifying the skip_wal table option via ALTER TABLE SET/UNSET syntax, enabling users to toggle WAL on or off at runtime without recreating tables.
Key changes:
- Extended SQL syntax to support
ALTER TABLE <table> SET 'skip_wal'='true'/'false'andALTER TABLE <table> UNSET 'skip_wal' - Implemented immediate in-memory WAL option changes at the region level, setting wal_options to Noop (disabled) or RaftEngine/Kafka (enabled)
- Added metadata persistence for skip_wal changes in both TableInfo and DatanodeTableValue, ensuring consistency across restarts
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cases/standalone/common/alter/alter_table_skip_wal.sql | Integration test verifying skip_wal can be set, unset, and persists across restarts |
| tests/cases/standalone/common/alter/alter_table_skip_wal.result | Expected output for skip_wal integration tests |
| src/store-api/src/region_request.rs | Added SkipWal variant to SetRegionOption and UnsetRegionOption enums with proper parsing |
| src/table/src/metadata.rs | Updated TableMeta to handle SetRegionOption::SkipWal in set_table_options method |
| src/mito2/src/worker/handle_alter.rs | Implemented in-memory WAL option switching in handle_alter_region_options_fast and new_region_options_on_empty_memtable |
| src/query/src/sql/show_create_table.rs | Modified SHOW CREATE TABLE to display skip_wal option in WITH clause |
| src/common/meta/src/key/datanode_table.rs | Enhanced build_update_table_options_txn to support updating region WAL options alongside region options |
| src/common/meta/src/key.rs | Updated update_table_info signature to accept optional new_region_wal_options parameter for persistence |
| src/common/meta/src/ddl/alter_table.rs | Added WAL options allocation logic when skip_wal changes, calling wal_options_allocator |
| src/common/meta/src/ddl/alter_table/executor.rs | Updated on_alter_metadata signature to pass new_region_wal_options through |
| src/common/meta/src/ddl/table_meta.rs | Exposed wal_options_allocator() method on TableMetadataAllocator |
| src/common/meta/src/ddl/alter_logical_tables/executor.rs | Updated update_table_info call with None for new_region_wal_options |
| src/common/meta/src/ddl/create_logical_tables/update_metadata.rs | Updated update_table_info call with None for new_region_wal_options |
| src/common/meta/src/reconciliation/reconcile_table/update_table_info.rs | Updated update_table_info call with None for new_region_wal_options |
| scripts/fetch-dashboard-assets.sh | Increased curl timeout values for improved download reliability (unrelated change) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| CREATE TABLE skip_wal_test ( | ||
| host STRING, | ||
| cpu_util DOUBLE, | ||
| ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(), | ||
| TIME INDEX(ts) | ||
| ); | ||
|
|
||
| -- Test setting skip_wal to true | ||
| ALTER TABLE skip_wal_test SET 'skip_wal'='true'; | ||
|
|
||
| SHOW CREATE TABLE skip_wal_test; | ||
|
|
||
| -- Test setting skip_wal to false | ||
| ALTER TABLE skip_wal_test SET 'skip_wal'='false'; | ||
|
|
||
| SHOW CREATE TABLE skip_wal_test; | ||
|
|
||
| -- Test unsetting skip_wal (should set to false) | ||
| ALTER TABLE skip_wal_test UNSET 'skip_wal'; | ||
|
|
||
| SHOW CREATE TABLE skip_wal_test; | ||
|
|
||
| -- Test setting skip_wal to true again | ||
| ALTER TABLE skip_wal_test SET 'skip_wal'='true'; | ||
|
|
||
| SHOW CREATE TABLE skip_wal_test; | ||
|
|
||
| -- SQLNESS ARG restart=true | ||
| -- Verify persistence after restart | ||
| SHOW CREATE TABLE skip_wal_test; | ||
|
|
||
| DROP TABLE skip_wal_test; | ||
|
|
There was a problem hiding this comment.
The test only verifies that the skip_wal option is correctly displayed in SHOW CREATE TABLE and persists across restarts. Consider adding tests that verify actual data write behavior when toggling skip_wal, such as:
- Write data with skip_wal=true
- Toggle to skip_wal=false
- Write more data
- Verify all data is retrievable after restart (data written with skip_wal=true should not be lost after toggle)
| local filename=$2 | ||
|
|
||
| curl --connect-timeout 10 --retry 3 -fsSL $url --output $filename || { | ||
| curl --connect-timeout 30 --max-time 60 --retry 3 -fsSL $url --output $filename || { |
There was a problem hiding this comment.
This change increases curl timeouts from 10s connection timeout with 3 retries to 30s connection timeout, 60s max time, with 3 retries. While this may improve reliability, this change appears unrelated to the skip_wal feature. Consider moving this to a separate PR or explaining its relevance to this feature in the PR description.
Signed-off-by: OmCheeLin <19563671928@163.com>
src/mito2/src/worker/handle_alter.rs
Outdated
| // The actual WAL options will be persisted in metasrv. | ||
| // We should read the correct WAL options from DatanodeTableValue | ||
| // or pass them through the AlterRegionRequest. | ||
| current_options.wal_options = WalOptions::RaftEngine; |
There was a problem hiding this comment.
The WAL type could be Kafak
WenyXu
left a comment
There was a problem hiding this comment.
@OmCheeLin There are three things that need to be done:
- Handle metadata changes, which you’ve almost done in this PR.
- Modify the WAL provider (or set a flag to stop it from writing data into the WAL). Before doing this, make sure all data in memory has been flushed to the WAL.
- Review the batch open logic for regions using Kafka options to make sure your changes work correctly with it.
You need to add new tests to cover these cases, make sure there are enough assertions so that all components behave as expected.
src/mito2/src/worker/handle_alter.rs
Outdated
| ); | ||
| } | ||
| } | ||
| SetRegionOption::SkipWal(skip_wal) => { |
There was a problem hiding this comment.
We can’t set the WAL options to RaftEngine; they could be Kafka. It would be better to let the MetaSrv send the detailed configuration.
src/mito2/src/worker/handle_alter.rs
Outdated
|
|
||
| current_options.sst_format = Some(new_format); | ||
| } | ||
| SetRegionOption::SkipWal(skip_wal) => { |
There was a problem hiding this comment.
If only the WAL options are configured, the underlying WAL provider is not affected, so the region continues writing data to the WAL.
|
|
||
| // Safety: region distribution is set in `submit_alter_region_requests`. | ||
| // Check if skip_wal changed and update WAL options if needed | ||
| let current_skip_wal = table_info_value.table_info.meta.options.skip_wal; |
There was a problem hiding this comment.
I prefer not to reallocate the WAL options, since a region might start writing to a different Kafka topic after reallocation, which could cause problems.
|
Sorry, I accidentally closed the PR. |
Signed-off-by: OmCheeLin <19563671928@163.com>
Signed-off-by: OmCheeLin <19563671928@163.com>
|
I have encountered some issues that need further confirmation at present. Should we modify the proto? |
Could you explain the details of the issue? |
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
What's changed and what's your intention?
This PR adds support for dynamically modifying the
skip_waltable option viaALTER TABLE SET/UNSETsyntax, allowing users to toggle WAL on or off at runtime without recreating tables.changes:
ALTER TABLE <table> SET 'skip_wal'='true'/'false'andALTER TABLE <table> UNSET 'skip_wal'skip_walis altered, the change is immediately applied to all regions in memory viahandle_alter_region_options_fast(), settingwal_optionstoNoop(disabled) orRaftEngine(enabled).TableInfoandDatanodeTableValueentries in metasrv, ensuring consistency across restarts.skip_waloption in theWITHclause.Limitations
skip_wal=false), the current implementation usesRaftEngineas default. The correct WAL options (e.g., Kafka topic) allocated by metasrv are persisted inDatanodeTableValueand will be loaded correctly on region restart, but the in-memory version may temporarily showRaftEngineeven if the actual WAL is Kafka. This is documented with a TODO for future improvement.PR Checklist