From c49a5af749bb91d6862348a49f01ba6d7c782da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Thu, 28 Nov 2024 13:06:23 +0100 Subject: [PATCH] RONDB-785: Added new command to set LocationDomainId in ndb_mgm --- .../suite/ndb/r/ndb_location_domain_id.result | 173 +++++++++++++ .../ndb/r/ndb_location_domain_id_2ng.result | 220 ++++++++++++++++ .../suite/ndb/t/ndb_location_domain_id.test | 52 ++++ .../ndb/t/ndb_location_domain_id_2ng.cnf | 3 + .../ndb/t/ndb_location_domain_id_2ng.test | 67 +++++ .../ndb/include/kernel/GlobalSignalNumbers.h | 5 +- storage/ndb/include/kernel/ndb_limits.h | 1 + .../include/kernel/signaldata/SetDomainId.hpp | 100 ++++++++ storage/ndb/include/mgmapi/mgmapi.h | 13 + storage/ndb/include/ndb_version.h.in | 22 ++ .../debugger/signaldata/SignalNames.cpp | 3 + .../ndb/src/common/mgmcommon/ConfigInfo.cpp | 4 +- storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp | 13 + storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.hpp | 1 + storage/ndb/src/kernel/blocks/dbspj/Dbspj.hpp | 1 + .../ndb/src/kernel/blocks/dbspj/DbspjInit.cpp | 1 + .../ndb/src/kernel/blocks/dbspj/DbspjMain.cpp | 26 ++ .../src/kernel/blocks/dbspj/DbspjProxy.cpp | 69 ++++- .../src/kernel/blocks/dbspj/DbspjProxy.hpp | 22 +- storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp | 1 + .../ndb/src/kernel/blocks/dbtc/DbtcInit.cpp | 1 + .../ndb/src/kernel/blocks/dbtc/DbtcMain.cpp | 33 ++- .../ndb/src/kernel/blocks/dbtc/DbtcProxy.cpp | 71 +++++- .../ndb/src/kernel/blocks/dbtc/DbtcProxy.hpp | 22 +- storage/ndb/src/kernel/blocks/qmgr/Qmgr.hpp | 19 +- .../ndb/src/kernel/blocks/qmgr/QmgrInit.cpp | 4 + .../ndb/src/kernel/blocks/qmgr/QmgrMain.cpp | 239 +++++++++++++++++- storage/ndb/src/kernel/vm/Emulator.hpp | 1 + storage/ndb/src/mgmapi/mgmapi.cpp | 41 +++ .../ndb/src/mgmclient/CommandInterpreter.cpp | 114 ++++++++- storage/ndb/src/mgmsrv/MgmtSrvr.cpp | 166 +++++++++++- storage/ndb/src/mgmsrv/MgmtSrvr.hpp | 12 +- storage/ndb/src/mgmsrv/Services.cpp | 32 +++ storage/ndb/src/mgmsrv/Services.hpp | 2 + storage/ndb/src/mgmsrv/ndb_mgmd_error.h | 1 + storage/ndb/src/ndbapi/ClusterMgr.cpp | 87 +++++++ storage/ndb/src/ndbapi/ClusterMgr.hpp | 2 + storage/ndb/src/ndbapi/Ndb.cpp | 9 +- storage/ndb/src/ndbapi/TransporterFacade.cpp | 7 +- storage/ndb/src/ndbapi/TransporterFacade.hpp | 10 +- .../ndb/src/ndbapi/ndb_cluster_connection.cpp | 122 +++++++-- .../ndbapi/ndb_cluster_connection_impl.hpp | 1 + storage/ndb/src/ndbapi/ndberror.cpp | 6 +- 43 files changed, 1755 insertions(+), 44 deletions(-) create mode 100644 mysql-test/suite/ndb/r/ndb_location_domain_id.result create mode 100644 mysql-test/suite/ndb/r/ndb_location_domain_id_2ng.result create mode 100644 mysql-test/suite/ndb/t/ndb_location_domain_id.test create mode 100644 mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.cnf create mode 100644 mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.test create mode 100644 storage/ndb/include/kernel/signaldata/SetDomainId.hpp diff --git a/mysql-test/suite/ndb/r/ndb_location_domain_id.result b/mysql-test/suite/ndb/r/ndb_location_domain_id.result new file mode 100644 index 000000000000..480152566323 --- /dev/null +++ b/mysql-test/suite/ndb/r/ndb_location_domain_id.result @@ -0,0 +1,173 @@ +Configuration changed to reflect new location domain id of node 1 +Now changing location domain id in the cluster +Node 1 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 2 +Now changing location domain id in the cluster +Node 2 now has location domain id 2 in the cluster + +Configuration changed to reflect new location domain id of node 16 +Now changing location domain id in the cluster +Node 16 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 32 +Now changing location domain id in the cluster +Node 32 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 48 +Now changing location domain id in the cluster +Node 48 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 49 +Now changing location domain id in the cluster +Node 49 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 63 +Now changing location domain id in the cluster +Node 63 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 127 +Now changing location domain id in the cluster +Node 127 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 192 +Now changing location domain id in the cluster +Node 192 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 228 +Now changing location domain id in the cluster +Node 228 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 229 +Now changing location domain id in the cluster +Node 229 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 230 +Now changing location domain id in the cluster +Node 230 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 231 +Now changing location domain id in the cluster +Node 231 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 232 +Now changing location domain id in the cluster +Node 232 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 233 +Now changing location domain id in the cluster +Node 233 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 255 +Now changing location domain id in the cluster +Node 255 now has location domain id 1 in the cluster + +create table t1 (a int not null primary key) engine ndb; +insert into t1 values (0),(1),(2),(3); +select * from t1 order by a; +a +0 +1 +2 +3 + +select a from t1 where a = 0; +a +0 +select a from t1 where a = 1; +a +1 +select a from t1 where a = 2; +a +2 +select a from t1 where a = 3; +a +3 + +Configuration changed to reflect new location domain id of node 1 +Now changing location domain id in the cluster +Node 1 now has location domain id 2 in the cluster + +Configuration changed to reflect new location domain id of node 2 +Now changing location domain id in the cluster +Node 2 now has location domain id 1 in the cluster + + +select a from t1 where a = 0; +a +0 +select a from t1 where a = 1; +a +1 +select a from t1 where a = 2; +a +2 +select a from t1 where a = 3; +a +3 + +drop table t1; +Configuration changed to reflect new location domain id of node 1 +Now changing location domain id in the cluster +Node 1 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 2 +Now changing location domain id in the cluster +Node 2 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 16 +Now changing location domain id in the cluster +Node 16 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 32 +Now changing location domain id in the cluster +Node 32 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 48 +Now changing location domain id in the cluster +Node 48 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 49 +Now changing location domain id in the cluster +Node 49 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 63 +Now changing location domain id in the cluster +Node 63 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 127 +Now changing location domain id in the cluster +Node 127 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 192 +Now changing location domain id in the cluster +Node 192 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 228 +Now changing location domain id in the cluster +Node 228 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 229 +Now changing location domain id in the cluster +Node 229 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 230 +Now changing location domain id in the cluster +Node 230 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 231 +Now changing location domain id in the cluster +Node 231 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 232 +Now changing location domain id in the cluster +Node 232 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 233 +Now changing location domain id in the cluster +Node 233 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 255 +Now changing location domain id in the cluster +Node 255 now has location domain id 0 in the cluster + diff --git a/mysql-test/suite/ndb/r/ndb_location_domain_id_2ng.result b/mysql-test/suite/ndb/r/ndb_location_domain_id_2ng.result new file mode 100644 index 000000000000..14f120a68ac6 --- /dev/null +++ b/mysql-test/suite/ndb/r/ndb_location_domain_id_2ng.result @@ -0,0 +1,220 @@ +Configuration changed to reflect new location domain id of node 1 +Now changing location domain id in the cluster +Node 1 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 2 +Now changing location domain id in the cluster +Node 2 now has location domain id 2 in the cluster + +Configuration changed to reflect new location domain id of node 3 +Now changing location domain id in the cluster +Node 3 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 4 +Now changing location domain id in the cluster +Node 4 now has location domain id 2 in the cluster + +Configuration changed to reflect new location domain id of node 16 +Now changing location domain id in the cluster +Node 16 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 32 +Now changing location domain id in the cluster +Node 32 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 48 +Now changing location domain id in the cluster +Node 48 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 49 +Now changing location domain id in the cluster +Node 49 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 63 +Now changing location domain id in the cluster +Node 63 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 127 +Now changing location domain id in the cluster +Node 127 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 192 +Now changing location domain id in the cluster +Node 192 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 228 +Now changing location domain id in the cluster +Node 228 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 229 +Now changing location domain id in the cluster +Node 229 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 230 +Now changing location domain id in the cluster +Node 230 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 231 +Now changing location domain id in the cluster +Node 231 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 232 +Now changing location domain id in the cluster +Node 232 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 233 +Now changing location domain id in the cluster +Node 233 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 255 +Now changing location domain id in the cluster +Node 255 now has location domain id 1 in the cluster + +create table t1 (a int not null primary key) engine ndb; +create table t2 (b int not null primary key) engine ndb; +insert into t1 values (0),(1),(2),(3); +insert into t2 values (0),(1),(2),(3); +select * from t1; +a +2 +3 +0 +1 + + +select a from t1 order by a; +a +0 +1 +2 +3 +select t1.a,t2.b from t1, t2 WHERE t1.a = t2.b order by t1.a; +a b +0 0 +1 1 +2 2 +3 3 + + + + +select a from t1 order by a; +a +0 +1 +2 +3 +select t1.a,t2.b from t1, t2 WHERE t1.a = t2.b order by t1.a; +a b +0 0 +1 1 +2 2 +3 3 + + +Configuration changed to reflect new location domain id of node 1 +Now changing location domain id in the cluster +Node 1 now has location domain id 2 in the cluster + +Configuration changed to reflect new location domain id of node 2 +Now changing location domain id in the cluster +Node 2 now has location domain id 1 in the cluster + +Configuration changed to reflect new location domain id of node 3 +Now changing location domain id in the cluster +Node 3 now has location domain id 2 in the cluster + +Configuration changed to reflect new location domain id of node 4 +Now changing location domain id in the cluster +Node 4 now has location domain id 1 in the cluster + + + +select a from t1 order by a; +a +0 +1 +2 +3 +select t1.a,t2.b from t1, t2 WHERE t1.a = t2.b order by t1.a; +a b +0 0 +1 1 +2 2 +3 3 + + +drop table t1; +drop table t2; +Configuration changed to reflect new location domain id of node 1 +Now changing location domain id in the cluster +Node 1 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 2 +Now changing location domain id in the cluster +Node 2 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 3 +Now changing location domain id in the cluster +Node 3 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 4 +Now changing location domain id in the cluster +Node 4 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 16 +Now changing location domain id in the cluster +Node 16 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 32 +Now changing location domain id in the cluster +Node 32 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 48 +Now changing location domain id in the cluster +Node 48 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 49 +Now changing location domain id in the cluster +Node 49 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 63 +Now changing location domain id in the cluster +Node 63 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 127 +Now changing location domain id in the cluster +Node 127 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 192 +Now changing location domain id in the cluster +Node 192 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 228 +Now changing location domain id in the cluster +Node 228 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 229 +Now changing location domain id in the cluster +Node 229 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 230 +Now changing location domain id in the cluster +Node 230 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 231 +Now changing location domain id in the cluster +Node 231 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 232 +Now changing location domain id in the cluster +Node 232 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 233 +Now changing location domain id in the cluster +Node 233 now has location domain id 0 in the cluster + +Configuration changed to reflect new location domain id of node 255 +Now changing location domain id in the cluster +Node 255 now has location domain id 0 in the cluster + diff --git a/mysql-test/suite/ndb/t/ndb_location_domain_id.test b/mysql-test/suite/ndb/t/ndb_location_domain_id.test new file mode 100644 index 000000000000..8546d7563229 --- /dev/null +++ b/mysql-test/suite/ndb/t/ndb_location_domain_id.test @@ -0,0 +1,52 @@ +-- source include/have_ndb.inc +-- source have_ndb_error_insert.inc +--exec $NDB_MGM --execute "1 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "2 LOCATION_DOMAIN_ID 2" +--exec $NDB_MGM --execute "16 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "32 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "48 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "49 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "63 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "127 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "192 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "228 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "229 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "230 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "231 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "232 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "233 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "255 LOCATION_DOMAIN_ID 1" +create table t1 (a int not null primary key) engine ndb; +insert into t1 values (0),(1),(2),(3); +select * from t1 order by a; +--exec $NDB_MGM --execute "2 ERROR 8121" +select a from t1 where a = 0; +select a from t1 where a = 1; +select a from t1 where a = 2; +select a from t1 where a = 3; +--exec $NDB_MGM --execute "2 ERROR 0" +--exec $NDB_MGM --execute "1 LOCATION_DOMAIN_ID 2" +--exec $NDB_MGM --execute "2 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "1 ERROR 8121" +select a from t1 where a = 0; +select a from t1 where a = 1; +select a from t1 where a = 2; +select a from t1 where a = 3; +--exec $NDB_MGM --execute "1 ERROR 0" +drop table t1; +--exec $NDB_MGM --execute "1 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "2 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "16 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "32 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "48 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "49 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "63 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "127 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "192 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "228 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "229 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "230 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "231 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "232 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "233 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "255 LOCATION_DOMAIN_ID 0" diff --git a/mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.cnf b/mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.cnf new file mode 100644 index 000000000000..7865a0c6aeb4 --- /dev/null +++ b/mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.cnf @@ -0,0 +1,3 @@ +!include ../my.cnf +[cluster_config.1] +ndbd=,,, diff --git a/mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.test b/mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.test new file mode 100644 index 000000000000..949e46099202 --- /dev/null +++ b/mysql-test/suite/ndb/t/ndb_location_domain_id_2ng.test @@ -0,0 +1,67 @@ +-- source include/have_ndb.inc +-- source have_ndb_error_insert.inc +--exec $NDB_MGM --execute "1 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "2 LOCATION_DOMAIN_ID 2" +--exec $NDB_MGM --execute "3 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "4 LOCATION_DOMAIN_ID 2" +--exec $NDB_MGM --execute "16 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "32 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "48 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "49 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "63 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "127 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "192 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "228 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "229 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "230 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "231 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "232 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "233 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "255 LOCATION_DOMAIN_ID 1" +create table t1 (a int not null primary key) engine ndb; +create table t2 (b int not null primary key) engine ndb; +insert into t1 values (0),(1),(2),(3); +insert into t2 values (0),(1),(2),(3); +select * from t1; +--exec $NDB_MGM --execute "2 ERROR 8121" +--exec $NDB_MGM --execute "4 ERROR 8121" +select a from t1 order by a; +select t1.a,t2.b from t1, t2 WHERE t1.a = t2.b order by t1.a; +--exec $NDB_MGM --execute "2 ERROR 0" +--exec $NDB_MGM --execute "4 ERROR 0" +--exec $NDB_MGM --execute "2 ERROR 5079" +--exec $NDB_MGM --execute "4 ERROR 5079" +select a from t1 order by a; +select t1.a,t2.b from t1, t2 WHERE t1.a = t2.b order by t1.a; +--exec $NDB_MGM --execute "2 ERROR 0" +--exec $NDB_MGM --execute "4 ERROR 0" +--exec $NDB_MGM --execute "1 LOCATION_DOMAIN_ID 2" +--exec $NDB_MGM --execute "2 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "3 LOCATION_DOMAIN_ID 2" +--exec $NDB_MGM --execute "4 LOCATION_DOMAIN_ID 1" +--exec $NDB_MGM --execute "1 ERROR 8121" +--exec $NDB_MGM --execute "3 ERROR 8121" +select a from t1 order by a; +select t1.a,t2.b from t1, t2 WHERE t1.a = t2.b order by t1.a; +--exec $NDB_MGM --execute "1 ERROR 0" +--exec $NDB_MGM --execute "3 ERROR 0" +drop table t1; +drop table t2; +--exec $NDB_MGM --execute "1 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "2 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "3 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "4 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "16 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "32 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "48 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "49 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "63 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "127 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "192 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "228 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "229 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "230 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "231 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "232 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "233 LOCATION_DOMAIN_ID 0" +--exec $NDB_MGM --execute "255 LOCATION_DOMAIN_ID 0" diff --git a/storage/ndb/include/kernel/GlobalSignalNumbers.h b/storage/ndb/include/kernel/GlobalSignalNumbers.h index fec6ad664a61..7c9818515f8b 100644 --- a/storage/ndb/include/kernel/GlobalSignalNumbers.h +++ b/storage/ndb/include/kernel/GlobalSignalNumbers.h @@ -32,7 +32,7 @@ * * When adding a new signal, remember to update MAX_GSN and SignalNames.cpp */ -const GlobalSignalNumber MAX_GSN = 912; +const GlobalSignalNumber MAX_GSN = 946; struct GsnName { GlobalSignalNumber gsn; @@ -1233,4 +1233,7 @@ extern const GlobalSignalNumber NO_OF_SIGNAL_NAMES; #define GSN_SEND_PUSH_ABORTCONF 911 #define GSN_PUSH_ABORT_TRAIN_ORD 912 +#define GSN_SET_DOMAIN_ID_REQ 944 +#define GSN_SET_DOMAIN_ID_CONF 945 +#define GSN_SET_DOMAIN_ID_REF 946 #endif diff --git a/storage/ndb/include/kernel/ndb_limits.h b/storage/ndb/include/kernel/ndb_limits.h index 6de892927780..52fc07f20c98 100644 --- a/storage/ndb/include/kernel/ndb_limits.h +++ b/storage/ndb/include/kernel/ndb_limits.h @@ -28,6 +28,7 @@ #include "ndb_version.h" // Limits might depend on NDB version +#define MAX_INT (0x7fffffff) #define RNIL Uint32(0xffffff00) #define RNIL64 Uint64(0xffffffffffffff00) #define MBYTE64 Uint64(1024 * 1024) diff --git a/storage/ndb/include/kernel/signaldata/SetDomainId.hpp b/storage/ndb/include/kernel/signaldata/SetDomainId.hpp new file mode 100644 index 000000000000..5727c5f434b7 --- /dev/null +++ b/storage/ndb/include/kernel/signaldata/SetDomainId.hpp @@ -0,0 +1,100 @@ +/* + Copyright (c) 2024, 2024, Logical Clocks and/or its affiliates. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef SET_DOMAIN_ID_HPP +#define SET_DOMAIN_ID_HPP + +#include "SignalData.hpp" + +#define JAM_FILE_ID 550 + +class SetDomainIdReq +{ + /** + * Reciver(s) + */ + friend class Cmvmi; + + /** + * Sender + */ + friend class MgmtSrvr; + +public: + static constexpr Uint32 SignalLength = 4; + +public: + Uint32 senderId; + Uint32 senderRef; + Uint32 changeNodeId; + Uint32 locationDomainId; +}; + +class SetDomainIdConf +{ + /** + * Sender(s) + */ + friend class Cmvmi; + + /** + * Receiver + */ + friend class MgmtSrvr; + +public: + static constexpr Uint32 SignalLength = 4; + +public: + Uint32 senderId; + Uint32 senderRef; + Uint32 changeNodeId; + Uint32 locationDomainId; +}; + +class SetDomainIdRef +{ + /** + * Sender(s) + */ + friend class Cmvmi; + + /** + * Receiver + */ + friend class MgmtSrvr; + +public: + static constexpr Uint32 SignalLength = 5; + +public: + Uint32 senderId; + Uint32 senderRef; + Uint32 changeNodeId; + Uint32 locationDomainId; + Uint32 errorCode; +}; +#undef JAM_FILE_ID +#endif + diff --git a/storage/ndb/include/mgmapi/mgmapi.h b/storage/ndb/include/mgmapi/mgmapi.h index dc184ad79e51..c920e6d91a2f 100644 --- a/storage/ndb/include/mgmapi/mgmapi.h +++ b/storage/ndb/include/mgmapi/mgmapi.h @@ -1044,6 +1044,19 @@ extern "C" { */ int ndb_mgm_get_nodeid(NdbMgmHandle handle, int &nodeId); + /** + * Set location domain id for a node + * + * @param handle Management handle. + * @param node Node ID of node to get new location domain id + * @param new_location_domain_id New location domain id to be set for node + * + * @return 0 for success, -1 on error + */ + int ndb_mgm_set_domain_id(NdbMgmHandle handle, + const int nodeId, + const int new_location_domain_id); + /** * Set hostname for a deactivated node * diff --git a/storage/ndb/include/ndb_version.h.in b/storage/ndb/include/ndb_version.h.in index 89a461b98ce2..2307293deaf0 100644 --- a/storage/ndb/include/ndb_version.h.in +++ b/storage/ndb/include/ndb_version.h.in @@ -928,4 +928,26 @@ ndbd_handle_new_hash_function(Uint32 x) return false; } +static +inline +bool +ndbd_support_set_location_domain_id(Uint32 x) +{ + const Uint32 major = (x >> 16) & 0xFF; + const Uint32 minor = (x >> 8) & 0xFF; + const Uint32 rel = x & 0xFF; + if (major > 24) + { + return true; + } + if ((major == 22) && (minor == 10) && (rel >= 6)) + { + return true; + } + if ((major == 24) && (minor == 10) && (rel >= 0)) + { + return true; + } + return false; +} #endif diff --git a/storage/ndb/src/common/debugger/signaldata/SignalNames.cpp b/storage/ndb/src/common/debugger/signaldata/SignalNames.cpp index 84e261429040..7d2da43894df 100644 --- a/storage/ndb/src/common/debugger/signaldata/SignalNames.cpp +++ b/storage/ndb/src/common/debugger/signaldata/SignalNames.cpp @@ -916,5 +916,8 @@ const GsnName SignalNames [] = { ,{ GSN_SEND_PUSH_ABORTCONF, "SEND_PUSH_ABORTCONF" } ,{ GSN_PUSH_ABORT_TRAIN_ORD, "PUSH_ABORT_TRAIN_ORD" } ,{ GSN_API_BROADCAST_REP, "API_BROADCAST_REP" } + ,{ GSN_SET_DOMAIN_ID_REQ, "SET_DOMAIN_ID_REQ" } + ,{ GSN_SET_DOMAIN_ID_CONF, "SET_DOMAIN_ID_CONF" } + ,{ GSN_SET_DOMAIN_ID_REF, "SET_DOMAIN_ID_REF" } }; const unsigned short NO_OF_SIGNAL_NAMES = sizeof(SignalNames)/sizeof(GsnName); diff --git a/storage/ndb/src/common/mgmcommon/ConfigInfo.cpp b/storage/ndb/src/common/mgmcommon/ConfigInfo.cpp index 511ebf4d4445..9000a47779af 100644 --- a/storage/ndb/src/common/mgmcommon/ConfigInfo.cpp +++ b/storage/ndb/src/common/mgmcommon/ConfigInfo.cpp @@ -46,6 +46,8 @@ #define MAX_INT_RNIL 0xfffffeff #define MAX_INT32 0xffffffff #define MAX_PORT_NO 65535 +#define MAX_SIGNED_INT 0x7fffffff + #define _STR_VALUE(x) #x #define STR_VALUE(x) _STR_VALUE(x) @@ -2085,7 +2087,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::CI_INT, nullptr, "0", - "16" + STR_VALUE(MAX_SIGNED_INT) }, { diff --git a/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp b/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp index e7b0b94ff00d..744ed4edeed0 100644 --- a/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp +++ b/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #ifdef ERROR_INSERT #include @@ -158,6 +159,7 @@ Cmvmi::Cmvmi(Block_context& ctx) : addRecSignal(GSN_ACTIVATE_REQ, &Cmvmi::execACTIVATE_REQ); addRecSignal(GSN_DEACTIVATE_REQ, &Cmvmi::execDEACTIVATE_REQ); addRecSignal(GSN_SET_HOSTNAME_REQ, &Cmvmi::execSET_HOSTNAME_REQ); + addRecSignal(GSN_SET_DOMAIN_ID_REQ, &Cmvmi::execSET_DOMAIN_ID_REQ); #ifdef ERROR_INSERT addRecSignal(GSN_FSOPENCONF, &Cmvmi::execFSOPENCONF); addRecSignal(GSN_FSCLOSECONF, &Cmvmi::execFSCLOSECONF); @@ -3882,6 +3884,17 @@ void Cmvmi::execGET_CONFIG_REQ(Signal *signal) TheEmptyCallback); } +void Cmvmi::execSET_DOMAIN_ID_REQ(Signal *signal) +{ + jamEntry(); + /* Just route it to Qmgr that has more state to handle it. */ + sendSignal(QMGR_REF, + GSN_SET_DOMAIN_ID_REQ, + signal, + SetDomainIdReq::SignalLength, + JBB); +} + void Cmvmi::execSET_HOSTNAME_REQ(Signal *signal) { jamEntry(); diff --git a/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.hpp b/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.hpp index d623f60213b2..8a62d1c58126 100644 --- a/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.hpp +++ b/storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.hpp @@ -79,6 +79,7 @@ class Cmvmi : public SimulatedBlock { void execACTIVATE_REQ(Signal*); void execDEACTIVATE_REQ(Signal*); void execSET_HOSTNAME_REQ(Signal*); + void execSET_DOMAIN_ID_REQ(Signal*); #ifdef ERROR_INSERT Uint32 g_remaining_responses; diff --git a/storage/ndb/src/kernel/blocks/dbspj/Dbspj.hpp b/storage/ndb/src/kernel/blocks/dbspj/Dbspj.hpp index b683850339a4..b62f61259481 100644 --- a/storage/ndb/src/kernel/blocks/dbspj/Dbspj.hpp +++ b/storage/ndb/src/kernel/blocks/dbspj/Dbspj.hpp @@ -94,6 +94,7 @@ class Dbspj: public SimulatedBlock { /** * General signals */ + void execSET_DOMAIN_ID_REQ(Signal* signal); void execDUMP_STATE_ORD(Signal* signal){} void execREAD_NODESCONF(Signal*); void execREAD_CONFIG_REQ(Signal* signal); diff --git a/storage/ndb/src/kernel/blocks/dbspj/DbspjInit.cpp b/storage/ndb/src/kernel/blocks/dbspj/DbspjInit.cpp index 1af817606b4c..1f5460ca6ff8 100644 --- a/storage/ndb/src/kernel/blocks/dbspj/DbspjInit.cpp +++ b/storage/ndb/src/kernel/blocks/dbspj/DbspjInit.cpp @@ -49,6 +49,7 @@ Dbspj::Dbspj(Block_context& ctx, Uint32 instanceNumber): BLOCK_CONSTRUCTOR(Dbspj); addRecSignal(GSN_SIGNAL_DROPPED_REP, &Dbspj::execSIGNAL_DROPPED_REP, true); + addRecSignal(GSN_SET_DOMAIN_ID_REQ, &Dbspj::execSET_DOMAIN_ID_REQ); addRecSignal(GSN_DUMP_STATE_ORD, &Dbspj::execDUMP_STATE_ORD); addRecSignal(GSN_READ_NODESCONF, &Dbspj::execREAD_NODESCONF); addRecSignal(GSN_READ_CONFIG_REQ, &Dbspj::execREAD_CONFIG_REQ); diff --git a/storage/ndb/src/kernel/blocks/dbspj/DbspjMain.cpp b/storage/ndb/src/kernel/blocks/dbspj/DbspjMain.cpp index 556025698b46..77323e23bf36 100644 --- a/storage/ndb/src/kernel/blocks/dbspj/DbspjMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbspj/DbspjMain.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -817,6 +818,31 @@ Dbspj::execREAD_NODESCONF(Signal* signal) sendSTTORRY(signal); } +void Dbspj::execSET_DOMAIN_ID_REQ(Signal *signal) { + jamEntry(); + const SetDomainIdReq* const req = + (const SetDomainIdReq *)signal->getDataPtr(); + Uint32 senderId = req->senderId; + BlockReference senderRef = req->senderRef; + NodeId changeNodeId = req->changeNodeId; + Uint32 locationDomainId = req->locationDomainId; + + /* Change the location domain id of the changeNodeId */ + m_location_domain_id[changeNodeId] = locationDomainId; + + /* Send response back, this should never fail, so always CONF */ + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtrSend(); + conf->senderId = senderId; + conf->senderRef = reference(); + conf->changeNodeId = changeNodeId; + conf->locationDomainId = locationDomainId; + sendSignal(senderRef, + GSN_SET_DOMAIN_ID_CONF, + signal, + SetDomainIdConf::SignalLength, + JBB); +} + void Dbspj::execINCL_NODEREQ(Signal* signal) { diff --git a/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.cpp b/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.cpp index e5efc077fb1f..1c6314f16540 100644 --- a/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.cpp +++ b/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.cpp @@ -30,7 +30,11 @@ DbspjProxy::DbspjProxy(Block_context& ctx) : DbgdmProxy(DBSPJ, ctx) -{} +{ + // GSN_SET_DOMAIN_ID_REQ + addRecSignal(GSN_SET_DOMAIN_ID_REQ, &DbspjProxy::execSET_DOMAIN_ID_REQ); + addRecSignal(GSN_SET_DOMAIN_ID_CONF, &DbspjProxy::execSET_DOMAIN_ID_CONF); +} DbspjProxy::~DbspjProxy() { @@ -42,5 +46,68 @@ DbspjProxy::newWorker(Uint32 instanceNo) return new Dbspj(m_ctx, instanceNo); } +// GSN_SET_DOMAIN_ID_REQ + +void +DbspjProxy::execSET_DOMAIN_ID_REQ(Signal* signal) +{ + jam(); + Ss_SET_DOMAIN_ID_REQ& ss = ssSeize(1); + memcpy(&ss.m_req, + signal->getDataPtr(), + sizeof(SetDomainIdReq)); + sendREQ(signal, ss); +} + +void +DbspjProxy::sendSET_DOMAIN_ID_REQ(Signal* signal, Uint32 ssId, SectionHandle*) +{ + SetDomainIdReq* const req = (SetDomainIdReq*)signal->getDataPtrSend(); + jam(); + Ss_SET_DOMAIN_ID_REQ& ss = ssFind(ssId); + req->senderId = ssId; + req->senderRef = reference(); + req->changeNodeId = ss.m_req.changeNodeId; + req->locationDomainId = ss.m_req.locationDomainId; + sendSignal(workerRef(ss.m_worker), + GSN_SET_DOMAIN_ID_REQ, + signal, + SetDomainIdReq::SignalLength, + JBB); +} + +void +DbspjProxy::execSET_DOMAIN_ID_CONF(Signal* signal) +{ + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtr(); + jam(); + Uint32 ssId = conf->senderId; + Ss_SET_DOMAIN_ID_REQ& ss = ssFind(ssId); + recvCONF(signal, ss); +} + +void +DbspjProxy::sendSET_DOMAIN_ID_CONF(Signal* signal, Uint32 ssId) +{ + jam(); + Ss_SET_DOMAIN_ID_REQ& ss = ssFind(ssId); + + if (!lastReply(ss)) + { + jam(); + return; + } + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtrSend(); + conf->senderId = ss.m_req.senderId; + conf->senderRef = reference(); + conf->changeNodeId = ss.m_req.changeNodeId; + conf->locationDomainId = ss.m_req.locationDomainId; + sendSignal(QMGR_REF, + GSN_SET_DOMAIN_ID_CONF, + signal, + SetDomainIdConf::SignalLength, + JBB); + ssRelease(ssId); +} BLOCK_FUNCTIONS(DbspjProxy) diff --git a/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.hpp b/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.hpp index 682d89dc9e0a..b3ad04f9897d 100644 --- a/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.hpp +++ b/storage/ndb/src/kernel/blocks/dbspj/DbspjProxy.hpp @@ -24,6 +24,7 @@ #define NDB_DBSPJ_PROXY_HPP #include "../dbgdm/DbgdmProxy.hpp" +#include #define JAM_FILE_ID 480 @@ -37,9 +38,26 @@ class DbspjProxy : public DbgdmProxy { protected: SimulatedBlock* newWorker(Uint32 instanceNo) override; + /** + * SET_DOMAIN_ID_REQ + */ + struct Ss_SET_DOMAIN_ID_REQ : SsParallel { + SetDomainIdReq m_req; + Ss_SET_DOMAIN_ID_REQ() { + m_sendREQ = (SsFUNCREQ)&DbspjProxy::sendSET_DOMAIN_ID_REQ; + m_sendCONF = (SsFUNCREP)&DbspjProxy::sendSET_DOMAIN_ID_CONF; + } + enum { poolSize = 1 }; + static SsPool& pool(LocalProxy* proxy) { + return ((DbspjProxy*)proxy)->c_ss_SET_DOMAIN_ID_REQ; + } + }; + SsPool c_ss_SET_DOMAIN_ID_REQ; + void execSET_DOMAIN_ID_REQ(Signal*); + void sendSET_DOMAIN_ID_REQ(Signal*, Uint32 ssId, SectionHandle*); + void execSET_DOMAIN_ID_CONF(Signal*); + void sendSET_DOMAIN_ID_CONF(Signal*, Uint32 ssId); }; - #undef JAM_FILE_ID - #endif diff --git a/storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp b/storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp index 0f029ff6de4c..37b036211411 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp +++ b/storage/ndb/src/kernel/blocks/dbtc/Dbtc.hpp @@ -2098,6 +2098,7 @@ class Dbtc void execKEYINFO20_R(Signal* signal); void execROUTE_ORD(Signal* signal); // Received signals + void execSET_DOMAIN_ID_REQ(Signal* signal); void execDUMP_STATE_ORD(Signal* signal); void execDBINFO_SCANREQ(Signal* signal); void execSEND_PACKED(Signal* signal); diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp index 158a0d554d81..1541620a9a8b 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcInit.cpp @@ -585,6 +585,7 @@ Dbtc::Dbtc(Block_context& ctx, Uint32 instanceNo): // Received signals + addRecSignal(GSN_SET_DOMAIN_ID_REQ, &Dbtc::execSET_DOMAIN_ID_REQ); addRecSignal(GSN_DUMP_STATE_ORD, &Dbtc::execDUMP_STATE_ORD); addRecSignal(GSN_DBINFO_SCANREQ, &Dbtc::execDBINFO_SCANREQ); addRecSignal(GSN_SEND_PACKED, &Dbtc::execSEND_PACKED, true); diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp index 295f40ad3f61..fbc79354054e 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp @@ -74,6 +74,7 @@ #include #include #include +#include #include #include @@ -1818,13 +1819,43 @@ void Dbtc::execREAD_NODESCONF(Signal* signal) ndb_mgm_destroy_iterator(p_iter); { HostRecordPtr Town_hostptr; - Town_hostptr.i = cownNodeid; + Town_hostptr.i = getOwnNodeId(); ptrCheckGuard(Town_hostptr, chostFilesize, hostRecord); m_my_location_domain_id = Town_hostptr.p->m_location_domain_id; } ndbsttorry010Lab(signal); }//Dbtc::execREAD_NODESCONF() +void Dbtc::execSET_DOMAIN_ID_REQ(Signal *signal) { + jamEntry(); + const SetDomainIdReq* const req = + (const SetDomainIdReq *)signal->getDataPtr(); + Uint32 senderId = req->senderId; + BlockReference senderRef = req->senderRef; + NodeId changeNodeId = req->changeNodeId; + Uint32 locationDomainId = req->locationDomainId; + + /* Change the location domain id of the changeNodeId */ + hostptr.i = changeNodeId; + ptrCheckGuard(hostptr, chostFilesize, hostRecord); + hostptr.p->m_location_domain_id = locationDomainId; + if (changeNodeId == getOwnNodeId()) { + m_my_location_domain_id = locationDomainId; + } + + /* Send response back, this should never fail, so always CONF */ + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtrSend(); + conf->senderId = senderId; + conf->senderRef = reference(); + conf->changeNodeId = changeNodeId; + conf->locationDomainId = locationDomainId; + sendSignal(senderRef, + GSN_SET_DOMAIN_ID_CONF, + signal, + SetDomainIdConf::SignalLength, + JBB); +} + /*****************************************************************************/ /* A P I _ F A I L R E Q */ // An API node has failed for some reason. We need to disconnect all API diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.cpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.cpp index 35500e4e6eb0..bab50c5bc337 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.cpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.cpp @@ -36,11 +36,15 @@ DbtcProxy::DbtcProxy(Block_context& ctx) : // GSN_TCSEIZEREQ addRecSignal(GSN_TCSEIZEREQ, &DbtcProxy::execTCSEIZEREQ); + // GSN_SET_DOMAIN_ID_REQ + addRecSignal(GSN_SET_DOMAIN_ID_REQ, &DbtcProxy::execSET_DOMAIN_ID_REQ); + addRecSignal(GSN_SET_DOMAIN_ID_CONF, &DbtcProxy::execSET_DOMAIN_ID_CONF); + // GSN_TCGETOPSIZEREQ addRecSignal(GSN_TCGETOPSIZEREQ, &DbtcProxy::execTCGETOPSIZEREQ); addRecSignal(GSN_TCGETOPSIZECONF, &DbtcProxy::execTCGETOPSIZECONF); - // GSN_TCGETOPSIZEREQ + // GSN_TC_CLOPSIZEREQ addRecSignal(GSN_TC_CLOPSIZEREQ, &DbtcProxy::execTC_CLOPSIZEREQ); addRecSignal(GSN_TC_CLOPSIZECONF, &DbtcProxy::execTC_CLOPSIZECONF); @@ -182,6 +186,71 @@ DbtcProxy::execTCSEIZEREQ(Signal* signal) } } +// GSN_SET_DOMAIN_ID_REQ + +void +DbtcProxy::execSET_DOMAIN_ID_REQ(Signal* signal) +{ + jam(); + Ss_SET_DOMAIN_ID_REQ& ss = ssSeize(1); + memcpy(&ss.m_req, + signal->getDataPtr(), + sizeof(SetDomainIdReq)); + sendREQ(signal, ss); +} + +void +DbtcProxy::sendSET_DOMAIN_ID_REQ(Signal* signal, Uint32 ssId, SectionHandle*) +{ + SetDomainIdReq* const req = (SetDomainIdReq*)signal->getDataPtrSend(); + jam(); + Ss_SET_DOMAIN_ID_REQ& ss = ssFind(ssId); + + req->senderId = ssId; + req->senderRef = reference(); + req->changeNodeId = ss.m_req.changeNodeId; + req->locationDomainId = ss.m_req.locationDomainId; + sendSignal(workerRef(ss.m_worker), + GSN_SET_DOMAIN_ID_REQ, + signal, + SetDomainIdReq::SignalLength, + JBB); +} + +void +DbtcProxy::execSET_DOMAIN_ID_CONF(Signal* signal) +{ + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtr(); + jam(); + Uint32 ssId = conf->senderId; + Ss_SET_DOMAIN_ID_REQ& ss = ssFind(ssId); + recvCONF(signal, ss); +} + +void +DbtcProxy::sendSET_DOMAIN_ID_CONF(Signal* signal, Uint32 ssId) +{ + jam(); + Ss_SET_DOMAIN_ID_REQ& ss = ssFind(ssId); + + if (!lastReply(ss)) + { + jam(); + return; + } + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtrSend(); + conf->senderId = ss.m_req.senderId; + conf->senderRef = reference(); + conf->changeNodeId = ss.m_req.changeNodeId; + conf->locationDomainId = ss.m_req.locationDomainId; + sendSignal(QMGR_REF, + GSN_SET_DOMAIN_ID_CONF, + signal, + SetDomainIdConf::SignalLength, + JBB); + ssRelease(ssId); +} + // GSN_TCGETOPSIZEREQ void diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.hpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.hpp index a57c327e60b4..095742fce1af 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.hpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcProxy.hpp @@ -26,7 +26,7 @@ #define NDB_DBTC_PROXY_HPP #include "../dbgdm/DbgdmProxy.hpp" - +#include #include #include @@ -58,6 +58,26 @@ class DbtcProxy : public DbgdmProxy { Uint32 m_tc_seize_req_instance; // round robin void execTCSEIZEREQ(Signal* signal); + /** + * SET_DOMAIN_ID_REQ + */ + struct Ss_SET_DOMAIN_ID_REQ : SsParallel { + SetDomainIdReq m_req; + Ss_SET_DOMAIN_ID_REQ() { + m_sendREQ = (SsFUNCREQ)&DbtcProxy::sendSET_DOMAIN_ID_REQ; + m_sendCONF = (SsFUNCREP)&DbtcProxy::sendSET_DOMAIN_ID_CONF; + } + enum { poolSize = 1 }; + static SsPool& pool(LocalProxy* proxy) { + return ((DbtcProxy*)proxy)->c_ss_SET_DOMAIN_ID_REQ; + } + }; + SsPool c_ss_SET_DOMAIN_ID_REQ; + void execSET_DOMAIN_ID_REQ(Signal*); + void sendSET_DOMAIN_ID_REQ(Signal*, Uint32 ssId, SectionHandle*); + void execSET_DOMAIN_ID_CONF(Signal*); + void sendSET_DOMAIN_ID_CONF(Signal*, Uint32 ssId); + /** * TCGETOPSIZEREQ */ diff --git a/storage/ndb/src/kernel/blocks/qmgr/Qmgr.hpp b/storage/ndb/src/kernel/blocks/qmgr/Qmgr.hpp index 99448176789e..261580fecd40 100644 --- a/storage/ndb/src/kernel/blocks/qmgr/Qmgr.hpp +++ b/storage/ndb/src/kernel/blocks/qmgr/Qmgr.hpp @@ -95,6 +95,7 @@ #define ZWRONG_STATE_ERROR 1117 #define ZNODE_ZERO_ERROR 1118 #define ZWRONG_NODE_ERROR 1119 +#define ZSET_DOMAIN_ID_BUSY_ERROR 1120 #endif @@ -544,6 +545,14 @@ class Qmgr : public SimulatedBlock { void execDEACTIVATE_CONF(Signal*); void execDEACTIVATE_REF(Signal*); + void execSET_DOMAIN_ID_REQ(Signal*); + void execSET_DOMAIN_ID_CONF(Signal*); + void execSET_DOMAIN_ID_REF(Signal*); + + void sendSET_DOMAIN_ID_REQ(Signal*, Uint32, Uint32, NodeId, Uint32); + void sendSET_DOMAIN_ID_CONF(Signal*, Uint32, Uint32, NodeId, Uint32); + void sendSET_DOMAIN_ID_REF(Signal*, Uint32, Uint32, NodeId, Uint32, Uint32); + void execSET_HOSTNAME_REQ(Signal*); void execSET_HOSTNAME_CONF(Signal*); void execSET_HOSTNAME_REF(Signal*); @@ -562,18 +571,21 @@ class Qmgr : public SimulatedBlock { void handle_activate_failed_node(Signal*, NodeRecPtr); bool send_activate_node(NodeRecPtr nodePtr); + bool send_location_domain_id_node(NodeRecPtr nodePtr); void handle_activate_receive(Uint32, Uint32); void check_activate_finished(Signal*); void check_deactivate_finished(Signal*); void check_set_hostname_finished(Signal*); + void check_set_location_domain_id_finished(Signal*); enum ActivateState { IDLE = 0, HANDLE_ACTIVATE = 1, HANDLE_DEACTIVATE = 2, - HANDLE_SET_HOSTNAME = 3 + HANDLE_SET_HOSTNAME = 3, + HANDLE_SET_DOMAIN_ID = 4 }; ActivateState m_activate_state; @@ -593,11 +605,16 @@ class Qmgr : public SimulatedBlock { */ NodeId m_activate_node_id; + Uint32 m_activate_sender_id; + Uint32 m_activate_location_domain_id; + /** * Did we fully succeed with the operation. */ bool m_activate_success; + Uint32 m_activate_error_code; + // Arbitration signals void execARBIT_CFG(Signal* signal); void execARBIT_PREPREQ(Signal* signal); diff --git a/storage/ndb/src/kernel/blocks/qmgr/QmgrInit.cpp b/storage/ndb/src/kernel/blocks/qmgr/QmgrInit.cpp index bcc499411e4a..bbb100673964 100644 --- a/storage/ndb/src/kernel/blocks/qmgr/QmgrInit.cpp +++ b/storage/ndb/src/kernel/blocks/qmgr/QmgrInit.cpp @@ -269,6 +269,10 @@ Qmgr::Qmgr(Block_context& ctx) addRecSignal(GSN_PROCESSINFO_REP, &Qmgr::execPROCESSINFO_REP); addRecSignal(GSN_SYNC_THREAD_VIA_CONF, &Qmgr::execSYNC_THREAD_VIA_CONF); + addRecSignal(GSN_SET_DOMAIN_ID_REQ, &Qmgr::execSET_DOMAIN_ID_REQ); + addRecSignal(GSN_SET_DOMAIN_ID_CONF, &Qmgr::execSET_DOMAIN_ID_CONF); + addRecSignal(GSN_SET_DOMAIN_ID_REF, &Qmgr::execSET_DOMAIN_ID_REF); + addRecSignal(GSN_ACTIVATE_REQ, &Qmgr::execACTIVATE_REQ); addRecSignal(GSN_ACTIVATE_CONF, &Qmgr::execACTIVATE_CONF); addRecSignal(GSN_ACTIVATE_REF, &Qmgr::execACTIVATE_REF); diff --git a/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp b/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp index 7aa96c00105c..0f92f845c1e1 100644 --- a/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp +++ b/storage/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -3811,6 +3812,223 @@ void Qmgr::apiHbHandlingLab(Signal* signal, NDB_TICKS now) return; }//Qmgr::apiHbHandlingLab() +void Qmgr::execSET_DOMAIN_ID_REQ(Signal *signal) +{ + jamEntry(); + const SetDomainIdReq* const req = + (const SetDomainIdReq *)signal->getDataPtr(); + Uint32 senderId = req->senderId; + BlockReference senderRef = req->senderRef; + NodeId changeNodeId = req->changeNodeId; + Uint32 locationDomainId = req->locationDomainId; + + ndbrequire(signal->getNoOfSections() == 0); + DEB_ACTIVATE(("SET_DOMAIN_ID_REQ from %x node: %u, new loc domain id: %u", + senderRef, + changeNodeId, + locationDomainId)); + + if (changeNodeId > MAX_NODES || + changeNodeId == 0 || + m_activate_state != ActivateState::IDLE) + { + g_eventLogger->info("SET_DOMAIN_ID_REQ failed, state: %u on node: %u", + m_activate_state, + changeNodeId); + sendSET_DOMAIN_ID_REF(signal, + senderId, + senderRef, + changeNodeId, + locationDomainId, + ZSET_DOMAIN_ID_BUSY_ERROR); + return; + } + g_eventLogger->info("SET LocationDomainId of Node %u to %u", + changeNodeId, + locationDomainId); + + m_activate_node_id = changeNodeId; + m_activate_ref = senderRef; + m_activate_state = ActivateState::HANDLE_SET_DOMAIN_ID; + m_activate_success = true; + m_activate_error_code = 0; + m_activate_outstanding = 0; + m_activate_sender_id = senderId; + m_activate_location_domain_id = locationDomainId; + + /* First contact DBTC, next DBSPJ and finally API nodes */ + sendSET_DOMAIN_ID_REQ(signal, + senderId, + DBTC_REF, + changeNodeId, + locationDomainId); +} + +void Qmgr::execSET_DOMAIN_ID_CONF(Signal *signal) +{ + jamEntry(); + const SetDomainIdConf* const conf = + (const SetDomainIdConf *)signal->getDataPtr(); + Uint32 senderId = conf->senderId; + Uint32 senderRef = conf->senderRef; + NodeId changeNodeId = conf->changeNodeId; + Uint32 locationDomainId = conf->locationDomainId; + ndbrequire(m_activate_state == ActivateState::HANDLE_SET_DOMAIN_ID); + Uint32 block = refToMain(senderRef); + if (block == DBTC) { + DEB_ACTIVATE(("SET_DOMAIN_ID_CONF from DBTC, node: %u", + changeNodeId)); + sendSET_DOMAIN_ID_REQ(signal, + senderId, + DBSPJ_REF, + changeNodeId, + locationDomainId); + return; + } else if (block == DBSPJ) { + DEB_ACTIVATE(("SET_DOMAIN_ID_CONF from DBSPJ, node: %u", + changeNodeId)); + ndbrequire(m_activate_outstanding == 0); + for (NodeId nodeId = 1; nodeId < MAX_NODES; nodeId++) + { + NodeRecPtr nodePtr; + nodePtr.i = Uint32(nodeId); + ptrAss(nodePtr, nodeRec); + if (send_location_domain_id_node(nodePtr)) + { + jam(); + jamLine(nodePtr.i); + Uint32 ref = numberToRef(API_CLUSTERMGR, nodePtr.i); + sendSET_DOMAIN_ID_REQ(signal, + m_activate_sender_id, + ref, + changeNodeId, + locationDomainId); + m_activate_outstanding++; + nodePtr.p->m_activate_ongoing = true; + } + } + DEB_ACTIVATE(("Sent SET_DOMAIN_ID_REQ to %u nodes", + m_activate_outstanding)); + check_set_location_domain_id_finished(signal); + return; + } + DEB_ACTIVATE(("SET_DOMAIN_ID_CONF from %u node: %u", + senderId, + changeNodeId)); + handle_activate_receive(senderId, changeNodeId); + check_set_location_domain_id_finished(signal); +} + +void Qmgr::execSET_DOMAIN_ID_REF(Signal *signal) +{ + jamEntry(); + NodeRecPtr nodePtr; + const SetDomainIdRef* const ref = + (const SetDomainIdRef *)signal->getDataPtr(); + Uint32 senderId = ref->senderId; + NodeId changeNodeId = ref->changeNodeId; + Uint32 error_code = ref->errorCode; + g_eventLogger->info("SET_DOMAIN_ID_REF from %u node: %u, error: %u", + senderId, + changeNodeId, + error_code); + ndbrequire(m_activate_state == ActivateState::HANDLE_SET_HOSTNAME); + handle_activate_receive(senderId, changeNodeId); + m_activate_success = false; + m_activate_error_code = error_code; + check_set_location_domain_id_finished(signal); +} + +void Qmgr::check_set_location_domain_id_finished(Signal *signal) +{ + if (m_activate_outstanding == 0) + { + jam(); + if (m_activate_success) + { + jam(); + sendSET_DOMAIN_ID_CONF(signal, + m_activate_sender_id, + m_activate_ref, + m_activate_node_id, + m_activate_location_domain_id); + } + else + { + jam(); + sendSET_DOMAIN_ID_REF(signal, + m_activate_sender_id, + m_activate_ref, + m_activate_node_id, + m_activate_location_domain_id, + m_activate_error_code); + } + m_activate_state = ActivateState::IDLE; + m_activate_node_id = 0; + m_activate_ref = 0; + m_activate_success = false; + m_activate_error_code = 0; + m_activate_sender_id = 0; + m_activate_location_domain_id = 0; + } +} + +void Qmgr::sendSET_DOMAIN_ID_REQ(Signal *signal, + Uint32 senderId, + Uint32 senderRef, + NodeId changeNodeId, + Uint32 locationDomainId) +{ + SetDomainIdReq* const req = (SetDomainIdReq*)signal->getDataPtrSend(); + req->senderId = senderId; + req->senderRef = reference(); + req->changeNodeId = changeNodeId, + req->locationDomainId = locationDomainId; + sendSignal(senderRef, + GSN_SET_DOMAIN_ID_REQ, + signal, + SetDomainIdReq::SignalLength, + JBB); +} + +void Qmgr::sendSET_DOMAIN_ID_CONF(Signal *signal, + Uint32 senderId, + Uint32 senderRef, + NodeId nodeId, + Uint32 locationDomainId) +{ + SetDomainIdConf* const conf = (SetDomainIdConf*)signal->getDataPtrSend(); + conf->senderId = senderId; + conf->senderRef = reference(); + conf->changeNodeId = Uint32(nodeId); + conf->locationDomainId = locationDomainId; + sendSignal(senderRef, + GSN_SET_DOMAIN_ID_CONF, + signal, + SetDomainIdConf::SignalLength, + JBB); +} + +void Qmgr::sendSET_DOMAIN_ID_REF(Signal *signal, + Uint32 senderId, + Uint32 senderRef, + NodeId changeNodeId, + Uint32 locationDomainId, + Uint32 errorCode) +{ + SetDomainIdRef* const ref = (SetDomainIdRef*)signal->getDataPtrSend(); + ref->senderId = senderId; + ref->senderRef = reference(); + ref->changeNodeId = changeNodeId; + ref->locationDomainId = locationDomainId; + ref->errorCode = errorCode; + sendSignal(senderRef, + GSN_SET_DOMAIN_ID_REF, + signal, + SetDomainIdRef::SignalLength, + JBB); +} + void Qmgr::execACTIVATE_REQ(Signal *signal) { jamEntry(); @@ -3971,6 +4189,11 @@ void Qmgr::handle_activate_failed_node(Signal *signal, NodeRecPtr nodePtr) check_set_hostname_finished(signal); break; } + case ActivateState::HANDLE_SET_DOMAIN_ID: + { + check_set_location_domain_id_finished(signal); + break; + } default: { ndbabort(); @@ -3992,6 +4215,20 @@ bool Qmgr::send_activate_node(NodeRecPtr nodePtr) return false; } +bool Qmgr::send_location_domain_id_node(NodeRecPtr nodePtr) +{ + bool data_node = (getNodeInfo(nodePtr.i).getType() == NodeInfo::DB); + bool supported = + ndbd_support_set_location_domain_id(getNodeInfo(nodePtr.i).m_version); + bool api_active = (nodePtr.p->phase == ZAPI_ACTIVE); + bool normal_fail_state = (nodePtr.p->failState == NORMAL); + if (!data_node && supported && api_active && normal_fail_state) + { + return true; + } + return false; +} + void Qmgr::handle_activate_receive(Uint32 nodeId, Uint32 handleNodeId) { NodeRecPtr nodePtr; @@ -4345,7 +4582,7 @@ void Qmgr::sendDEACTIVATE_REF(Signal *signal, sendSignal(senderRef, GSN_DEACTIVATE_REF, signal, - ActivateRef::SignalLength, + DeactivateRef::SignalLength, JBB); } diff --git a/storage/ndb/src/kernel/vm/Emulator.hpp b/storage/ndb/src/kernel/vm/Emulator.hpp index eb573b425719..81028a6b73b9 100644 --- a/storage/ndb/src/kernel/vm/Emulator.hpp +++ b/storage/ndb/src/kernel/vm/Emulator.hpp @@ -682,6 +682,7 @@ static constexpr const char* const jamFileNames[] = "TrpKeepAlive.cpp", // 547 "CommitReq.hpp", // 548 "CommitReq.cpp", // 549 + "SetDomainId.hpp", // 550 // END jamFileNames (This marker is used by ./test_jamFileNames.sh) }; diff --git a/storage/ndb/src/mgmapi/mgmapi.cpp b/storage/ndb/src/mgmapi/mgmapi.cpp index db3aa2c47607..482ed83f5145 100644 --- a/storage/ndb/src/mgmapi/mgmapi.cpp +++ b/storage/ndb/src/mgmapi/mgmapi.cpp @@ -2896,6 +2896,47 @@ ndb_mgm_get_nodeid(NdbMgmHandle handle, DBUG_RETURN(result); } +extern "C" +int +ndb_mgm_set_domain_id(NdbMgmHandle handle, + const int nodeId, + const int new_location_domain_id) +{ + DBUG_ENTER("ndb_mgm_set_domain_id"); + CHECK_HANDLE(handle, -1); + SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_set_domain_id"); + const ParserRow set_domain_id_reply[] = { + MGM_CMD("set_location_domain_id reply", NULL, ""), + MGM_ARG("result", String, Mandatory, "Error message"), + MGM_END() + }; + int activated = -1; + CHECK_CONNECTED(handle, -1); + Properties args; + args.put("node", nodeId); + args.put("new_location_domain_id", new_location_domain_id); + const Properties *reply; + reply = ndb_mgm_call(handle, + set_domain_id_reply, + "set_location_domain_id", + &args); + if (reply != NULL) + { + BaseString result; + reply->get("result", result); + if (strcmp(result.c_str(), "Ok") == 0) + { + activated = 0; + } + else + { + SET_ERROR(handle, EINVAL, result.c_str()); + } + } + delete reply; + DBUG_RETURN(activated); +} + extern "C" int ndb_mgm_set_hostname(NdbMgmHandle handle, diff --git a/storage/ndb/src/mgmclient/CommandInterpreter.cpp b/storage/ndb/src/mgmclient/CommandInterpreter.cpp index 475796973240..9385fede8eb9 100644 --- a/storage/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/storage/ndb/src/mgmclient/CommandInterpreter.cpp @@ -149,6 +149,7 @@ class CommandInterpreter { bool interactive); public: + int executeSetDomain(int processId, const char* parameters, bool all); int executeHostname(int processId, const char* parameters, bool all); int executeActivate(int processId, const char* parameters, bool all); int executeDeactivate(int processId, const char* parameters, bool all); @@ -308,6 +309,7 @@ static const char* helpText = "CLUSTERLOG OFF [] ... Disable Cluster logging\n" "CLUSTERLOG TOGGLE [] ... Toggle severity filter on/off\n" "CLUSTERLOG INFO Print cluster log information\n" +" LOCATION_DOMAIN_ID [] Change location domain id of a node\n" " HOSTNAME [] Change hostname of a deactivated node\n" " ACTIVATE Activate a node previously deactivated\n" " DEACTIVATE Deactivate a node (and stop it)\n" @@ -476,11 +478,20 @@ static const char* helpTextHostname = "---------------------------------------------------------------------------\n" " RonDB -- Management Client -- Help for HOSTNAME command\n" "---------------------------------------------------------------------------\n" -"HOSTNAME Change hostname of a currently deactive node\n\n" +"HOSTNAME Change hostname of a currently deactivated node\n\n" " HOSTNAME [] Set the new hostname of the node identified \n" " by .\n\n" ; +static const char* helpTextSetDomainId = +"---------------------------------------------------------------------------\n" +" RonDB -- Management Client -- Help for LOCATION_DOMAIN_ID command\n" +"---------------------------------------------------------------------------\n" +"HOSTNAME Change location domain id of a node\n\n" +" LOCATION_DOMAIN_ID [] Set the new location domain id of \n" +" the node identified by \n\n" +; + static const char* helpTextActivate = "---------------------------------------------------------------------------\n" " RonDB -- Management Client -- Help for ACTIVATE command\n" @@ -748,6 +759,7 @@ struct st_cmd_help { {"CLUSTERLOG OFF", helpTextClusterlogOff, NULL}, {"CLUSTERLOG TOGGLE", helpTextClusterlogToggle, NULL}, {"CLUSTERLOG INFO", helpTextClusterlogInfo, NULL}, + {"LOCATION_DOMAIN_ID", helpTextSetDomainId, NULL}, {"HOSTNAME", helpTextHostname, NULL}, {"ACTIVATE", helpTextActivate, NULL}, {"DEACTIVATE", helpTextDeactivate, NULL}, @@ -1585,6 +1597,7 @@ static const CommandInterpreter::CommandFunctionPair commands[] = { ,{ "HOSTNAME", &CommandInterpreter::executeHostname } ,{ "ACTIVATE", &CommandInterpreter::executeActivate } ,{ "DEACTIVATE", &CommandInterpreter::executeDeactivate } + ,{ "LOCATION_DOMAIN_ID", &CommandInterpreter::executeSetDomain } }; @@ -2575,6 +2588,105 @@ CommandInterpreter::check_before_config_change(int processId, return true; } +int +CommandInterpreter::executeSetDomain(int processId, + const char* parameters, + bool all) +{ + if (all) + { + ndbout << "ALL LOCATION_DOMAIN_ID command not allowed" << endl; + return -1; + } + bool is_node_up; + ndb_mgm_node_type node_type; + if (!check_before_config_change(processId, is_node_up, node_type)) + { + return -1; + } + (void)is_node_up; + (void)node_type; + + Vector command_list; + if (!parameters) + { + ndbout_c("Need a location domain id parameter to this command"); + ndbout_c(" LOCATION_DOMAIN_ID location_domain_id"); + return -1; + } + split_args(parameters, command_list); + if (command_list.size() != 1) + { + ndbout_c("Command have too many parameters"); + ndbout_c(" LOCATION_DOMAIN_ID location_domain_id"); + return -1; + } + + ndb_mgm_configuration * conf = ndb_mgm_get_configuration(m_mgmsrv,0); + if (conf == 0) + { + ndbout_c("Could not get configuration"); + printError(); + return -1; + } + + ConfigValues::Iterator iter(conf->m_config_values); + bool ret = get_node_section(iter, processId, 0); + if (!ret) + { + printError(); + ndbout_c("Failed to get configuration of node %d", processId); + ndb_mgm_destroy_configuration(conf); + return -1; + } + const char *new_location_domain_id_str = command_list[0].c_str(); + Uint32 str_len = strlen(new_location_domain_id_str); + const char *memory_end = new_location_domain_id_str + str_len; + char *end_ptr = nullptr; + Int64 val = strtoll(new_location_domain_id_str, &end_ptr, 10); + if (unlikely(errno == ERANGE || + end_ptr != memory_end || + val < 0 || + val > MAX_INT)) { + iter.closeSection(); + ndbout_c("Location domain id must be an unsigned no larger than MAX_INT"); + ndb_mgm_destroy_configuration(conf); + return -1; + } + Uint32 new_location_domain_id = Uint32(val); + iter.set(CFG_LOCATION_DOMAIN_ID, new_location_domain_id); + iter.closeSection(); + int ret_code = ndb_mgm_set_configuration(m_mgmsrv, conf); + if (ret_code != 0) + { + ndbout_c("Failed to change configuration"); + printError(); + ndb_mgm_destroy_configuration(conf); + return -1; + } + ndbout_c("Configuration changed to reflect new location domain id of node %d", + processId); + ndbout_c("Now changing location domain id in the cluster"); + + ret_code = ndb_mgm_set_domain_id(m_mgmsrv, + processId, + new_location_domain_id); + if (ret_code < 0) + { + ndbout_c("Failed to set location domain id for node %d in the cluster", + processId); + printError(); + return -1; + } + else + { + ndbout_c("Node %d now has location domain id %u in the cluster", + processId, + new_location_domain_id); + } + return 0; +} + int CommandInterpreter::executeHostname(int processId, const char* parameters, diff --git a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp index 5432ef79b78b..8153da461b2f 100644 --- a/storage/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/storage/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include "portlib/ndb_sockaddr.h" @@ -424,7 +425,7 @@ MgmtSrvr::start_transporter(const Config* config) { DBUG_ENTER("MgmtSrvr::start_transporter"); - theFacade= new TransporterFacade(0); + theFacade= new TransporterFacade(0, nullptr); if (theFacade == 0) { g_eventLogger->error("Could not create TransporterFacade."); @@ -1378,6 +1379,121 @@ int MgmtSrvr::sendStopMgmd(NodeId nodeId, return 0; } +int +MgmtSrvr::set_location_domain_id_request( + int changeNodeId, + const int new_location_domain_id) +{ + DBUG_ENTER("MgmtSrvr::set_location_domain_id_request"); + DBUG_PRINT("enter", ("Set location domain id: %u for node %d", + new_location_domain_id, changeNodeId)); + + SignalSender ss(theFacade); + SimpleSignal ssig; + ss.lock(); // lock will be released on exit + SetDomainIdReq* const setDomainIdReq = CAST_PTR(SetDomainIdReq, + ssig.getDataPtrSend()); + ssig.set(ss, + TestOrd::TraceAPI, + CMVMI, + GSN_SET_DOMAIN_ID_REQ, + SetDomainIdReq::SignalLength); + setDomainIdReq->senderId = 0; + setDomainIdReq->senderRef = ss.getOwnRef(); + setDomainIdReq->changeNodeId = Uint32(changeNodeId); + setDomainIdReq->locationDomainId = Uint32(new_location_domain_id); + + if (!check_node_support_set_location_domain_id()) + { + DBUG_RETURN(FAILED_SET_DOMAIN_ID_REQUEST); + } + // send the signals + int failed = 0; + NodeBitmask nodes; + { + NodeId nodeId = 0; + while(getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_NDB)) + { + if (okToSendTo(nodeId, true) == 0) + { + SendStatus result = ss.sendSignal(nodeId, &ssig); + if (result == SEND_OK) + nodes.set(nodeId); + else + failed++; + } + } + } + if (nodes.isclear() && failed > 0) + { + DBUG_RETURN(SEND_OR_RECEIVE_FAILED); + } + int error_code = 0; + while (!nodes.isclear()) + { + SimpleSignal *signal = ss.waitFor(); + int gsn = signal->readSignalNumber(); + switch (gsn) { + case GSN_SET_DOMAIN_ID_REF: + { + const SetDomainIdRef* setDomainIdRef = + CAST_CONSTPTR(SetDomainIdRef, signal->getDataPtr()); + assert(setDomainIdRef->changeNodeId == Uint32(changeNodeId)); + assert(setDomainIdRef->senderId <= nodes.max_size()); + NodeId senderNodeId = refToNode(setDomainIdRef->senderRef); + nodes.clear(senderNodeId); + error_code = FAILED_SET_DOMAIN_ID_REQUEST; + break; + } + case GSN_SET_DOMAIN_ID_CONF: + { + const SetDomainIdConf* setDomainIdConf = + CAST_CONSTPTR(SetDomainIdConf, signal->getDataPtr()); + assert(setDomainIdConf->changeNodeId == Uint32(changeNodeId)); + assert(setDomainIdConf->senderId <= nodes.max_size()); + NodeId senderNodeId = refToNode(setDomainIdConf->senderRef); + nodes.clear(senderNodeId); + break; + } + case GSN_NF_COMPLETEREP: + { + const NFCompleteRep * rep = CAST_CONSTPTR(NFCompleteRep, + signal->getDataPtr()); + if (rep->failedNodeId <= nodes.max_size()) + nodes.clear(rep->failedNodeId); // clear the failed node + break; + } + case GSN_NODE_FAILREP: + { + const NodeFailRep * rep = CAST_CONSTPTR(NodeFailRep, + signal->getDataPtr()); + Uint32 len = NodeFailRep::getNodeMaskLength(signal->getLength()); + assert(len == NodeBitmask::Size || // only full length in ndbapi + len == 0); + NodeBitmask mask; + if (signal->header.m_noOfSections >= 1) + { + mask.assign(signal->ptr[0].sz, signal->ptr[0].p); + } + else + { + mask.assign(len, rep->theAllNodes); + } + nodes.bitANDC(mask); + break; + } + case GSN_API_REGCONF: + case GSN_TAKE_OVERTCCONF: + case GSN_CONNECT_REP: + continue; + default: + report_unknown_signal(signal); + DBUG_RETURN(SEND_OR_RECEIVE_FAILED); + } + } + DBUG_RETURN(error_code); +} + int MgmtSrvr::set_hostname_request(int nodeId, const char *new_hostname) { @@ -1438,6 +1554,7 @@ MgmtSrvr::set_hostname_request(int nodeId, const char *new_hostname) { DBUG_RETURN(SEND_OR_RECEIVE_FAILED); } + int error_code = 0; while (!nodes.isclear()) { SimpleSignal *signal = ss.waitFor(); @@ -1445,7 +1562,12 @@ MgmtSrvr::set_hostname_request(int nodeId, const char *new_hostname) switch (gsn) { case GSN_SET_HOSTNAME_REF: { - DBUG_RETURN(FAILED_SET_HOSTNAME_REQUEST); + const SetHostnameRef* setHostnameRef = CAST_CONSTPTR(SetHostnameRef, + signal->getDataPtr()); + assert(setHostnameRef->changeNodeId == Uint32(nodeId)); + assert(setHostnameRef->senderNodeId <= nodes.max_size()); + nodes.clear(setHostnameRef->senderNodeId); + error_code = FAILED_SET_HOSTNAME_REQUEST; break; } case GSN_SET_HOSTNAME_CONF: @@ -1493,7 +1615,7 @@ MgmtSrvr::set_hostname_request(int nodeId, const char *new_hostname) DBUG_RETURN(SEND_OR_RECEIVE_FAILED); } } - DBUG_RETURN(0); + DBUG_RETURN(error_code); } NodeId @@ -1524,6 +1646,24 @@ MgmtSrvr::check_node_support_activate() return true; } +bool +MgmtSrvr::check_node_support_set_location_domain_id() +{ + NodeId nodeId = 0; + while(getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_NDB)) + { + if (okToSendTo(nodeId, true) == 0) + { + Uint32 version = getNodeInfo(nodeId).m_info.m_version; + if (!ndbd_support_set_location_domain_id(version)) + { + return false; + } + } + } + return true; +} + int MgmtSrvr::activate_request(int activateNodeId) { @@ -1568,6 +1708,7 @@ MgmtSrvr::activate_request(int activateNodeId) { DBUG_RETURN(SEND_OR_RECEIVE_FAILED); } + int error_code = 0; while (!nodes.isclear()) { SimpleSignal *signal = ss.waitFor(); @@ -1575,7 +1716,12 @@ MgmtSrvr::activate_request(int activateNodeId) switch (gsn) { case GSN_ACTIVATE_REF: { - DBUG_RETURN(FAILED_ACTIVATE_REQUEST); + const ActivateRef* activateRef = CAST_CONSTPTR(ActivateRef, + signal->getDataPtr()); + assert(activateRef->activateNodeId == Uint32(activateNodeId)); + assert(activateRef->senderNodeId <= nodes.max_size()); + nodes.clear(activateRef->senderNodeId); + error_code = FAILED_ACTIVATE_REQUEST; break; } case GSN_ACTIVATE_CONF: @@ -1623,7 +1769,7 @@ MgmtSrvr::activate_request(int activateNodeId) DBUG_RETURN(SEND_OR_RECEIVE_FAILED); } } - DBUG_RETURN(0); + DBUG_RETURN(error_code); } int @@ -1672,6 +1818,7 @@ MgmtSrvr::deactivate_request(int deactivateNodeId) { DBUG_RETURN(SEND_OR_RECEIVE_FAILED); } + int error_code = 0; while (!nodes.isclear()) { SimpleSignal *signal = ss.waitFor(); @@ -1679,7 +1826,12 @@ MgmtSrvr::deactivate_request(int deactivateNodeId) switch (gsn) { case GSN_DEACTIVATE_REF: { - DBUG_RETURN(FAILED_DEACTIVATE_REQUEST); + const DeactivateRef* deactivateRef = CAST_CONSTPTR(DeactivateRef, + signal->getDataPtr()); + assert(deactivateRef->deactivateNodeId == Uint32(deactivateNodeId)); + assert(deactivateRef->senderNodeId <= nodes.max_size()); + nodes.clear(deactivateRef->senderNodeId); + error_code = FAILED_DEACTIVATE_REQUEST; break; } case GSN_DEACTIVATE_CONF: @@ -1727,7 +1879,7 @@ MgmtSrvr::deactivate_request(int deactivateNodeId) DBUG_RETURN(SEND_OR_RECEIVE_FAILED); } } - DBUG_RETURN(0); + DBUG_RETURN(error_code); } /** diff --git a/storage/ndb/src/mgmsrv/MgmtSrvr.hpp b/storage/ndb/src/mgmsrv/MgmtSrvr.hpp index cb4554d686b6..c721228eea95 100644 --- a/storage/ndb/src/mgmsrv/MgmtSrvr.hpp +++ b/storage/ndb/src/mgmsrv/MgmtSrvr.hpp @@ -208,9 +208,18 @@ class MgmtSrvr : private ConfigSubscriber, public trp_client { */ NodeId get_mgm_nodeid_request(); + /** + * Set a new location domain id on a deactivated node. + * @param processId Id of the DB process to change + * @new_location_domain_id new location domain id for the node + * @return 0 if succeeded, otherwise: error code + */ + int set_location_domain_id_request(int processId, + const int new_location_domain_id); + /** * Set a new hostname on a deactivated node. - * @param processId Id of the DB process to activate + * @param processId Id of the DB process to change hostname * @new_hostname new hostname for the node * @return 0 if succeeded, otherwise: error code */ @@ -617,6 +626,7 @@ class MgmtSrvr : private ConfigSubscriber, public trp_client { int& error_code, BaseString& error_string, Uint32 timeout_s = 20); bool check_node_support_activate(); + bool check_node_support_set_location_domain_id(); public: /* Nodeid allocation diff --git a/storage/ndb/src/mgmsrv/Services.cpp b/storage/ndb/src/mgmsrv/Services.cpp index 8c62948b1626..ce13d29ecbb5 100644 --- a/storage/ndb/src/mgmsrv/Services.cpp +++ b/storage/ndb/src/mgmsrv/Services.cpp @@ -248,6 +248,10 @@ ParserRow commands[] = { MGM_CMD("get mgm nodeid", &MgmApiSession::get_mgm_nodeid, ""), + MGM_CMD("set_location_domain_id", &MgmApiSession::set_location_domain_id, ""), + MGM_ARG("node", Int, Mandatory, "node"), + MGM_ARG("new_location_domain_id", Int, Mandatory, "new location_domain_id"), + MGM_CMD("set_hostname", &MgmApiSession::set_hostname, ""), MGM_ARG("node", Int, Mandatory, "node"), MGM_ARG("new_hostname", String, Mandatory, "new hostname"), @@ -1461,6 +1465,34 @@ MgmApiSession::get_mgm_nodeid(Parser::Context &, m_output->println("%s", ""); } +void +MgmApiSession::set_location_domain_id(Parser::Context &, + Properties const &args) +{ + Uint32 node; + Uint32 new_location_domain_id; + + bool arg1 = args.get("node", &node); + bool arg2 = args.get("new_location_domain_id", &new_location_domain_id); + int result; + if (arg1 && arg2) + { + result = m_mgmsrv.set_location_domain_id_request( + node, new_location_domain_id); + } + else + { + result = INCORRECT_MGM_COMMAND; + } + + m_output->println("set_location_domain_id reply"); + if(result != 0) + m_output->println("result: %s", get_error_text(result)); + else + m_output->println("result: Ok"); + m_output->println("%s", ""); +} + void MgmApiSession::set_hostname(Parser::Context &, Properties const &args) diff --git a/storage/ndb/src/mgmsrv/Services.hpp b/storage/ndb/src/mgmsrv/Services.hpp index 8c699d725abc..52fac7982395 100644 --- a/storage/ndb/src/mgmsrv/Services.hpp +++ b/storage/ndb/src/mgmsrv/Services.hpp @@ -108,6 +108,8 @@ class MgmApiSession : public SocketServer::Session void stop(const class Properties &args, int version); void stopAll(Parser_t::Context &ctx, const class Properties &args); void get_mgm_nodeid(Parser_t::Context &ctx, const class Properties &args); + void set_location_domain_id(Parser_t::Context &ctx, + const class Properties &args); void set_hostname(Parser_t::Context &ctx, const class Properties &args); void activate(Parser_t::Context &ctx, const class Properties &args); void deactivate(Parser_t::Context &ctx, const class Properties &args); diff --git a/storage/ndb/src/mgmsrv/ndb_mgmd_error.h b/storage/ndb/src/mgmsrv/ndb_mgmd_error.h index d8c791df17af..eff30df8c4b1 100644 --- a/storage/ndb/src/mgmsrv/ndb_mgmd_error.h +++ b/storage/ndb/src/mgmsrv/ndb_mgmd_error.h @@ -46,5 +46,6 @@ #define NODE_CURRENTLY_DEACTIVATED 5065 #define INCORRECT_MGM_COMMAND 5066 #define FAILED_SET_HOSTNAME_REQUEST 5067 +#define FAILED_SET_DOMAIN_ID_REQUEST 5069 #endif diff --git a/storage/ndb/src/ndbapi/ClusterMgr.cpp b/storage/ndb/src/ndbapi/ClusterMgr.cpp index 3c55e949e86d..b0db185c8bc3 100644 --- a/storage/ndb/src/ndbapi/ClusterMgr.cpp +++ b/storage/ndb/src/ndbapi/ClusterMgr.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -550,6 +551,10 @@ ClusterMgr::trp_deliver_signal(const NdbApiSignal* sig, const Uint32 * theData = sig->getDataPtr(); switch (gsn){ + case GSN_SET_DOMAIN_ID_REQ: + execSET_DOMAIN_ID_REQ(theData); + break; + case GSN_ACTIVATE_REQ: execACTIVATE_REQ(theData); break; @@ -795,6 +800,88 @@ ClusterMgr::recalcMinApiVersion() minApiVersion = newMinApiVersion; } +void +ClusterMgr::sendSET_DOMAIN_ID_REF(Uint32 ref, + Uint32 senderId, + Uint32 senderRef, + NodeId changeNodeId, + Uint32 locationDomainId, + Uint32 errorCode) { + NdbApiSignal signal(ref); + SetDomainIdRef * const ref_sig = + CAST_PTR(SetDomainIdRef, signal.getDataPtrSend()); + signal.theVerId_signalNumber = GSN_SET_DOMAIN_ID_REF; + signal.theReceiversBlockNumber = refToMain(senderRef); + signal.theTrace = 0; + signal.theLength = SetDomainIdRef::SignalLength; + ref_sig->senderId = senderId; + ref_sig->senderRef = ref; + ref_sig->changeNodeId = changeNodeId; + ref_sig->locationDomainId = locationDomainId; + ref_sig->errorCode = errorCode; + safe_sendSignal(&signal, refToNode(senderRef)); + DEBUG_FPRINTF((stderr, "Send SET_DOMAIN_ID_REF to %u about node %u, err: %u", + refToNode(senderRef), + changeNodeId, + errorCode)); + +} + +void +ClusterMgr::execSET_DOMAIN_ID_REQ(const Uint32 *theData) +{ + const SetDomainIdReq * const setDomainIdReq = + (const SetDomainIdReq *)&theData[0]; + Uint32 senderId = setDomainIdReq->senderId; + Uint32 senderRef = setDomainIdReq->senderRef; + NodeId changeNodeId = setDomainIdReq->changeNodeId; + Uint32 locationDomainId = setDomainIdReq->locationDomainId; + Uint32 ref = numberToRef(API_CLUSTERMGR, theFacade.ownId()); + if (changeNodeId > MAX_NODES) + { + /* Should never happen, thus error code 0 */ + sendSET_DOMAIN_ID_REF(ref, + senderId, + senderRef, + changeNodeId, + locationDomainId, + 0); + return; + } + Ndb_cluster_connection_impl *ndb_cluster_connection = + theFacade.get_ndb_cluster_connection(); + int error_code = 0; + if (ndb_cluster_connection != nullptr) { + error_code = + ndb_cluster_connection->set_location_domain_id(changeNodeId, + locationDomainId); + } + if (error_code != 0) { + sendSET_DOMAIN_ID_REF(ref, + senderId, + senderRef, + changeNodeId, + locationDomainId, + Uint32(error_code)); + return; + } + NdbApiSignal signal(ref); + SetDomainIdConf * const conf = + CAST_PTR(SetDomainIdConf, signal.getDataPtrSend()); + signal.theVerId_signalNumber = GSN_SET_DOMAIN_ID_CONF; + signal.theReceiversBlockNumber = refToMain(senderRef); + signal.theTrace = 0; + signal.theLength = SetDomainIdConf::SignalLength; + conf->senderId = theFacade.ownId(); + conf->senderRef = ref; + conf->changeNodeId = changeNodeId; + conf->locationDomainId = locationDomainId; + safe_sendSignal(&signal, refToNode(senderRef)); + DEBUG_FPRINTF((stderr, "Send SET_DOMAIN_ID_CONF to %u about node %u", + refToNode(senderRef), + changeNodeId)); +} + void ClusterMgr::execACTIVATE_REQ(const Uint32 *theData) { diff --git a/storage/ndb/src/ndbapi/ClusterMgr.hpp b/storage/ndb/src/ndbapi/ClusterMgr.hpp index 5f21f4c7853f..20f479ede87b 100644 --- a/storage/ndb/src/ndbapi/ClusterMgr.hpp +++ b/storage/ndb/src/ndbapi/ClusterMgr.hpp @@ -216,6 +216,7 @@ class ClusterMgr : public trp_client /** * Signals received */ + void execSET_DOMAIN_ID_REQ (const Uint32 * theData); void execSET_HOSTNAME_REQ(const NdbApiSignal*, const LinearSectionPtr ptr[]); void execACTIVATE_REQ (const Uint32 * theData); void execDEACTIVATE_REQ (const Uint32 * theData); @@ -226,6 +227,7 @@ class ClusterMgr : public trp_client void execNODE_FAILREP (const NdbApiSignal*, const LinearSectionPtr ptr[]); void execNF_COMPLETEREP(const NdbApiSignal*, const LinearSectionPtr ptr[3]); + void sendSET_DOMAIN_ID_REF(Uint32, Uint32, Uint32, NodeId, Uint32, Uint32); void check_wait_for_hb(NodeId nodeId); void is_cluster_completely_unavailable(Int32 & error, Uint32 line); diff --git a/storage/ndb/src/ndbapi/Ndb.cpp b/storage/ndb/src/ndbapi/Ndb.cpp index 921bd465c30b..8cbbb7af6ba0 100644 --- a/storage/ndb/src/ndbapi/Ndb.cpp +++ b/storage/ndb/src/ndbapi/Ndb.cpp @@ -813,9 +813,11 @@ NdbImpl::select_node(NdbTableImpl *table_impl, * nodes with the same proximity, but small enough to not prioritize * it over other nodes with higher proximity. */ + DBUG_ENTER("NdbImpl::select_node"); + DBUG_PRINT("enter",("cnt: %u", cnt)); if (table_impl == nullptr) { - return m_ndb_cluster_connection.select_any(this); + DBUG_RETURN(m_ndb_cluster_connection.select_any(this)); } Uint32 nodeId; @@ -841,11 +843,13 @@ NdbImpl::select_node(NdbTableImpl *table_impl, nodes, cnt, primary_node); + DBUG_PRINT("exit",("select_location_based: nodeId: %u", nodeId)); } else { /* Backwards compatible setting */ nodeId = primary_node; + DBUG_PRINT("exit",("Choose primary: nodeId: %u", nodeId)); } } else if (fullyReplicated) @@ -865,8 +869,9 @@ NdbImpl::select_node(NdbTableImpl *table_impl, * Except for fully replicated tables, see above. */ nodeId = m_ndb_cluster_connection.select_any(this); + DBUG_PRINT("exit",("select_any: nodeId: %u", nodeId)); } - return nodeId; + DBUG_RETURN(nodeId); } NdbTransaction* diff --git a/storage/ndb/src/ndbapi/TransporterFacade.cpp b/storage/ndb/src/ndbapi/TransporterFacade.cpp index 7172085cd4c9..45e114f4e1e7 100644 --- a/storage/ndb/src/ndbapi/TransporterFacade.cpp +++ b/storage/ndb/src/ndbapi/TransporterFacade.cpp @@ -1665,7 +1665,9 @@ TransporterFacade::external_poll(Uint32 wait_time) } while (wait_time > 0); } -TransporterFacade::TransporterFacade(GlobalDictCache *cache) : +TransporterFacade::TransporterFacade( + GlobalDictCache *cache, + Ndb_cluster_connection_impl *ndb_cluster_connection) : min_active_clients_recv_thread(DEFAULT_MIN_ACTIVE_CLIENTS_RECV_THREAD), recv_thread_cpu_id(NO_RECV_THREAD_CPU_ID), m_poll_owner_tid(), @@ -1706,7 +1708,8 @@ TransporterFacade::TransporterFacade(GlobalDictCache *cache) : m_send_thread_mutex(nullptr), m_send_thread_cond(nullptr), m_send_thread_nodes(), - m_has_data_nodes() + m_has_data_nodes(), + m_ndb_cluster_connection(ndb_cluster_connection) { DBUG_ENTER("TransporterFacade::TransporterFacade"); thePollMutex = NdbMutex_CreateWithName("PollMutex"); diff --git a/storage/ndb/src/ndbapi/TransporterFacade.hpp b/storage/ndb/src/ndbapi/TransporterFacade.hpp index d16c17da2720..a729a28147f8 100644 --- a/storage/ndb/src/ndbapi/TransporterFacade.hpp +++ b/storage/ndb/src/ndbapi/TransporterFacade.hpp @@ -42,6 +42,7 @@ #include "transporter/TransporterCallback.hpp" #include "portlib/ndb_sockaddr.h" +class Ndb_cluster_connection_impl; class ClusterMgr; class ArbitMgr; struct ndb_mgm_configuration; @@ -68,7 +69,7 @@ class TransporterFacade : */ static constexpr Uint32 MAX_NO_THREADS = 4711; static constexpr Uint32 MAX_LOCKED_CLIENTS = 256; - TransporterFacade(GlobalDictCache *cache); + TransporterFacade(GlobalDictCache *cache, Ndb_cluster_connection_impl*); ~TransporterFacade() override; int start_instance(NodeId, const ndb_mgm_configuration*); @@ -608,6 +609,13 @@ class TransporterFacade : * of sending to these nodes. */ NodeBitmask m_has_data_nodes; + + Ndb_cluster_connection_impl *m_ndb_cluster_connection; + +public: + Ndb_cluster_connection_impl* get_ndb_cluster_connection() { + return m_ndb_cluster_connection; + } }; inline diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp index 5cc81395ad52..86ccdb472c9b 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp @@ -540,14 +540,14 @@ Ndb_cluster_connection_impl(const char * connect_string, if (!m_main_connection) { m_globalDictCache = new GlobalDictCache; - m_transporter_facade= new TransporterFacade(m_globalDictCache); + m_transporter_facade= new TransporterFacade(m_globalDictCache, this); } else { assert(m_main_connection->m_impl.m_globalDictCache != nullptr); m_globalDictCache = nullptr; m_transporter_facade= - new TransporterFacade(m_main_connection->m_impl.m_globalDictCache); + new TransporterFacade(m_main_connection->m_impl.m_globalDictCache, this); // The secondary connection can't use same nodeid, but it's ok // to specify one to use. Use the force_api_nodeid given(although @@ -766,6 +766,69 @@ Ndb_cluster_connection_impl::set_next_transid(Uint32 reference, Uint32 value) unlock_ndb_objects(); } +int +Ndb_cluster_connection_impl::set_location_domain_id(Uint32 nodeId, + Uint32 locationDomainId) { + Uint32 old_locationDomainId = m_location_domain_id[nodeId]; + Uint32 my_old_locationDomainId = m_my_location_domain_id; + DBUG_ENTER("Ndb_cluster_connection_impl::set_location_domain_id"); + DBUG_PRINT("enter",("nodeId: %u, locDomId: %u, old_dom: %u, my_node: %u", + nodeId, locationDomainId, old_locationDomainId, m_my_node_id)); + if (m_location_domain_id[nodeId] == locationDomainId) { + DBUG_RETURN(0); + } + + /* We have actually changed the LocationDomainId */ + if (nodeId == m_my_node_id) { + m_my_location_domain_id = locationDomainId; + } else { + if (nodeId >= MAX_NDB_NODES || + m_db_nodes.get(nodeId) == 0) { // Thus it is another API node + DBUG_RETURN(0); + } + if (m_my_location_domain_id == 0) { // Our location domain id is not set + m_location_domain_id[nodeId] = locationDomainId; + DBUG_RETURN(0); + } + } + NdbMutex_Lock(m_nodes_proximity_mutex); + m_location_domain_id[nodeId] = locationDomainId; + Int32 adjustment = 0; + if (m_my_location_domain_id == my_old_locationDomainId) { + /* We stay in the same LocationDomainId, thus changing a DB node */ + if (m_my_location_domain_id == old_locationDomainId && + old_locationDomainId != 0) { + /* Moved out of the same location domain id */ + adjustment += 5; + } else if (m_my_location_domain_id == locationDomainId) { + /* Moved into our location domain id */ + adjustment -= 5; + } + if (adjustment != 0) { + adjust_node_proximity(nodeId, adjustment); + } + } else { + /* We move to a new LocationDomainId for our node */ + for (Uint32 i = 1; i < MAX_NDB_NODES; i++) { + if (m_db_nodes.get(i) == 0) continue; + if (old_locationDomainId == m_location_domain_id[i] && + old_locationDomainId != 0) { + /* Moved out of location domain of DB node */ + adjustment += 5; + } else if (locationDomainId == m_location_domain_id[i] && + locationDomainId != 0) { + adjustment -= 5; + } + if (adjustment != 0) { + adjust_node_proximity(i, adjustment); + } + } + } + NdbMutex_Unlock(m_nodes_proximity_mutex); + DBUG_PRINT("exit",("adjustment: %d", adjustment)); + DBUG_RETURN(0); +} + /** * adjust_node_proximity * @@ -1686,9 +1749,12 @@ Ndb_cluster_connection_impl::select_any(NdbImpl *impl_ndb) Uint16 prospective_node_ids[MAX_NDB_NODES]; Uint32 num_prospective_nodes = 0; Uint32 my_location_domain_id = m_my_location_domain_id; + DBUG_ENTER("Ndb_cluster_connection_impl::select_any"); + DBUG_PRINT("enter",("my_domain: %u", + my_location_domain_id)); if (my_location_domain_id == 0) { - return 0; + DBUG_RETURN(0); } for (Uint32 i = 0; i < m_nodes_proximity.size(); i++) { @@ -1697,22 +1763,23 @@ Ndb_cluster_connection_impl::select_any(NdbImpl *impl_ndb) impl_ndb->get_node_available(nodeid)) { prospective_node_ids[num_prospective_nodes++] = nodeid; + DBUG_PRINT("info",("Prospective node: %u", nodeid)); } } if (num_prospective_nodes == 0) { - return 0; + DBUG_RETURN(0); } else if (num_prospective_nodes == 1) { - return prospective_node_ids[0]; + DBUG_RETURN(prospective_node_ids[0]); } else { - return select_node(impl_ndb, - prospective_node_ids, - num_prospective_nodes, - 0); + DBUG_RETURN(select_node(impl_ndb, + prospective_node_ids, + num_prospective_nodes, + 0)); } } @@ -1730,33 +1797,41 @@ Ndb_cluster_connection_impl::select_location_based(NdbImpl *impl_ndb, Uint16 prospective_node_ids[MAX_NDB_NODES]; Uint32 num_prospective_nodes = 0; Uint32 my_location_domain_id = m_my_location_domain_id; + DBUG_ENTER("Ndb_cluster_connection_impl::select_location_based"); + DBUG_PRINT("enter",("cnt: %u, primary: %u, my_domain: %u", + cnt, primary_node, my_location_domain_id)); if (my_location_domain_id == 0) { - return select_node(impl_ndb, nodes, cnt, primary_node); + DBUG_RETURN(select_node(impl_ndb, nodes, cnt, primary_node)); } for (Uint32 i = 0; i < cnt; i++) { + DBUG_PRINT("info",("Location domain id: %u of node: %u, avail: %u", + m_location_domain_id[nodes[i]], + nodes[i], + impl_ndb->get_node_available(nodes[i]))); if (my_location_domain_id == m_location_domain_id[nodes[i]] && impl_ndb->get_node_available(nodes[i])) { + DBUG_PRINT("info",("Prospective node: %u", nodes[i])); prospective_node_ids[num_prospective_nodes++] = nodes[i]; } } if (num_prospective_nodes == 0) { - return select_node(impl_ndb, nodes, cnt, primary_node); + DBUG_RETURN(select_node(impl_ndb, nodes, cnt, primary_node)); } else if (num_prospective_nodes == 1) { - return prospective_node_ids[0]; + DBUG_RETURN(prospective_node_ids[0]); } else { - return select_node(impl_ndb, - prospective_node_ids, - num_prospective_nodes, - primary_node); + DBUG_RETURN(select_node(impl_ndb, + prospective_node_ids, + num_prospective_nodes, + primary_node)); } } @@ -1766,13 +1841,16 @@ Ndb_cluster_connection_impl::select_node(NdbImpl *impl_ndb, Uint32 cnt, Uint32 primary_node) { + DBUG_ENTER("Ndb_cluster_connection_impl::select_node"); + DBUG_PRINT("enter",("cnt: %u, primary: %u, my_domain: %u", + cnt, primary_node, m_my_location_domain_id)); if (cnt == 1) { - return nodes[0]; + DBUG_RETURN(nodes[0]); } else if (cnt == 0) { - return 0; + DBUG_RETURN(0); } NdbNodeBitmask checked; @@ -1857,6 +1935,8 @@ Ndb_cluster_connection_impl::select_node(NdbImpl *impl_ndb, best_node = candidate_node; best_score = nodes_arr[i].adjusted_group; best_usage = nodes_arr[i].hint_count; + DBUG_PRINT("info",("1: node: %u, best_score: %u, best_usage: %u", + candidate_node, best_score, best_usage)); } else if (nodes_arr[i].adjusted_group == best_score) { @@ -1871,6 +1951,8 @@ Ndb_cluster_connection_impl::select_node(NdbImpl *impl_ndb, best_idx = i; best_node = candidate_node; best_usage = usage; + DBUG_PRINT("info",("2: node: %u, best_score: %u, best_usage: %u", + candidate_node, best_score, best_usage)); } else { @@ -1885,6 +1967,8 @@ Ndb_cluster_connection_impl::select_node(NdbImpl *impl_ndb, best_idx = i; best_node = candidate_node; best_usage = usage; + DBUG_PRINT("info",("3: node: %u, best_score: %u,best_usage:%u", + candidate_node, best_score, best_usage)); } } } @@ -1898,7 +1982,7 @@ Ndb_cluster_connection_impl::select_node(NdbImpl *impl_ndb, nodes_arr[best_idx].hint_count = (nodes_arr[best_idx].hint_count + 1) & HINT_COUNT_MASK; } - return best_node; + DBUG_RETURN(best_node); } template class Vector; diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp index 83abe44278ad..6248ac6e3ed9 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp @@ -86,6 +86,7 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection inline unsigned get_min_api_version() const; public: inline Uint64 *get_latest_trans_gci() { return &m_latest_trans_gci; } + int set_location_domain_id(Uint32 nodeId, Uint32 location_domain_id); private: friend class Ndb; diff --git a/storage/ndb/src/ndbapi/ndberror.cpp b/storage/ndb/src/ndbapi/ndberror.cpp index 2c230b1e2b2c..ba6ac941f752 100644 --- a/storage/ndb/src/ndbapi/ndberror.cpp +++ b/storage/ndb/src/ndbapi/ndberror.cpp @@ -1042,7 +1042,11 @@ ErrorBundle ErrorCodes[] = { { 5067 /* FAILED_SET_HOSTNAME_REQUEST */, DMEC, AE, "Data nodes failed to set new hostname"}, { 5068 /* FAILED_DEACTIVATE_REQUEST */, DMEC, AE, - "Data nodes failed Deactivate Request"} + "Data nodes failed Deactivate Request"}, + { 5069 /* FAILED_SET_DOMAIN_ID_REQUEST */, DMEC, AE, + "Data nodes failed Set Location_Domain_Id Request"}, + { 1120, DMEC, AE, + "Set Location_Domain_Id Request failed, busy state"} }; static