Skip to content

Commit 9bc740d

Browse files
authored
codec: fix a panic in Debezium when configuring column-selector (#12210)
close #12208
1 parent 9ffd20b commit 9bc740d

File tree

20 files changed

+56
-69
lines changed

20 files changed

+56
-69
lines changed

pkg/sink/codec/debezium/codec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func (c *dbzCodec) writeDebeziumFieldValues(
5050
colInfos := tableInfo.GetColInfosForRowChangedEvent()
5151
writer.WriteObjectField(fieldName, func() {
5252
for i, col := range cols {
53+
if col == nil {
54+
continue
55+
}
5356
colx := model.GetColumnDataX(col, tableInfo)
5457
err = c.writeDebeziumFieldValue(writer, colx, colInfos[i].Ft)
5558
if err != nil {
@@ -1038,6 +1041,9 @@ func (c *dbzCodec) EncodeValue(
10381041
validCols = e.Columns
10391042
}
10401043
for _, col := range validCols {
1044+
if col == nil {
1045+
continue
1046+
}
10411047
colx := model.GetColumnDataX(col, e.TableInfo)
10421048
ft := &e.TableInfo.GetColumnByID(colx.ColumnID).FieldType
10431049
c.writeDebeziumFieldSchema(fieldsWriter, colx, ft)

tests/integration_tests/_utils/check_table_not_exists

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ while [ $i -lt $check_time ]; do
1919
break
2020
fi
2121
((i++))
22-
echo "table $1 not exists for $i-th check, retry later"
22+
echo "table $1 exists for $i-th check, retry later"
2323
sleep 2
2424
done
2525

2626
if [ $i -ge $check_time ]; then
27-
echo "table $1 not exists at last check"
27+
echo "table $1 exists at last check"
2828
exit 1
2929
fi

tests/integration_tests/canal_json_adapter_compatibility/run.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ function run() {
3333
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
3434

3535
# sync_diff can't check non-exist table, so we check expected tables are created in downstream first
36-
check_table_exists test.binary_columns ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 600
36+
run_sql "CREATE TABLE test.finish_mark1 (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
37+
check_table_exists test.finish_mark1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
3738
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 600
3839

3940
run_sql_file $CUR/data/data_gbk.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
40-
check_table_exists test.binary_columns ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 600
41+
run_sql "CREATE TABLE test.finish_mark2 (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
42+
check_table_exists test.finish_mark2 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
4143
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml 600
4244

4345
cleanup_process $CDC_BINARY

tests/integration_tests/canal_json_basic/data/data.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,3 @@ CREATE TABLE 表1 (
323323
RENAME TABLE 表1 TO 表2;
324324

325325
DROP TABLE2;
326-
327-
create table finish_mark
328-
(
329-
id int PRIMARY KEY
330-
);

tests/integration_tests/canal_json_basic/data/data_gbk.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,3 @@ CREATE TABLE
9494
) ENGINE = InnoDB;
9595

9696
RENAME TABLE 表1 TO 表2;
97-
98-
create table finish_mark
99-
(
100-
id int PRIMARY KEY
101-
);

tests/integration_tests/canal_json_basic/run.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ function run() {
5050
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
5151

5252
# sync_diff can't check non-exist table, so we check expected tables are created in downstream first
53-
check_table_exists test.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
53+
run_sql "CREATE TABLE test.finish_mark1 (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
54+
check_table_exists test.finish_mark1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
5455
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
5556

5657
run_sql_file $CUR/data/data_gbk.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
57-
check_table_exists test.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
58+
run_sql "CREATE TABLE test.finish_mark2 (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
59+
check_table_exists test.finish_mark2 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
5860
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
5961

6062
cleanup_process $CDC_BINARY

tests/integration_tests/canal_json_content_compatible/data/data.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,3 @@ CREATE TABLE 表1 (
323323
RENAME TABLE 表1 TO 表2;
324324

325325
DROP TABLE2;
326-
327-
create table finish_mark
328-
(
329-
id int PRIMARY KEY
330-
);

tests/integration_tests/canal_json_content_compatible/data/data_gbk.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,3 @@ CREATE TABLE
9494
) ENGINE = InnoDB;
9595

9696
RENAME TABLE 表1 TO 表2;
97-
98-
create table finish_mark
99-
(
100-
id int PRIMARY KEY
101-
);

tests/integration_tests/canal_json_content_compatible/run.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ function run() {
5050
run_sql_file $CUR/data/data.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
5151

5252
# sync_diff can't check non-exist table, so we check expected tables are created in downstream first
53-
check_table_exists test.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
53+
run_sql "CREATE TABLE test.finish_mark1 (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
54+
check_table_exists test.finish_mark1 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
5455
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
5556

5657
run_sql_file $CUR/data/data_gbk.sql ${UP_TIDB_HOST} ${UP_TIDB_PORT}
57-
check_table_exists test.finish_mark ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
58+
run_sql "CREATE TABLE test.finish_mark2 (a int primary key);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
59+
check_table_exists test.finish_mark2 ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} 200
5860
check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
5961

6062
cleanup_process $CDC_BINARY
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[sink]
2+
column-selectors = [
3+
{matcher = ['test.t1'], columns = ['account_id']},
4+
]

0 commit comments

Comments
 (0)