Skip to content

Commit 79acc99

Browse files
authored
fix: Delete statement not supported in metric engine close #4649 (#5473)
* fix: Delete statement not supported in metric engine close #4649 Signed-off-by: yihong0618 <[email protected]> * fix: do not include Truncate address review comments Signed-off-by: yihong0618 <[email protected]> * fix: address comments Signed-off-by: yihong0618 <[email protected]> * fix: address comment again Signed-off-by: yihong0618 <[email protected]> --------- Signed-off-by: yihong0618 <[email protected]>
1 parent 0a16998 commit 79acc99

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

src/metric-engine/src/engine.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,18 @@ impl RegionEngine for MetricEngine {
163163
}
164164
}
165165
RegionRequest::Flush(req) => self.inner.flush_region(region_id, req).await,
166-
RegionRequest::Delete(_) | RegionRequest::Truncate(_) => {
167-
UnsupportedRegionRequestSnafu { request }.fail()
166+
RegionRequest::Truncate(_) => UnsupportedRegionRequestSnafu { request }.fail(),
167+
RegionRequest::Delete(_) => {
168+
if self.inner.is_physical_region(region_id) {
169+
self.inner
170+
.mito
171+
.handle_request(region_id, request)
172+
.await
173+
.context(error::MitoDeleteOperationSnafu)
174+
.map(|response| response.affected_rows)
175+
} else {
176+
UnsupportedRegionRequestSnafu { request }.fail()
177+
}
168178
}
169179
RegionRequest::Catchup(req) => self.inner.catchup_region(region_id, req).await,
170180
};

src/metric-engine/src/error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ pub enum Error {
125125
#[snafu(implicit)]
126126
location: Location,
127127
},
128+
#[snafu(display("Mito delete operation fails"))]
129+
MitoDeleteOperation {
130+
source: BoxedError,
131+
#[snafu(implicit)]
132+
location: Location,
133+
},
128134

129135
#[snafu(display("Mito catchup operation fails"))]
130136
MitoCatchupOperation {
@@ -288,7 +294,8 @@ impl ErrorExt for Error {
288294
| MitoReadOperation { source, .. }
289295
| MitoWriteOperation { source, .. }
290296
| MitoCatchupOperation { source, .. }
291-
| MitoFlushOperation { source, .. } => source.status_code(),
297+
| MitoFlushOperation { source, .. }
298+
| MitoDeleteOperation { source, .. } => source.status_code(),
292299

293300
EncodePrimaryKey { source, .. } => source.status_code(),
294301

tests/cases/standalone/common/basic.result

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ SELECT * from t1;
107107
| host1 | 1970-01-01T00:00:00 | 0.0 |
108108
+-------+-------------------------+-----+
109109

110+
-- issue #4649 should fail (do not support delete from logical table for now)
111+
delete from t1;
112+
113+
Error: 1001(Unsupported), Unsupported region request: Delete
114+
115+
-- issue #4649 should succeed
116+
delete from phy;
117+
118+
Affected Rows: 2
119+
110120
CREATE TABLE t2 (ts timestamp time index, job string primary key, val double) engine = metric with ("on_physical_table" = "phy");
111121

112122
Affected Rows: 0
@@ -143,12 +153,8 @@ select * from foo;
143153

144154
SELECT * from t1;
145155

146-
+-------+-------------------------+-----+
147-
| host | ts | val |
148-
+-------+-------------------------+-----+
149-
| host2 | 1970-01-01T00:00:00.001 | 1.0 |
150-
| host1 | 1970-01-01T00:00:00 | 0.0 |
151-
+-------+-------------------------+-----+
156+
++
157+
++
152158

153159
SELECT * from t2;
154160

tests/cases/standalone/common/basic.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ INSERT INTO t1 VALUES ('host1',0, 0), ('host2', 1, 1,);
4747

4848
SELECT * from t1;
4949

50+
-- issue #4649 should fail (do not support delete from logical table for now)
51+
delete from t1;
52+
53+
-- issue #4649 should succeed
54+
delete from phy;
55+
5056
CREATE TABLE t2 (ts timestamp time index, job string primary key, val double) engine = metric with ("on_physical_table" = "phy");
5157

5258
SELECT * from t2;

0 commit comments

Comments
 (0)