This is an automated email from the ASF dual-hosted git repository.
Yukang-Lian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 01616972649 [fix](delete) Use the FE schema version for the delete
rowset in local mode (#70286)
01616972649 is described below
commit 01616972649556b08ef131b64de65d4857ab2af5
Author: Jamie <[email protected]>
AuthorDate: Thu Nov 26 11:33:52 2026 +0800
[fix](delete) Use the FE schema version for the delete rowset in local mode
(#70286)
### Background
In local (non-cloud) mode, a DELETE is pushed to every replica as a
`TPushReq` and handled by `PushHandler::_do_streaming_ingestion`, which
writes an empty rowset carrying the delete predicate. The rowset's
schema is a copy of the tablet's max-version schema with its columns
rebuilt from `request.columns_desc` (the FE's current schema). When a
compaction merges rowsets, it uses the schema with the highest
`schema_version` among its inputs. Then
`TabletSchema::merge_dropped_columns` adds each delete rowset's columns
that are missing from that schema as dropped columns, and `CHECK`s that
none of them is a key column.
### What problem does this PR solve?
Issue Number: None
Related PR: #36083 (made the cloud delete task use
`request.schema_version`; the local path was not changed)
PR Type: Bugfix
Problem Summary:
The local push handler takes the delete rowset's columns from the FE but
keeps the tablet's schema version, which can be stale. After a key
column is appended to a DUPLICATE KEY table with a VARIANT column, a
DELETE on that column followed by a full compaction aborts every replica
with `Check failed: !src_col->is_key() <col> is key column, should not
be dropped.` This PR sets the delete rowset's schema version from
`request.schema_version`, as the cloud delete task already does, and
adds a regression case. Cloud mode is not affected.
### Details
- **Frequency:** Deterministic once the sequence below happens; found by
a randomized compaction/schema-change stress test.
- **Root cause:**
1. `ALTER TABLE ... ADD COLUMN <k> <type> KEY` appends a key column
after the existing keys. If the short key count does not change and the
base tablet has no delete predicates, the BE uses a linked schema change
(`sc_sorting: 0, sc_directly: 0`).
2. When the tablet schema has a VARIANT column,
`BaseBetaRowsetWriter::add_rowset` replaces the rowset schema with the
linked (old) rowset's schema to keep the variant subcolumns. All rowsets
of the new tablet therefore keep the old schema version and lack `<k>`.
3. The new tablet is created with schema version 0, and nothing raises
its max-version schema until a load arrives.
4. A DELETE that references `<k>` (e.g. `... AND <k> IS NULL`) is pushed
before any load. Its rowset has `<k>` in its columns (from
`columns_desc`) but the tablet's stale schema version, which is not
higher than the linked rowsets' version.
5. Full compaction picks a linked rowset's schema (without `<k>`) as the
target, `merge_dropped_columns` sees `<k>` from the delete rowset as a
dropped key column, and the `CHECK` aborts the BE. Every replica runs
the same compaction and crashes.
- **Why existing tests missed it:** It needs a VARIANT column, a linked
add-key schema change, and a delete on the new key before any other
load. No existing case combines them.
- **Fix:** When the columns are rebuilt from `columns_desc`, also set
the schema version from `request.schema_version` (only when it is set).
The delete rowset then has the FE's version and becomes the compaction
target; older rowsets are read with the missing key column filled by its
default value, as after any light schema change. The tablet's
max-version schema is intentionally left untouched (same as the cloud
path): updating it from this rebuilt schema would drop the variant's
extracted subcolumns.
- **Other paths and branches:** The cloud delete task already sets the
version. The linked schema change keeping the old rowset schema for
VARIANT tables is left as is; with this fix it no longer leads to a
crash.
### Testing
- New regression case
`schema_change_p0/test_delete_after_linked_add_key_variant`: DUPLICATE
KEY table with a VARIANT column, two loads, `ADD COLUMN k4 DATE KEY`
(linked schema change), `DELETE ... WHERE k1 = 1 AND k4 IS NULL`, full
compaction, then queries before/after compaction and after another load.
Without the fix the full compaction aborts the BE.
- The root cause was confirmed from BE logs of a failed stress run: the
tablet's schema change was linked, four delete pushes landed before any
load, and full compaction over all versions aborted with the `CHECK`
above.
- The new case has not been run locally yet; it runs in CI.
### Release note
Fix a BE crash in compaction when a DELETE references a key column that
was just added to a table with a VARIANT column (local mode).
---
be/src/load/delta_writer/push_handler.cpp | 7 +++
.../test_delete_after_linked_add_key_variant.out | 14 +++++
...test_delete_after_linked_add_key_variant.groovy | 68 ++++++++++++++++++++++
3 files changed, 89 insertions(+)
diff --git a/be/src/load/delta_writer/push_handler.cpp
b/be/src/load/delta_writer/push_handler.cpp
index 3b7dc63d5df..db58120845a 100644
--- a/be/src/load/delta_writer/push_handler.cpp
+++ b/be/src/load/delta_writer/push_handler.cpp
@@ -210,6 +210,13 @@ Status
PushHandler::_do_streaming_ingestion(TabletSharedPtr tablet, const TPushR
for (const auto& column_desc : request.columns_desc) {
tablet_schema->append_column(TabletColumn(column_desc));
}
+ // The columns above come from the FE's current schema, so the schema
version must
+ // match them too. Otherwise the pushed rowset keeps the tablet's
stale version and a
+ // later compaction may pick an older rowset schema that misses its
columns (e.g. a
+ // key column added by a linked schema change), which aborts
merge_dropped_columns.
+ if (request.__isset.schema_version) {
+ tablet_schema->set_schema_version(request.schema_version);
+ }
}
RowsetSharedPtr rowset_to_add;
// writes
diff --git
a/regression-test/data/schema_change_p0/test_delete_after_linked_add_key_variant.out
b/regression-test/data/schema_change_p0/test_delete_after_linked_add_key_variant.out
new file mode 100644
index 00000000000..2950be1ec46
--- /dev/null
+++
b/regression-test/data/schema_change_p0/test_delete_after_linked_add_key_variant.out
@@ -0,0 +1,14 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !before_compaction --
+2 2 2 \N 2
+3 3 3 \N 3
+
+-- !after_compaction --
+2 2 2 \N 2
+3 3 3 \N 3
+
+-- !after_insert --
+2 2 2 \N 2
+3 3 3 \N 3
+4 4 4 2026-01-01 4
+
diff --git
a/regression-test/suites/schema_change_p0/test_delete_after_linked_add_key_variant.groovy
b/regression-test/suites/schema_change_p0/test_delete_after_linked_add_key_variant.groovy
new file mode 100644
index 00000000000..e92b6fc2174
--- /dev/null
+++
b/regression-test/suites/schema_change_p0/test_delete_after_linked_add_key_variant.groovy
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// A DUPLICATE KEY table with a VARIANT column gets a new key column appended
after the
+// existing keys. The BE handles it as a linked schema change, so the new
tablet's
+// rowsets keep the old rowset schema (without the new key column). A DELETE
that
+// references the new key column is then pushed before any other load. The
delete rowset
+// must carry the FE schema version; otherwise full compaction picks the old
rowset schema,
+// treats the new key column as dropped and aborts the BE.
+suite("test_delete_after_linked_add_key_variant", "p0") {
+ def tableName = "test_delete_after_linked_add_key_variant"
+
+ sql """ DROP TABLE IF EXISTS ${tableName} """
+ sql """
+ CREATE TABLE ${tableName} (
+ k1 INT NOT NULL,
+ k2 INT NOT NULL,
+ k3 INT NOT NULL,
+ v1 VARIANT NOT NULL,
+ v2 INT NULL
+ )
+ DUPLICATE KEY(k1, k2, k3)
+ DISTRIBUTED BY HASH(k1) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1",
+ "disable_auto_compaction" = "true"
+ )
+ """
+
+ sql """ INSERT INTO ${tableName} VALUES (1, 1, 1, '{"a": 1}', 1), (2, 2,
2, '{"a": 2, "b": "x"}', 2) """
+ sql """ INSERT INTO ${tableName} VALUES (3, 3, 3, '{"c": [1, 2]}', 3) """
+
+ // Appended key column, short key count unchanged and no delete predicate
yet:
+ // the BE takes the linked schema change path.
+ sql """ ALTER TABLE ${tableName} ADD COLUMN k4 DATE KEY """
+ waitForSchemaChangeDone {
+ sql """ SHOW ALTER TABLE COLUMN WHERE TableName='${tableName}' ORDER
BY createtime DESC LIMIT 1 """
+ time 600
+ }
+
+ // No load between the schema change and the delete, so the tablet's max
version schema
+ // is still the one the new tablet was created with.
+ sql """ DELETE FROM ${tableName} WHERE k1 = 1 AND k4 IS NULL """
+ order_qt_before_compaction """ SELECT k1, k2, k3, k4, v2 FROM ${tableName}
"""
+
+ trigger_and_wait_compaction(tableName, "full")
+
+ order_qt_after_compaction """ SELECT k1, k2, k3, k4, v2 FROM ${tableName}
"""
+
+ sql """ INSERT INTO ${tableName} VALUES (4, 4, 4, '2026-01-01', '{"a":
4}', 4) """
+ order_qt_after_insert """ SELECT k1, k2, k3, k4, v2 FROM ${tableName} """
+
+ sql """ DROP TABLE IF EXISTS ${tableName} """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]