Skip to content

Commit b6e5047

Browse files
hnwyllmmobdevfkuner
authored
Filter fork unlock dependent-task check to DDL_FORK_TABLE
Co-authored-by: obdev <obdev@oceanbase.com> Co-authored-by: fkuner <fkuner@users.noreply.github.com>
1 parent 05c9b4b commit b6e5047

3 files changed

Lines changed: 154 additions & 7 deletions

File tree

src/storage/ddl/ob_ddl_lock.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,9 @@ int ObDDLLock::check_has_dependent_task(
812812
ObISQLClient::ReadResult res;
813813
sqlclient::ObMySQLResult *result = NULL;
814814

815-
if (OB_FAIL(sql_string.assign_fmt("SELECT EXISTS(SELECT 1 FROM %s WHERE task_id != %ld AND (object_id = %lu OR target_object_id = %lu)) as has",
816-
share::OB_ALL_DDL_TASK_STATUS_TNAME, current_task_id, table_id, table_id))) {
815+
if (OB_FAIL(sql_string.assign_fmt("SELECT EXISTS(SELECT 1 FROM %s WHERE task_id != %ld AND ddl_type = %d "
816+
"AND (object_id = %lu OR target_object_id = %lu)) as has",
817+
OB_ALL_DDL_TASK_STATUS_TNAME, current_task_id, share::ObDDLType::DDL_FORK_TABLE, table_id, table_id))) {
817818
LOG_WARN("assign sql string failed", K(ret));
818819
} else {
819820
ObInnerSQLConnection *iconn = static_cast<ObInnerSQLConnection *>(trans.get_connection());

tools/deploy/mysql_test/test_suite/fork_table/r/mysql/fork_table_with_index.result

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ Outputs & filters:
119119
force partition granule
120120
3 - output([t2_fork.id], [t2_fork.name], [t2_fork.age], [t2_fork.email]), filter(nil), rowset=16
121121
access([t2_fork.id], [t2_fork.name], [t2_fork.age], [t2_fork.email]), partitions(p[0-1])
122-
is_index_back=true, is_global_index=false,
123-
range_key([t2_fork.name], [t2_fork.id]), range(Alice,MIN ; Alice,MAX),
122+
is_index_back=true, is_global_index=false,
123+
range_key([t2_fork.name], [t2_fork.id]), range(Alice,MIN ; Alice,MAX),
124124
range_cond([t2_fork.name = 'Alice'])
125125
explain select * from t2_fork where age = 30;
126126
Query Plan
@@ -141,8 +141,8 @@ Outputs & filters:
141141
force partition granule
142142
3 - output([t2_fork.id], [t2_fork.age], [t2_fork.name], [t2_fork.email]), filter(nil), rowset=16
143143
access([t2_fork.id], [t2_fork.age], [t2_fork.name], [t2_fork.email]), partitions(p[0-1])
144-
is_index_back=true, is_global_index=false,
145-
range_key([t2_fork.age], [t2_fork.id]), range(30,MIN ; 30,MAX),
144+
is_index_back=true, is_global_index=false,
145+
range_key([t2_fork.age], [t2_fork.id]), range(30,MIN ; 30,MAX),
146146
range_cond([t2_fork.age = 30])
147147
============================================
148148
2.1 Fork Table with Index Building
@@ -249,6 +249,63 @@ t2c_fork CREATE TABLE `t2c_fork` (
249249
VECTOR KEY `idx_vec_emb` (`emb`) WITH (DISTANCE=L2, TYPE=HNSW, LIB=VSAG, M=16, EF_CONSTRUCTION=200, EF_SEARCH=64) BLOCK_SIZE 16384
250250
) ORGANIZATION INDEX DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = replica_num BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE ENABLE_MACRO_BLOCK_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
251251
============================================
252+
2.4 Fork未完成时删除源表向量索引(debug sync)
253+
============================================
254+
drop table if exists t2d;
255+
Warnings:
256+
Note 1051 Unknown table 'db_fork_index.t2d'
257+
drop table if exists t2d_fork;
258+
Warnings:
259+
Note 1051 Unknown table 'db_fork_index.t2d_fork'
260+
create table t2d (
261+
id int primary key,
262+
name varchar(50),
263+
age int,
264+
email varchar(100),
265+
emb vector(3)
266+
);
267+
insert into t2d values (1, 'Alice', 25, 'alice@example.com', '[0.203846,0.205289,0.880265]');
268+
insert into t2d values (2, 'Bob', 30, 'bob@example.com', '[0.1,0.2,0.3]');
269+
create vector index idx_vec_race on t2d(emb) with (distance=l2, type=hnsw, lib=vsag);
270+
# 获取源表table_id(用于等待fork任务阶段)
271+
# 卡在FORK_TABLE_SUCCESS:RS 侧任务已到 SUCCESS 但未执行完 cleanup(fork 仍未完成)
272+
alter system set debug_sync_timeout = '120s';
273+
set ob_global_debug_sync = 'reset';
274+
set ob_global_debug_sync = 'FORK_TABLE_SUCCESS wait_for signal_fork_success_resume execute 10000';
275+
# fork table 客户端返回后 RS 侧任务继续;此处与 lock 用例一致不使用 --send
276+
fork table t2d to t2d_fork;
277+
set ob_trx_timeout = 100000000;
278+
set ob_query_timeout = 100000000;
279+
use db_fork_index;
280+
# fork未完成:发起删除源表向量索引(与 fork cleanup 并发;历史问题:可能卡死/泄漏锁)
281+
# drop index 会等待 fork 在 SUCCESS 卡点之前仍持有的 DDL/表锁;同步执行会与 signal 死锁,故对 drop 使用 --send
282+
drop index idx_vec_race on t2d;;
283+
set ob_global_debug_sync = 'FORK_TABLE_SUCCESS clear';
284+
set ob_global_debug_sync = 'now signal signal_fork_success_resume';
285+
# 验证:源表向量索引已删除;fork表仍保留向量索引定义
286+
show create table t2d;
287+
Table Create Table
288+
t2d CREATE TABLE `t2d` (
289+
`id` int(11) NOT NULL,
290+
`name` varchar(50) DEFAULT NULL,
291+
`age` int(11) DEFAULT NULL,
292+
`email` varchar(100) DEFAULT NULL,
293+
`emb` VECTOR(3) DEFAULT NULL,
294+
PRIMARY KEY (`id`)
295+
) ORGANIZATION INDEX DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = replica_num BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE ENABLE_MACRO_BLOCK_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
296+
show create table t2d_fork;
297+
Table Create Table
298+
t2d_fork CREATE TABLE `t2d_fork` (
299+
`id` int(11) NOT NULL,
300+
`name` varchar(50) DEFAULT NULL,
301+
`age` int(11) DEFAULT NULL,
302+
`email` varchar(100) DEFAULT NULL,
303+
`emb` VECTOR(3) DEFAULT NULL,
304+
PRIMARY KEY (`id`),
305+
VECTOR KEY `idx_vec_race` (`emb`) WITH (DISTANCE=L2, TYPE=HNSW, LIB=VSAG, M=16, EF_CONSTRUCTION=200, EF_SEARCH=64) BLOCK_SIZE 16384
306+
) ORGANIZATION INDEX DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE ENABLE_MACRO_BLOCK_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
307+
set ob_global_debug_sync = 'reset';
308+
============================================
252309
3. Fork Table with Unique Index
253310
============================================
254311
drop table if exists t3;
@@ -381,6 +438,8 @@ drop table if exists t2b;
381438
drop table if exists t2b_fork;
382439
drop table if exists t2c;
383440
drop table if exists t2c_fork;
441+
drop table if exists t2d;
442+
drop table if exists t2d_fork;
384443
drop table if exists t3;
385444
drop table if exists t3_fork;
386445
drop table if exists t4;

tools/deploy/mysql_test/test_suite/fork_table/t/fork_table_with_index.test

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##owner: fankun.fan
22
##owner group: 底层引擎部-轻量版
33
##description: Fork Table索引处理测试
4-
##tags: fork_table index
4+
##tags: fork_table index debug_sync vector_index drop_index
55
##author: fankun.fan
66

77
--disable_warnings
@@ -238,6 +238,90 @@ connection default;
238238
--replace_regex /REPLICA_NUM = [0-9]*/REPLICA_NUM = replica_num/g
239239
show create table t2c_fork;
240240

241+
--echo ============================================
242+
--echo 2.4 Fork未完成时删除源表向量索引(debug sync)
243+
--echo ============================================
244+
245+
drop table if exists t2d;
246+
drop table if exists t2d_fork;
247+
248+
create table t2d (
249+
id int primary key,
250+
name varchar(50),
251+
age int,
252+
email varchar(100),
253+
emb vector(3)
254+
);
255+
256+
insert into t2d values (1, 'Alice', 25, 'alice@example.com', '[0.203846,0.205289,0.880265]');
257+
insert into t2d values (2, 'Bob', 30, 'bob@example.com', '[0.1,0.2,0.3]');
258+
259+
create vector index idx_vec_race on t2d(emb) with (distance=l2, type=hnsw, lib=vsag);
260+
261+
--echo # 获取源表table_id(用于等待fork任务阶段)
262+
--disable_query_log
263+
let $table_t2d_id = query_get_value(select table_id from oceanbase.__all_table where table_name = 't2d' and database_id = (select database_id from oceanbase.__all_database where database_name = 'db_fork_index'), table_id, 1);
264+
--enable_query_log
265+
266+
--echo # 卡在FORK_TABLE_SUCCESS:RS 侧任务已到 SUCCESS 但未执行完 cleanup(fork 仍未完成)
267+
connection obsys;
268+
alter system set debug_sync_timeout = '120s';
269+
sleep 1;
270+
set ob_global_debug_sync = 'reset';
271+
set ob_global_debug_sync = 'FORK_TABLE_SUCCESS wait_for signal_fork_success_resume execute 10000';
272+
sleep 1;
273+
connection default;
274+
275+
--echo # fork table 客户端返回后 RS 侧任务继续;此处与 lock 用例一致不使用 --send
276+
fork table t2d to t2d_fork;
277+
278+
--disable_query_log
279+
let $table_t2d_fork_id = query_get_value(select table_id from oceanbase.__all_table where table_name = 't2d_fork' and database_id = (select database_id from oceanbase.__all_database where database_name = 'db_fork_index'), table_id, 1);
280+
--enable_query_log
281+
282+
connect (conn_drop,$OBMYSQL_MS0,root@sys,,db_fork_index,$OBMYSQL_PORT);
283+
connection conn_drop;
284+
set ob_trx_timeout = 100000000;
285+
set ob_query_timeout = 100000000;
286+
use db_fork_index;
287+
288+
connection default;
289+
let $wait_src_table_id= $table_t2d_id;
290+
let $wait_dest_table_id= $table_t2d_fork_id;
291+
let $wait_status= SUCCESS;
292+
--source mysql_test/test_suite/fork_table/include/wait_fork_table.inc
293+
294+
--echo # fork未完成:发起删除源表向量索引(与 fork cleanup 并发;历史问题:可能卡死/泄漏锁)
295+
--echo # drop index 会等待 fork 在 SUCCESS 卡点之前仍持有的 DDL/表锁;同步执行会与 signal 死锁,故对 drop 使用 --send
296+
connection conn_drop;
297+
--send drop index idx_vec_race on t2d;
298+
299+
connection obsys;
300+
set ob_global_debug_sync = 'FORK_TABLE_SUCCESS clear';
301+
set ob_global_debug_sync = 'now signal signal_fork_success_resume';
302+
connection default;
303+
304+
let $wait_src_table_id= $table_t2d_id;
305+
let $wait_dest_table_id= $table_t2d_fork_id;
306+
--source mysql_test/test_suite/fork_table/include/wait_fork_table.inc
307+
308+
connection conn_drop;
309+
--reap
310+
311+
connection default;
312+
313+
--echo # 验证:源表向量索引已删除;fork表仍保留向量索引定义
314+
--replace_regex /REPLICA_NUM = [0-9]*/REPLICA_NUM = replica_num/g
315+
show create table t2d;
316+
show create table t2d_fork;
317+
318+
disconnect conn_drop;
319+
connection default;
320+
321+
connection obsys;
322+
set ob_global_debug_sync = 'reset';
323+
connection default;
324+
241325
--echo ============================================
242326
--echo 3. Fork Table with Unique Index
243327
--echo ============================================
@@ -352,8 +436,11 @@ drop table if exists t2b;
352436
drop table if exists t2b_fork;
353437
drop table if exists t2c;
354438
drop table if exists t2c_fork;
439+
drop table if exists t2d;
440+
drop table if exists t2d_fork;
355441
drop table if exists t3;
356442
drop table if exists t3_fork;
357443
drop table if exists t4;
358444
drop table if exists t4_fork;
359445
drop database if exists db_fork_index;
446+

0 commit comments

Comments
 (0)