Skip to content

Commit 2d8137b

Browse files
authored
codec: fix a panic in Debezium when configuring column-selector (#12210) (#12213)
close #12208
1 parent a956eab commit 2d8137b

File tree

15 files changed

+28
-52
lines changed

15 files changed

+28
-52
lines changed

pkg/sink/codec/debezium/codec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func (c *dbzCodec) writeDebeziumFieldValues(
4949
colInfos := tableInfo.GetColInfosForRowChangedEvent()
5050
writer.WriteObjectField(fieldName, func() {
5151
for i, col := range cols {
52+
if col == nil {
53+
continue
54+
}
5255
colx := model.GetColumnDataX(col, tableInfo)
5356
err = c.writeDebeziumFieldValue(writer, colx, colInfos[i].Ft)
5457
if err != nil {
@@ -1088,6 +1091,9 @@ func (c *dbzCodec) EncodeValue(
10881091
}
10891092
colInfos := e.TableInfo.GetColInfosForRowChangedEvent()
10901093
for i, col := range validCols {
1094+
if col == nil {
1095+
continue
1096+
}
10911097
colx := model.GetColumnDataX(col, e.TableInfo)
10921098
c.writeDebeziumFieldSchema(fieldsWriter, colx, colInfos[i].Ft)
10931099
}

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

tests/integration_tests/kafka_simple_basic/data/data.sql

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

409409
DROP TABLE2;
410-
411-
create table finish_mark
412-
(
413-
id int PRIMARY KEY
414-
);

0 commit comments

Comments
 (0)