int main(int argc, char** argv) { if (argc != 8) { ndbout << "Arguments are <connect_string cluster 1> <connect_string cluster 2> <database> <table name> <primary key> <value of primary key> <attribute to update>.\n"; exit(-1); } // ndb_init must be called first ndb_init(); { const char *opt_connectstring1 = argv[1]; const char *opt_connectstring2 = argv[2]; const char *opt_db = argv[3]; const char *opt_table = argv[4]; const char *opt_pk = argv[5]; const Uint32 opt_pk_val = atoi(argv[6]); const char *opt_col = argv[7]; // Object representing the cluster 1 Ndb_cluster_connection cluster1_connection(opt_connectstring1); // Object representing the cluster 2 Ndb_cluster_connection cluster2_connection(opt_connectstring2); // connect cluster 1 and run application // Connect to cluster 1 management server (ndb_mgmd) if (cluster1_connection.connect(4 /* retries */, 5 /* delay between retries */, 1 /* verbose */)) { g_err << "Cluster 1 management server was not ready within 30 secs.\n"; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster1_connection.wait_until_ready(30,0) < 0) { g_err << "Cluster 1 was not ready within 30 secs.\n"; exit(-1); } // connect cluster 2 and run application // Connect to cluster management server (ndb_mgmd) if (cluster2_connection.connect(4 /* retries */, 5 /* delay between retries */, 1 /* verbose */)) { g_err << "Cluster 2 management server was not ready within 30 secs.\n"; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster2_connection.wait_until_ready(30,0) < 0) { g_err << "Cluster 2 was not ready within 30 secs.\n"; exit(-1); } // Object representing the database Ndb myNdb1(&cluster1_connection, opt_db); Ndb myNdb2(&cluster2_connection, opt_db); // struct Xxx xxx1; struct Xxx xxx2; struct XxxR xxxr; prepare_master_or_slave(myNdb1, opt_table, opt_pk, opt_pk_val, opt_col, xxx1, xxxr); prepare_master_or_slave(myNdb2, opt_table, opt_pk, opt_pk_val, opt_col, xxx2, xxxr); while (1) { // run the application code run_master_update(xxx1, xxxr); run_slave_wait(xxx2, xxxr); ndbout << "latency: " << xxxr.latency << endl; } } // Note: all connections must have been destroyed before calling ndb_end() ndb_end(0); return 0; }
int main(int argc, char** argv) { if (argc != 5) { std::cout << "Arguments are <socket mysqld1> <connect_string cluster 1> <socket mysqld2> <connect_string cluster 2>.\n"; exit(-1); } // ndb_init must be called first ndb_init(); { char * mysqld1_sock = argv[1]; const char *connectstring1 = argv[2]; char * mysqld2_sock = argv[3]; const char *connectstring2 = argv[4]; // Object representing the cluster 1 Ndb_cluster_connection cluster1_connection(connectstring1); MYSQL mysql1; // Object representing the cluster 2 Ndb_cluster_connection cluster2_connection(connectstring2); MYSQL mysql2; // connect to mysql server and cluster 1 and run application // Connect to cluster 1 management server (ndb_mgmd) if (cluster1_connection.connect(4 /* retries */, 5 /* delay between retries */, 1 /* verbose */)) { std::cout << "Cluster 1 management server was not ready within 30 secs.\n"; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster1_connection.wait_until_ready(30,0) < 0) { std::cout << "Cluster 1 was not ready within 30 secs.\n"; exit(-1); } // connect to mysql server in cluster 1 if ( !mysql_init(&mysql1) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql1, "localhost", "root", "", "", 0, mysqld1_sock, 0) ) MYSQLERROR(mysql1); // connect to mysql server and cluster 2 and run application // Connect to cluster management server (ndb_mgmd) if (cluster2_connection.connect(4 /* retries */, 5 /* delay between retries */, 1 /* verbose */)) { std::cout << "Cluster 2 management server was not ready within 30 secs.\n"; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster2_connection.wait_until_ready(30,0) < 0) { std::cout << "Cluster 2 was not ready within 30 secs.\n"; exit(-1); } // connect to mysql server in cluster 2 if ( !mysql_init(&mysql2) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql2, "localhost", "root", "", "", 0, mysqld2_sock, 0) ) MYSQLERROR(mysql2); // run the application code run_application(mysql1, cluster1_connection, "MYTABLENAME1", "TEST_DB_1"); run_application(mysql2, cluster2_connection, "MYTABLENAME2", "TEST_DB_2"); } // Note: all connections must have been destroyed before calling ndb_end() ndb_end(0); return 0; }