From: Frazer Clement Date: February 21 2012 2:05am Subject: bzr push into mysql-5.1-telco-7.0 branch (frazer.clement:4838 to 4839) List-Archive: http://lists.mysql.com/commits/142997 Message-Id: <201202210205.q1L25nBl019631@acsmt358.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4839 Frazer Clement 2012-02-21 Test commit reorg with max_rows scaling modified: mysql-test/suite/ndb/t/ndb_addnode.test sql/ha_ndbcluster.cc 4838 Frazer Clement 2012-01-31 Align #include behaviour with 7.2 modified: sql/ndb_conflict.cc sql/ndb_conflict.h === modified file 'mysql-test/suite/ndb/t/ndb_addnode.test' --- a/mysql-test/suite/ndb/t/ndb_addnode.test 2011-05-06 13:48:00 +0000 +++ b/mysql-test/suite/ndb/t/ndb_addnode.test 2012-02-21 02:04:43 +0000 @@ -19,9 +19,13 @@ CREATE TABLESPACE ts_1 create table t1(id int NOT NULL PRIMARY KEY, data char(8)) engine=ndb; create table t2(id int NOT NULL PRIMARY KEY, data char(8)) TABLESPACE ts_1 STORAGE DISK engine=ndb; +create table t5(id int NOT NULL PRIMARY KEY, data char(8)) max_rows=100000000 engine=ndb; load data local infile 'suite/ndb/data/table_data10000.dat' into table t1 fields terminated by ' ' lines terminated by '\n'; load data local infile 'suite/ndb/data/table_data10000.dat' into table t2 fields terminated by ' ' lines terminated by '\n'; +load data local infile 'suite/ndb/data/table_data10000.dat' into table t5 fields terminated by ' ' lines terminated by '\n'; + +select @initial_t5_part_count:= count(1) from information_schema.partitions where table_schema="test" and table_name="t5"; ## Create nodegroup for "new" nodes --exec $NDB_MGM -e "create nodegroup 3,4" @@ -47,6 +51,18 @@ insert into t4(id, data) VALUES alter online table t1 reorganize partition; alter online table t2 reorganize partition; +alter online table t5 reorganize partition; + +select @later_t5_part_count:= count(1) from information_schema.partitions where table_schema="test" and table_name="t5"; + +let $t5_part_count_diff = query_get_value('select @later_t5_part_count-@initial_t5_part_count as diff',diff,1); + +--echo t5 partition count change is $t5_part_count_diff + +if (!$t5_part_count_diff) +{ + --die Number of t5 fragments did not increase in reorg +} ## Drop nodegroup with "new" nodes is not allowed with data one those nodes # NOTE: --error=0 is due to return codes doesnt work on windoze @@ -56,7 +72,7 @@ alter online table t2 reorganize partiti ## Nodegroup with "new" nodes still exist after dropping it as shown: --exec $NDB_MGM -e show -drop table t1,t2,t3,t4; +drop table t1,t2,t3,t4,t5; ## Drop nodegroup with "new" nodes --exec $NDB_MGM -e "drop nodegroup 1" === modified file 'sql/ha_ndbcluster.cc' --- a/sql/ha_ndbcluster.cc 2012-01-31 10:01:22 +0000 +++ b/sql/ha_ndbcluster.cc 2012-02-21 02:04:43 +0000 @@ -14864,6 +14864,70 @@ ha_ndbcluster::set_up_partition_info(par } #ifndef NDB_WITHOUT_ONLINE_ALTER + +/* + determineTableNodeCount + + Returns the number of nodes holding at least one + fragment of the table +*/ +Uint32 determineTableNodeCount(const NDBTAB* table) +{ + Uint32 tabNodeCount= 0; + Uint32 fragCount= table->getFragmentCount(); + + Bitmask tabNodes; + for (Uint32 i=0; i < fragCount; i++) + { + Uint32 replicaNodes[4]; + if (table->getFragmentNodes(i, replicaNodes, NDB_ARRAY_SIZE(replicaNodes))) + { + Uint32 primaryFragNode = replicaNodes[0]; + if (!tabNodes.get(primaryFragNode)) + { + tabNodes.set(primaryFragNode); + tabNodeCount++; + } + } + else + { + abort(); + } + } + + return tabNodeCount; +} + +/* + determineScaledFragCount + + This method uses the fragmentation of the old table + to determine how many fragments it should have with + the current node configuration. + + The number of fragments per node of the old table is + determined and then extrapolated using the + new number of nodes +*/ +Uint32 determineScaledFragCount(const NDBTAB* old_tab) +{ + DBUG_ENTER("determineScaledFragCount"); + Uint32 oldTabFragCount = old_tab->getFragmentCount(); + Uint32 oldTabNodeCount = determineTableNodeCount(old_tab); + Uint32 newTabNodeCount = g_ndb_cluster_connection->no_db_nodes(); + assert(newTabNodeCount >= oldTabNodeCount); + + /* newTabFragCount = newTabNodeCount * (oldTabFragCount/oldTabNodeCount) */ + Uint32 newTabFragCount = (newTabNodeCount * oldTabFragCount) / oldTabNodeCount; + + DBUG_PRINT("info", ("Old tab #frags : %u, #nodes : %u\n", + oldTabFragCount, oldTabNodeCount)); + DBUG_PRINT("info", ("New tab #frags : %u, #nodes : %u\n", + newTabFragCount, newTabNodeCount)); + + DBUG_RETURN(newTabFragCount); +} + static HA_ALTER_FLAGS supported_alter_operations() { @@ -15000,8 +15064,25 @@ int ha_ndbcluster::check_if_supported_al if (alter_flags->is_set(HA_ALTER_TABLE_REORG)) { - new_tab.setFragmentCount(0); - new_tab.setFragmentData(0, 0); + if (old_tab->getMaxRows() != 0) + { + /* + Table has had fragment count adjusted by MAX_ROWS, + try to accomodate as part of reorg. + Should be no need to 'adjust', as if the existing table + frags/node is supportable, the new table should be + supportable. + */ + Uint32 scaledFragCount = determineScaledFragCount(old_tab); + new_tab.setFragmentCount(scaledFragCount); + } + else + { + /* Normal online reorg case, kernel decides # partitions */ + assert(old_tab->getMinRows() == 0); + new_tab.setFragmentCount(0); + new_tab.setFragmentData(0, 0); + } } else if (alter_flags->is_set(HA_ADD_PARTITION)) { @@ -15329,8 +15410,29 @@ int ha_ndbcluster::alter_table_phase1(TH { if (alter_flags->is_set(HA_ALTER_TABLE_REORG)) { - new_tab->setFragmentCount(0); - new_tab->setFragmentData(0, 0); + if (old_tab->getMaxRows() != 0) + { + /* + Table has had fragment count adjusted by MAX_ROWS, + try to accomodate as part of reorg + Should be no need to 'adjust', as if the existing table + frags/node is supportable, the new table should be + supportable. + */ + Uint32 origFragCount = old_tab->getFragmentCount(); + Uint32 scaledFragCount = determineScaledFragCount(old_tab); + /* TODO : REMOVE */ + fprintf(stderr, "Alter Table (%s) scaling fragment count from %u to %u\n", + old_tab->getName(), origFragCount, scaledFragCount); + new_tab->setFragmentCount(scaledFragCount); + } + else + { + /* Normal online reorg case, kernel decides # partitions */ + assert(old_tab->getMinRows() == 0); + new_tab->setFragmentCount(0); + new_tab->setFragmentData(0, 0); + } } else if (alter_flags->is_set(HA_ADD_PARTITION)) { No bundle (reason: useless for push emails).