Skip to content

Commit f7a0842

Browse files
authored
[fix](binlog) Fix missing DELETE events in row binlog (#68034)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: Predicate deletes only persist delete predicates and therefore cannot produce row-level DELETE events. A merge-on-write unique table with light delete enabled incorrectly used that path even when ROW binlog was enabled, leaving downstream consumers with stale rows. Route these deletes through row-bearing DELETE FROM USING execution, and reject any ROW-binlog predicate delete that still reaches the legacy handler. ### Release note Ensure DELETE on merge-on-write unique tables with ROW binlog emits row-level DELETE events even when light delete is enabled. Predicate DELETE on ROW-binlog tables now reports an explicit unsupported error. ### Check List (For Author) - Test: Regression test, FE unit test, and manual test - Regression test: row_binlog_p0/test_row_binlog_mow_light_delete - Unit Test: org.apache.doris.nereids.trees.plans.commands.DeleteFromCommandTest - Manual test: verified ROW binlog DELETE events with historical values disabled and enabled - Behavior changed: Yes; MOW ROW-binlog deletes use row-bearing execution, while unsupported predicate deletes fail explicitly - Does this need documentation: No
1 parent 85ad28a commit f7a0842

4 files changed

Lines changed: 126 additions & 6 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.doris.analysis.Predicate;
2121
import org.apache.doris.catalog.Database;
2222
import org.apache.doris.catalog.Env;
23-
import org.apache.doris.catalog.KeysType;
2423
import org.apache.doris.catalog.OlapTable;
2524
import org.apache.doris.catalog.Partition;
2625
import org.apache.doris.common.AnalysisException;
@@ -112,10 +111,10 @@ public void process(Database targetDb, OlapTable targetTbl, List<Partition> sele
112111
try {
113112
targetTbl.readLock();
114113
try {
115-
if (targetTbl.needRowBinlog() && targetTbl.getKeysType() == KeysType.DUP_KEYS) {
114+
if (targetTbl.needRowBinlog()) {
116115
throw new AnalysisException(
117-
"DELETE with predicates is not supported on DUPLICATE KEY tables when binlog<row>"
118-
+ "is enabled. Please disable binlog<row> for this table or avoid DELETE.");
116+
"DELETE with predicates is not supported when binlog<row> is enabled because it cannot "
117+
+ "produce row-level DELETE events.");
119118
}
120119
if (targetTbl.getState() != OlapTable.OlapTableState.NORMAL) {
121120
// table under alter operation can also do delete.

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
210210
}
211211
}
212212

213-
// if table's enable_mow_light_delete is false, use `DeleteFromUsingCommand`
213+
// Row binlog needs row-bearing deletes to emit DELETE events. Predicate deletes only write
214+
// delete predicates, so use `DeleteFromUsingCommand` even when MOW light delete is enabled.
214215
if (olapTable.getKeysType() == KeysType.UNIQUE_KEYS && olapTable.getEnableUniqueKeyMergeOnWrite()
215-
&& !olapTable.getEnableMowLightDelete()) {
216+
&& (!olapTable.getEnableMowLightDelete() || olapTable.needRowBinlog())) {
216217
new DeleteFromUsingCommand(nameParts, tableAlias, isTempPart, partitions, logicalQuery,
217218
Optional.empty(), false).run(ctx, executor);
218219
return;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !without_history_base --
3+
2 two
4+
5+
-- !without_history_binlog --
6+
0 1 one
7+
0 2 two
8+
2 1 \N
9+
10+
-- !with_history_base --
11+
2 two
12+
13+
-- !with_history_binlog --
14+
0 1 one \N
15+
0 2 two \N
16+
2 1 one one
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_row_binlog_mow_light_delete", "nonConcurrent") {
19+
sql "DROP TABLE IF EXISTS test_row_binlog_mow_light_delete_without_history FORCE"
20+
sql "DROP TABLE IF EXISTS test_row_binlog_mow_light_delete_with_history FORCE"
21+
sql "DROP TABLE IF EXISTS test_row_binlog_dup_delete FORCE"
22+
23+
sql """
24+
CREATE TABLE test_row_binlog_mow_light_delete_without_history (
25+
k INT,
26+
v STRING
27+
)
28+
UNIQUE KEY(k)
29+
DISTRIBUTED BY HASH(k) BUCKETS 1
30+
PROPERTIES (
31+
"replication_num" = "1",
32+
"enable_unique_key_merge_on_write" = "true",
33+
"enable_mow_light_delete" = "true",
34+
"binlog.enable" = "true",
35+
"binlog.format" = "ROW",
36+
"binlog.need_historical_value" = "false"
37+
)
38+
"""
39+
40+
sql "INSERT INTO test_row_binlog_mow_light_delete_without_history VALUES (1, 'one'), (2, 'two')"
41+
sql "DELETE FROM test_row_binlog_mow_light_delete_without_history WHERE k = 1"
42+
43+
order_qt_without_history_base """
44+
SELECT k, v
45+
FROM test_row_binlog_mow_light_delete_without_history
46+
"""
47+
48+
qt_without_history_binlog """
49+
SELECT __DORIS_BINLOG_OP__ AS op, k, v
50+
FROM binlog("table" = "test_row_binlog_mow_light_delete_without_history")
51+
ORDER BY __DORIS_BINLOG_TSO__, __DORIS_BINLOG_LSN__
52+
"""
53+
54+
sql """
55+
CREATE TABLE test_row_binlog_mow_light_delete_with_history (
56+
k INT,
57+
v STRING
58+
)
59+
UNIQUE KEY(k)
60+
DISTRIBUTED BY HASH(k) BUCKETS 1
61+
PROPERTIES (
62+
"replication_num" = "1",
63+
"enable_unique_key_merge_on_write" = "true",
64+
"enable_mow_light_delete" = "true",
65+
"binlog.enable" = "true",
66+
"binlog.format" = "ROW",
67+
"binlog.need_historical_value" = "true"
68+
)
69+
"""
70+
71+
sql "INSERT INTO test_row_binlog_mow_light_delete_with_history VALUES (1, 'one'), (2, 'two')"
72+
sql "DELETE FROM test_row_binlog_mow_light_delete_with_history WHERE k = 1"
73+
74+
order_qt_with_history_base """
75+
SELECT k, v
76+
FROM test_row_binlog_mow_light_delete_with_history
77+
"""
78+
79+
qt_with_history_binlog """
80+
SELECT __DORIS_BINLOG_OP__ AS op, k, v, __BEFORE__v__
81+
FROM binlog("table" = "test_row_binlog_mow_light_delete_with_history")
82+
ORDER BY __DORIS_BINLOG_TSO__, __DORIS_BINLOG_LSN__
83+
"""
84+
85+
sql """
86+
CREATE TABLE test_row_binlog_dup_delete (
87+
k INT,
88+
v STRING
89+
)
90+
DUPLICATE KEY(k)
91+
DISTRIBUTED BY HASH(k) BUCKETS 1
92+
PROPERTIES (
93+
"replication_num" = "1",
94+
"binlog.enable" = "true",
95+
"binlog.format" = "ROW"
96+
)
97+
"""
98+
99+
sql "INSERT INTO test_row_binlog_dup_delete VALUES (1, 'one')"
100+
test {
101+
sql "DELETE FROM test_row_binlog_dup_delete WHERE k = 1"
102+
exception "DELETE with predicates is not supported when binlog<row> is enabled"
103+
}
104+
}

0 commit comments

Comments
 (0)