mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-08-22 05:58:33 +00:00
78084a9d44
* feat: add admin function to discard unflushed data Signed-off-by: evenyag <realevenyag@gmail.com> * test: cover discarding unflushed data by table Signed-off-by: evenyag <realevenyag@gmail.com> * chore: fix license header Signed-off-by: evenyag <realevenyag@gmail.com> * fix: reject discarding logical metric table data Signed-off-by: evenyag <realevenyag@gmail.com> * refactor: defer table name formatting in error paths Signed-off-by: evenyag <realevenyag@gmail.com> * chore(deps): update greptime-proto revision Signed-off-by: evenyag <realevenyag@gmail.com> * refactor: rename discard unflushed admin function Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com>
134 lines
3.7 KiB
Plaintext
134 lines
3.7 KiB
Plaintext
CREATE TABLE discard_unflushed_data_test (
|
|
host STRING PRIMARY KEY,
|
|
val DOUBLE,
|
|
ts TIMESTAMP TIME INDEX
|
|
) ENGINE = mito;
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO discard_unflushed_data_test VALUES ('persisted', 1, 1);
|
|
|
|
Affected Rows: 1
|
|
|
|
ADMIN FLUSH_TABLE('discard_unflushed_data_test');
|
|
|
|
+--------------------------------------------------+
|
|
| ADMIN FLUSH_TABLE('discard_unflushed_data_test') |
|
|
+--------------------------------------------------+
|
|
| 0 |
|
|
+--------------------------------------------------+
|
|
|
|
INSERT INTO discard_unflushed_data_test VALUES ('unflushed', 2, 2);
|
|
|
|
Affected Rows: 1
|
|
|
|
ADMIN discard_unflushed('discard_unflushed_data_test');
|
|
|
|
+--------------------------------------------------------+
|
|
| ADMIN discard_unflushed('discard_unflushed_data_test') |
|
|
+--------------------------------------------------------+
|
|
| 0 |
|
|
+--------------------------------------------------------+
|
|
|
|
-- Repeating the operation is idempotent.
|
|
ADMIN discard_unflushed('discard_unflushed_data_test');
|
|
|
|
+--------------------------------------------------------+
|
|
| ADMIN discard_unflushed('discard_unflushed_data_test') |
|
|
+--------------------------------------------------------+
|
|
| 0 |
|
|
+--------------------------------------------------------+
|
|
|
|
SELECT host, val FROM discard_unflushed_data_test ORDER BY host;
|
|
|
|
+-----------+-----+
|
|
| host | val |
|
|
+-----------+-----+
|
|
| persisted | 1.0 |
|
|
+-----------+-----+
|
|
|
|
-- The function must only be available through ADMIN.
|
|
-- SQLNESS REPLACE \nDid\syou\smean.*
|
|
SELECT discard_unflushed(0);
|
|
|
|
Error: 3000(PlanQuery), Failed to plan SQL: Error during planning: Invalid function 'discard_unflushed'.
|
|
|
|
DROP TABLE discard_unflushed_data_test;
|
|
|
|
Affected Rows: 0
|
|
|
|
CREATE TABLE discard_unflushed_data_test (
|
|
host STRING PRIMARY KEY,
|
|
val DOUBLE,
|
|
ts TIMESTAMP TIME INDEX
|
|
) ENGINE = mito;
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO discard_unflushed_data_test VALUES ('unflushed', 1, 1);
|
|
|
|
Affected Rows: 1
|
|
|
|
-- The table has no persisted data, so discarding leaves it empty.
|
|
ADMIN discard_unflushed('discard_unflushed_data_test');
|
|
|
|
+--------------------------------------------------------+
|
|
| ADMIN discard_unflushed('discard_unflushed_data_test') |
|
|
+--------------------------------------------------------+
|
|
| 0 |
|
|
+--------------------------------------------------------+
|
|
|
|
SELECT COUNT(*) FROM discard_unflushed_data_test;
|
|
|
|
+----------+
|
|
| count(*) |
|
|
+----------+
|
|
| 0 |
|
|
+----------+
|
|
|
|
DROP TABLE discard_unflushed_data_test;
|
|
|
|
Affected Rows: 0
|
|
|
|
CREATE TABLE discard_unflushed_data_physical (
|
|
ts TIMESTAMP TIME INDEX,
|
|
val DOUBLE
|
|
) ENGINE = metric WITH ("physical_metric_table" = "");
|
|
|
|
Affected Rows: 0
|
|
|
|
CREATE TABLE discard_unflushed_data_logical (
|
|
host STRING PRIMARY KEY,
|
|
val DOUBLE,
|
|
ts TIMESTAMP TIME INDEX
|
|
) ENGINE = metric WITH ("on_physical_table" = "discard_unflushed_data_physical");
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO discard_unflushed_data_logical VALUES ('unflushed', 1, 1);
|
|
|
|
Affected Rows: 1
|
|
|
|
-- Logical Metric Engine tables share their physical regions with other logical tables.
|
|
-- Discarding by logical table name must not truncate those shared regions.
|
|
ADMIN discard_unflushed('discard_unflushed_data_logical');
|
|
|
|
Error: 1002(Unexpected), Failed to execute admin function discard_unflushed: Execution error: Not supported: discarding unflushed data from a Metric Engine logical table
|
|
|
|
SELECT host, val FROM discard_unflushed_data_logical;
|
|
|
|
+-----------+-----+
|
|
| host | val |
|
|
+-----------+-----+
|
|
| unflushed | 1.0 |
|
|
+-----------+-----+
|
|
|
|
DROP TABLE discard_unflushed_data_logical;
|
|
|
|
Affected Rows: 0
|
|
|
|
DROP TABLE discard_unflushed_data_physical;
|
|
|
|
Affected Rows: 0
|
|
|