[MDEV-9254] 'truncate table' make server crash in sharding&ha configuration when wrapper is oracle Created: 2015-12-09  Updated: 2023-01-22  Resolved: 2023-01-22

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Spider
Affects Version/s: 10.0.22
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: chengxiaoz Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Environment:

windows centos



 Description   

In sharding&ha configuration, "truncate table/delete from table" statement will make the server crash when wrapper is oracle, but it is ok when wrapper is mysql.

-------------------------------------
example:
CREATE SERVER ora_backend1
FOREIGN DATA WRAPPER oracle
OPTIONS(
HOST '$ORA_BACKEND1_IP',
PORT $ORA_BACKEND1_PORT,
DATABASE '$ORA_DATABASE',
USER '$ORA_USER',
PASSWORD '$ORA_PWD'
);
SELECT SPIDER_DIRECT_SQL('begin execute immediate \'DROP TABLE "FED_HA1"\'; exception when others then null; end;', '', 'srv "ora_backend1"');
SELECT SPIDER_DIRECT_SQL('create table fed_ha1(a int , b float, c varchar(10), d char(10), e date)', '', 'srv "ora_backend1"');

SELECT SPIDER_DIRECT_SQL('begin execute immediate \'DROP TABLE "FED_HA2"\'; exception when others then null; end;', '', 'srv "ora_backend1"');
SELECT SPIDER_DIRECT_SQL('create table fed_ha2(a int , b float, c varchar(10), d char(10), e date)', '', 'srv "ora_backend1"');

--echo create spider table on proxy
drop table if exists ora_fed_ha;
create table ora_fed_ha(A int, B float, C varchar(10), D char(10), E date) ENGINE = SPIDER CONNECTION='wrapper "oracle", table "FED_HA1 FED_HA2", srv "ora_backend1 ora_backend1"';

insert into ora_fed_ha values(1, 1.1, 'aaaa1', 'bbbbbb1', null);
select * from ora_fed_ha;
dtruncate ora_fed_ha;
-------------------------------------
This may be cased by an oversight, because in all other functions

SPIDER_CONN *conn = conns[roop_count];
spider_db_handler *dbton_hdl = dbton_handler[conn->dbton_id];

is used to get spider_db_handler.
for example, line 6327 in spider_db_update function of spd_db_conn.cc
https://github.com/MariaDB/server/blob/10.1/storage/spider/spd_db_conn.cc

'truncate table' make server crash when wrapper is oracle but ok when wrapper is mysql, because coincidence of value.
for example, there are two tables, myt1 and orat1.
create table myt1(A int) ENGINE = SPIDER CONNECTION='wrapper "oracle", table "T1 T2", srv "my_backend1 my_backend1"';
create table orat1(A int) ENGINE = SPIDER CONNECTION='wrapper "oracle", table "T1 T2", srv "ora_backend1 ora_backend1"';
for myt1, the memory value is
SPIDER_SHARE.use_sql_dbton_count=1
SPIDER_SHARE.use_sql_dbton_ids[0]=0
SPIDER_SHARE.use_sql_dbton_ids[1]=0 initial value
ha_spider.dbton_handler[0] is the pointer of mysql_db_handler object
ha_spider.dbton_handler[1]=0
for orat1, the memory value is
SPIDER_SHARE.use_sql_dbton_count=1
SPIDER_SHARE.use_sql_dbton_ids[0]=1
SPIDER_SHARE.use_sql_dbton_ids[1]=0 initial value
ha_spider.dbton_handler[0]=0
ha_spider.dbton_handler[1] is the pointer of oracle_db_handler object

when execute codes

dbton_id = share->use_sql_dbton_ids[roop_count];
spider_db_handler *dbton_hdl = spider->dbton_handler[dbton_id];

For the first link and second link of myt1, dbton_id is 0 and can get the right dbton_handler.
For orat1, the first link's dbton_id is 1 and can get the right dbton_handler.
But the second link's dbton_id is 0, and ha_spider.dbton_handler[0]=0, then the null point make the server crash.
--------------------------------------------------------

have fixed the problem and create a pull request
https://github.com/MariaDB/server/pull/129


Generated at Thu Feb 08 07:33:17 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.