Skip to content

Commit 07436eb

Browse files
committed
Bug #33523991 Ndb online reorg : Scan count verification
Online table reorganisation increases the number of fragments of a table, and moves rows between them. This is done in a number of steps : 1 Copying - rows are duplicated to the new fragments 2 Commit - The distribution info is changed (hashmap count and total fragments) 3 Commit-wait - Wait for scan activity using the old distribution to stop 4 Deleting - Delete rows which have moved-out of existing partitions 5 Complete - Remove the reference to the old hashmap 6 Complete-wait - Wait for scan activity started since step 2 to stop Due to a counting error, the reorg can get stuck in step 6 as it does not correctly decrement the scan reference count, which therefore never reaches zero. This is fixed, and an MTR testcase is extended to cover the scenario. Approved by : Mauritz Sundell <[email protected]>
1 parent 2db179f commit 07436eb

File tree

3 files changed

+113
-9
lines changed

3 files changed

+113
-9
lines changed

mysql-test/suite/ndb/r/ndb_add_partition.result

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,46 @@ PRIMARY KEY(c) - UniqueHashIndex
27282728
NDBT_ProgramExit: 0 - OK
27292729

27302730
drop table t1,t2,t3,t5;
2731+
Bug 33523991 Ndb online reorg : Scan count verification
2732+
Scan count issue on complete phase of reorg
2733+
create table t1 (a int primary key, b int, c int, d int, unique(b), unique(c)) engine=ndb;
2734+
Populate some data
2735+
insert into t1 values (1,1,1,1);
2736+
insert into t1 select a+1, b+1, c+1, d+1 from t1;
2737+
insert into t1 select a+2, b+2, c+2, d+2 from t1;
2738+
insert into t1 select a+4, b+4, c+4, d+4 from t1;
2739+
insert into t1 select a+8, b+8, c+8, d+8 from t1;
2740+
insert into t1 select a+16, b+16, c+16, d+16 from t1;
2741+
insert into t1 select a+32, b+32, c+32, d+32 from t1;
2742+
insert into t1 select a+64, b+64, c+64, d+64 from t1;
2743+
insert into t1 select a+128, b+128, c+128, d+128 from t1;
2744+
insert into t1 select a+256, b+256, c+256, d+256 from t1;
2745+
insert into t1 select a+512, b+512, c+512, d+512 from t1;
2746+
insert into t1 select a+1024, b+1024, c+1024, d+1024 from t1;
2747+
insert into t1 select a+2048, b+2048, c+2048, d+2048 from t1;
2748+
create procedure scans (max_iterations int)
2749+
sp: begin
2750+
DECLARE sum_d int;
2751+
set @x=0;
2752+
repeat
2753+
select sum(d) into sum_d from t1;
2754+
set @x = @x + 1;
2755+
if sum_d = 0
2756+
then
2757+
leave sp;
2758+
end if;
2759+
until @x=max_iterations
2760+
end repeat;
2761+
end%
2762+
call scans(20000);;
2763+
alter table t1 algorithm=inplace, add partition partitions 1;
2764+
Alter ok, run again
2765+
alter table t1 algorithm=inplace, add partition partitions 1;
2766+
Second alter ok, finish scans
2767+
select sum(d) into @sum_d from t1;
2768+
insert into t1 values (20000,20000,20000, 0 - @sum_d);
2769+
drop procedure scans;
2770+
drop table t1;
27312771
alter tablespace ts1 drop datafile 'datafile.dat' engine = ndb;
27322772
drop tablespace ts1 engine = ndb;
27332773
drop logfile group lg1 engine = ndb;

mysql-test/suite/ndb/t/ndb_add_partition.test

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#but needs to be kept for tests that would need MyISAM in future.
44
--source include/force_myisam_default.inc
55

6-
--source include/have_ndb.inc
6+
--source include/have_multi_ndb.inc
77
--source include/not_embedded.inc
88

99
--disable_warnings
@@ -458,6 +458,69 @@ let $ndb_desc_opts= -b -i -d test t5;
458458
source suite/ndb/include/ndb_desc_print.inc;
459459

460460
drop table t1,t2,t3,t5;
461+
462+
--echo Bug 33523991 Ndb online reorg : Scan count verification
463+
--echo Scan count issue on complete phase of reorg
464+
465+
create table t1 (a int primary key, b int, c int, d int, unique(b), unique(c)) engine=ndb;
466+
467+
--echo Populate some data
468+
insert into t1 values (1,1,1,1);
469+
insert into t1 select a+1, b+1, c+1, d+1 from t1;
470+
insert into t1 select a+2, b+2, c+2, d+2 from t1;
471+
insert into t1 select a+4, b+4, c+4, d+4 from t1;
472+
insert into t1 select a+8, b+8, c+8, d+8 from t1;
473+
insert into t1 select a+16, b+16, c+16, d+16 from t1;
474+
insert into t1 select a+32, b+32, c+32, d+32 from t1;
475+
insert into t1 select a+64, b+64, c+64, d+64 from t1;
476+
insert into t1 select a+128, b+128, c+128, d+128 from t1;
477+
insert into t1 select a+256, b+256, c+256, d+256 from t1;
478+
insert into t1 select a+512, b+512, c+512, d+512 from t1;
479+
insert into t1 select a+1024, b+1024, c+1024, d+1024 from t1;
480+
insert into t1 select a+2048, b+2048, c+2048, d+2048 from t1;
481+
482+
--connection server2
483+
484+
delimiter %;
485+
create procedure scans (max_iterations int)
486+
sp: begin
487+
DECLARE sum_d int;
488+
set @x=0;
489+
repeat
490+
select sum(d) into sum_d from t1;
491+
set @x = @x + 1;
492+
if sum_d = 0
493+
then
494+
leave sp;
495+
end if;
496+
until @x=max_iterations
497+
end repeat;
498+
end%
499+
500+
delimiter ;%
501+
502+
--send call scans(20000);
503+
504+
--connection server1
505+
506+
alter table t1 algorithm=inplace, add partition partitions 1;
507+
508+
--echo Alter ok, run again
509+
510+
alter table t1 algorithm=inplace, add partition partitions 1;
511+
512+
--echo Second alter ok, finish scans
513+
select sum(d) into @sum_d from t1;
514+
insert into t1 values (20000,20000,20000, 0 - @sum_d);
515+
516+
--connection server2
517+
--reap
518+
519+
drop procedure scans;
520+
521+
--connection server1
522+
drop table t1;
523+
461524
alter tablespace ts1 drop datafile 'datafile.dat' engine = ndb;
462525
drop tablespace ts1 engine = ndb;
463526
drop logfile group lg1 engine = ndb;

storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15560,7 +15560,6 @@ Dbdih::start_scan_on_table(TabRecordPtr tabPtr,
1556015560
}
1556115561

1556215562
tabPtr.p->m_scan_count[0]++;
15563-
ndbrequire(tabPtr.p->m_map_ptr_i != DihScanTabConf::InvalidCookie);
1556415563
{
1556515564
DihScanTabConf* conf = (DihScanTabConf*)signal->getDataPtrSend();
1556615565
conf->tableId = tabPtr.i;
@@ -15579,7 +15578,7 @@ Dbdih::start_scan_on_table(TabRecordPtr tabPtr,
1557915578
conf->fragmentCount = tabPtr.p->partitionCount;
1558015579

1558115580
conf->noOfBackups = tabPtr.p->noOfBackups;
15582-
conf->scanCookie = tabPtr.p->m_map_ptr_i;
15581+
conf->scanCookie = tabPtr.p->m_scan_reorg_flag;
1558315582
conf->reorgFlag = tabPtr.p->m_scan_reorg_flag;
1558415583
NdbMutex_Unlock(&tabPtr.p->theMutex);
1558515584
return;
@@ -15598,7 +15597,7 @@ Dbdih::start_scan_on_table(TabRecordPtr tabPtr,
1559815597

1559915598
void
1560015599
Dbdih::complete_scan_on_table(TabRecordPtr tabPtr,
15601-
Uint32 map_ptr_i,
15600+
Uint32 scanCookie,
1560215601
EmulatedJamBuffer *jambuf)
1560315602
{
1560415603
/**
@@ -15610,16 +15609,18 @@ Dbdih::complete_scan_on_table(TabRecordPtr tabPtr,
1561015609
*/
1561115610

1561215611
NdbMutex_Lock(&tabPtr.p->theMutex);
15613-
if (map_ptr_i == tabPtr.p->m_map_ptr_i)
15612+
if (scanCookie == tabPtr.p->m_scan_reorg_flag)
1561415613
{
15614+
/* Scan started + completed in same reorg state */
1561515615
thrjam(jambuf);
15616-
ndbassert(tabPtr.p->m_scan_count[0]);
15616+
ndbrequire(tabPtr.p->m_scan_count[0]);
1561715617
tabPtr.p->m_scan_count[0]--;
1561815618
}
1561915619
else
1562015620
{
15621+
/* Scan started + completed in diff reorg states */
1562115622
thrjam(jambuf);
15622-
ndbassert(tabPtr.p->m_scan_count[1]);
15623+
ndbrequire(tabPtr.p->m_scan_count[1]);
1562315624
tabPtr.p->m_scan_count[1]--;
1562415625
}
1562515626
NdbMutex_Unlock(&tabPtr.p->theMutex);
@@ -15872,7 +15873,7 @@ Dbdih::make_new_table_read_and_writeable(TabRecordPtr tabPtr,
1587215873
DIH_TAB_WRITE_UNLOCK(tabPtr.p);
1587315874

1587415875
/* These variables are only protected by mutex. */
15875-
ndbassert(tabPtr.p->m_scan_count[1] == 0);
15876+
ndbrequire(tabPtr.p->m_scan_count[1] == 0);
1587615877
tabPtr.p->m_scan_count[1] = tabPtr.p->m_scan_count[0];
1587715878
tabPtr.p->m_scan_count[0] = 0;
1587815879
tabPtr.p->m_scan_reorg_flag = 1;
@@ -15919,7 +15920,7 @@ Dbdih::make_old_table_non_writeable(TabRecordPtr tabPtr,
1591915920
* REORG_NOT_MOVED flag set we also start waiting for those
1592015921
* scans to complete here.
1592115922
*/
15922-
ndbassert(tabPtr.p->m_scan_count[1] == 0);
15923+
ndbrequire(tabPtr.p->m_scan_count[1] == 0);
1592315924
tabPtr.p->m_scan_count[1] = tabPtr.p->m_scan_count[0];
1592415925
tabPtr.p->m_scan_count[0] = 0;
1592515926
wait_flag = true;

0 commit comments

Comments
 (0)