feat: Support altering table TTL (#4848)

* feat/alter-ttl:
 Update greptime-proto source and add ChangeTableOptions handling

 - Change greptime-proto source repository and revision in Cargo.lock and Cargo.toml
 - Implement handling for ChangeTableOptions in grpc-expr and meta modules
 - Add support for parsing and applying region option changes in mito2
 - Introduce new error type for invalid change table option requests
 - Add humantime dependency to store-api
 - Fix SQL syntax in tests for changing column types

* chore: remove write buffer size option handling since we don't support specifying write_buffer_size for single table or region

* persist ttl to manifest

* chore: add sqlness

* fix: sqlness

* fix: typo and toml format

* fix: tests

* update: change alter syntax

* feat/alter-ttl: Add Clone trait to RegionFlushRequest and remove redundant Default derive in region_request.rs.

* feat/alter-ttl: Refactor code to replace 'ChangeTableOption' with 'ChangeRegionOption' and handle TTL as a region option

 • Rename ChangeTableOption to ChangeRegionOption across various files.
 • Update AlterKind::ChangeTableOptions to AlterKind::ChangeRegionOptions.
 • Modify TTL handling to treat '0d' as None for TTL in table options.
 • Adjust related function names and comments to reflect the change from table to region options.
 • Include test case updates to verify the new TTL handling behavior.

* chore: update format

* refactor: update region options in DatanodeTableValue

* feat/alter-ttl:
 Remove TTL handling from RegionManifest and related structures

 - Eliminate TTL fields from `RegionManifest`, `RegionChange`, and associated handling logic.
 - Update tests and checksums to reflect removal of TTL.
 - Refactor `RegionOpener` and `handle_alter` to adjust to TTL removal.
 - Simplify `RegionChangeResult` by replacing `change` with `new_meta`.

* chore: fmt

* remove useless delete op

* feat/alter-ttl: Updated Cargo.lock and gRPC expression Cargo.toml to include store-api dependency. Refactored alter.rs to use ChangeOption from store-api instead of ChangeTableOptionRequest.
Adjusted error handling in error.rs to use MetadataError. Modified handle_alter.rs to handle TTL changes with ChangeOption. Simplified region_request.rs by replacing
ChangeRegionOption with ChangeOption and removing redundant code. Removed UnsupportedTableOptionChange error in table/src/error.rs. Updated metadata.rs to use ChangeOption for table
options. Removed ChangeTableOptionRequest enum and related conversion code from requests.rs.

* feat/alter-ttl: Update greptime-proto dependency to revision 53ab9a9553

* chore: format code

* chore: update greptime-proto
This commit is contained in:
Lei, HUANG
2024-10-29 21:39:48 -07:00
committed by GitHub
parent 83eb777d21
commit d275cdd570
34 changed files with 648 additions and 66 deletions

View File

@@ -0,0 +1,88 @@
CREATE TABLE ato(i INTEGER, j TIMESTAMP TIME INDEX);
Affected Rows: 0
ALTER TABLE ato SET 'ttl'='1d';
Affected Rows: 0
SHOW CREATE TABLE ato;
+-------+------------------------------------+
| Table | Create Table |
+-------+------------------------------------+
| ato | CREATE TABLE IF NOT EXISTS "ato" ( |
| | "i" INT NULL, |
| | "j" TIMESTAMP(3) NOT NULL, |
| | TIME INDEX ("j") |
| | ) |
| | |
| | ENGINE=mito |
| | WITH( |
| | ttl = '1day' |
| | ) |
+-------+------------------------------------+
ALTER TABLE ato SET 'ttl'='2d';
Affected Rows: 0
SHOW CREATE TABLE ato;
+-------+------------------------------------+
| Table | Create Table |
+-------+------------------------------------+
| ato | CREATE TABLE IF NOT EXISTS "ato" ( |
| | "i" INT NULL, |
| | "j" TIMESTAMP(3) NOT NULL, |
| | TIME INDEX ("j") |
| | ) |
| | |
| | ENGINE=mito |
| | WITH( |
| | ttl = '2days' |
| | ) |
+-------+------------------------------------+
ALTER TABLE ato SET 'ttl'=NULL;
Affected Rows: 0
SHOW CREATE TABLE ato;
+-------+------------------------------------+
| Table | Create Table |
+-------+------------------------------------+
| ato | CREATE TABLE IF NOT EXISTS "ato" ( |
| | "i" INT NULL, |
| | "j" TIMESTAMP(3) NOT NULL, |
| | TIME INDEX ("j") |
| | ) |
| | |
| | ENGINE=mito |
| | |
+-------+------------------------------------+
ALTER TABLE ato SET 'ttl'='0d';
Affected Rows: 0
SHOW CREATE TABLE ato;
+-------+------------------------------------+
| Table | Create Table |
+-------+------------------------------------+
| ato | CREATE TABLE IF NOT EXISTS "ato" ( |
| | "i" INT NULL, |
| | "j" TIMESTAMP(3) NOT NULL, |
| | TIME INDEX ("j") |
| | ) |
| | |
| | ENGINE=mito |
| | |
+-------+------------------------------------+
DROP TABLE ato;
Affected Rows: 0

View File

@@ -0,0 +1,19 @@
CREATE TABLE ato(i INTEGER, j TIMESTAMP TIME INDEX);
ALTER TABLE ato SET 'ttl'='1d';
SHOW CREATE TABLE ato;
ALTER TABLE ato SET 'ttl'='2d';
SHOW CREATE TABLE ato;
ALTER TABLE ato SET 'ttl'=NULL;
SHOW CREATE TABLE ato;
ALTER TABLE ato SET 'ttl'='0d';
SHOW CREATE TABLE ato;
DROP TABLE ato;

View File

@@ -6,23 +6,23 @@ INSERT INTO test VALUES (1, 1, 1, false), (2, 2, 2, true);
Affected Rows: 2
ALTER TABLE test MODIFY "I" STRING;
ALTER TABLE test MODIFY COLUMN "I" STRING;
Error: 4002(TableColumnNotFound), Column I not exists in table test
ALTER TABLE test MODIFY k DATE;
ALTER TABLE test MODIFY COLUMN k DATE;
Error: 1004(InvalidArguments), Invalid alter table(test) request: column 'k' cannot be cast automatically to type 'Date'
ALTER TABLE test MODIFY id STRING;
ALTER TABLE test MODIFY COLUMN id STRING;
Error: 1004(InvalidArguments), Invalid alter table(test) request: Not allowed to change primary key index column 'id'
ALTER TABLE test MODIFY j STRING;
ALTER TABLE test MODIFY COLUMN j STRING;
Error: 1004(InvalidArguments), Invalid alter table(test) request: Not allowed to change timestamp index column 'j' datatype
ALTER TABLE test MODIFY I STRING;
ALTER TABLE test MODIFY COLUMN I STRING;
Affected Rows: 0
@@ -61,7 +61,7 @@ DESCRIBE test;
| k | Boolean | | YES | | FIELD |
+--------+----------------------+-----+------+---------+---------------+
ALTER TABLE test MODIFY I INTEGER;
ALTER TABLE test MODIFY COLUMN I INTEGER;
Affected Rows: 0

View File

@@ -2,15 +2,15 @@ CREATE TABLE test(id INTEGER PRIMARY KEY, i INTEGER NULL, j TIMESTAMP TIME INDEX
INSERT INTO test VALUES (1, 1, 1, false), (2, 2, 2, true);
ALTER TABLE test MODIFY "I" STRING;
ALTER TABLE test MODIFY COLUMN "I" STRING;
ALTER TABLE test MODIFY k DATE;
ALTER TABLE test MODIFY COLUMN k DATE;
ALTER TABLE test MODIFY id STRING;
ALTER TABLE test MODIFY COLUMN id STRING;
ALTER TABLE test MODIFY j STRING;
ALTER TABLE test MODIFY COLUMN j STRING;
ALTER TABLE test MODIFY I STRING;
ALTER TABLE test MODIFY COLUMN I STRING;
SELECT * FROM test;
@@ -21,7 +21,7 @@ SELECT * FROM test;
DESCRIBE test;
ALTER TABLE test MODIFY I INTEGER;
ALTER TABLE test MODIFY COLUMN I INTEGER;
-- SQLNESS SORT_RESULT 3 1
SELECT * FROM test;

View File

@@ -15,7 +15,7 @@ SELECT * FROM test;
| 1970-01-01T00:00:00.002 | 2 |
+-------------------------+---+
ALTER TABLE test MODIFY j STRING;
ALTER TABLE test MODIFY COLUMN j STRING;
Error: 1004(InvalidArguments), Invalid alter table(test) request: column 'j' must be nullable to ensure safe conversion.

View File

@@ -4,7 +4,7 @@ INSERT INTO test VALUES (1, 1), (2, 2);
SELECT * FROM test;
ALTER TABLE test MODIFY j STRING;
ALTER TABLE test MODIFY COLUMN j STRING;
SELECT * FROM test;