Skip to content

feat: Allow ALTER TABLE to modify the skip_wal option dynamically#7550

Draft
OmCheeLin wants to merge 11 commits intoGreptimeTeam:mainfrom
OmCheeLin:skip_wal
Draft

feat: Allow ALTER TABLE to modify the skip_wal option dynamically#7550
OmCheeLin wants to merge 11 commits intoGreptimeTeam:mainfrom
OmCheeLin:skip_wal

Conversation

@OmCheeLin
Copy link

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_wal table option via ALTER TABLE SET/UNSET syntax, allowing users to toggle WAL on or off at runtime without recreating tables.

changes:

  • SQL Syntax: ALTER TABLE <table> SET 'skip_wal'='true'/'false' and ALTER TABLE <table> UNSET 'skip_wal'
  • Region-level: When skip_wal is altered, the change is immediately applied to all regions in memory via handle_alter_region_options_fast(), setting wal_options to Noop (disabled) or RaftEngine (enabled).
  • Metadata persistence: The change is persisted in both TableInfo and DatanodeTableValue entries in metasrv, ensuring consistency across restarts.
  • SHOW CREATE TABLE: Updated to display the skip_wal option in the WITH clause.

Limitations

  • In distributed mode, when enabling WAL (skip_wal=false), the current implementation uses RaftEngine as default. The correct WAL options (e.g., Kafka topic) allocated by metasrv are persisted in DatanodeTableValue and will be loaded correctly on region restart, but the in-memory version may temporarily show RaftEngine even if the actual WAL is Kafka. This is documented with a TODO for future improvement.

PR Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

Signed-off-by: OmCheeLin <19563671928@163.com>
Signed-off-by: OmCheeLin <19563671928@163.com>
Signed-off-by: OmCheeLin <19563671928@163.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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' and ALTER 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.

Comment on lines +1 to +33
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;

Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

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:

  1. Write data with skip_wal=true
  2. Toggle to skip_wal=false
  3. Write more data
  4. Verify all data is retrievable after restart (data written with skip_wal=true should not be lost after toggle)

Copilot uses AI. Check for mistakes.
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 || {
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
// 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;
Copy link
Contributor

Choose a reason for hiding this comment

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

The WAL type could be Kafak

Copy link
Member

@WenyXu WenyXu left a comment

Choose a reason for hiding this comment

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

@OmCheeLin There are three things that need to be done:

  1. Handle metadata changes, which you’ve almost done in this PR.
  2. 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.
  3. 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.

);
}
}
SetRegionOption::SkipWal(skip_wal) => {
Copy link
Member

Choose a reason for hiding this comment

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

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.


current_options.sst_format = Some(new_format);
}
SetRegionOption::SkipWal(skip_wal) => {
Copy link
Member

Choose a reason for hiding this comment

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

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.

@OmCheeLin OmCheeLin closed this Jan 13, 2026
@OmCheeLin OmCheeLin reopened this Jan 13, 2026
@OmCheeLin
Copy link
Author

Sorry, I accidentally closed the PR.

@OmCheeLin
Copy link
Author

@WenyXu Should I wait until #7549 to be merged?

@WenyXu
Copy link
Member

WenyXu commented Jan 19, 2026

@WenyXu Should I wait until #7549 to be merged?

No, go ahead whenever you’re ready.

@github-actions github-actions bot added size/M and removed size/S labels Jan 20, 2026
Signed-off-by: OmCheeLin <19563671928@163.com>
Signed-off-by: OmCheeLin <19563671928@163.com>
@OmCheeLin
Copy link
Author

OmCheeLin commented Jan 20, 2026

I have encountered some issues that need further confirmation at present. Should we modify the proto?

@WenyXu
Copy link
Member

WenyXu commented Jan 22, 2026

I have encountered some issues that need further confirmation at present. Should we modify the proto?

Could you explain the details of the issue?

@MichaelScofield MichaelScofield marked this pull request as draft January 28, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants