From 5c1ca07de84fd397c6d91aec131462d760153098 Mon Sep 17 00:00:00 2001 From: John David Duncan Date: Fri, 10 Mar 2017 12:07:37 -0800 Subject: [PATCH] wl#9819 Version 2. Patch #6: Ndb_cluster_connection --- .../include/ndbapi/ndb_cluster_connection.hpp | 37 ++++++++--- .../ndb/src/ndbapi/ndb_cluster_connection.cpp | 62 +++++++++++++++---- .../ndbapi/ndb_cluster_connection_impl.hpp | 11 ++-- 3 files changed, 85 insertions(+), 25 deletions(-) diff --git a/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp b/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp index cd8b0cdab4b5..9a21810e7b21 100644 --- a/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp +++ b/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp @@ -105,17 +105,38 @@ class Ndb_cluster_connection { void set_name(const char *name); /** - * Set an application host network address and port number on the connection, - * which will be reported in ndbinfo.processes. - * This must be called prior to connect() for the information to be visible. - * If address_string is null, the network address used by the NDBAPI - * connection will be reported. + * For each Ndb_cluster_connection, NDB publishes a URI in the ndbinfo + * processes table. A user may customize this URI using set_service_uri(). * - * @param address_string - * @param port + * By default the published URI takes the form ndb://x.x.x.x/, where x.x.x.x + * is the IPv4 address of the node. This default URI has scheme "ndb", + * port 0, host set to null, and empty path, as described below. * + * If set_service_uri() is called prior to connect(), the URI will be + * published immediately upon connection. If called after the cluster + * connection is established, the URI will be published after a delay + * of up to HeartbeatIntervalDbApi msec. + * + * @param scheme The URI scheme. The scheme may contain only lowercase + * letters, numbers, and the characters ".", "+", and "-". + * It will be truncated to 16 characters. + * @param host The URI network address or hostname. + * Host will be truncated to 48 characters, which is sufficient space for + * an IPv6 network address, but not necessarily for a domain name. + * If host is null, each data node will report the network address from + * its own connection to this node. An Ndb_cluster_connection that uses + * a variety of transporters or network addresses to connect to different + * data nodes will appear in multiple rows of the ndbinfo.processes + * table. + * @param port The URI port. If 0, no port component will not be published. + * @param path The URI path, possibly followed by a query component beginning + * with the character "?". The combined path and query will be truncated + * to 128 characters. It may not begin with a double slash. + * + * @return 0 on success, 1 on syntax error in scheme or path component */ - void set_application_address(const char * address_string, int port); + int set_service_uri(const char * scheme, const char * host, int port, + const char * path); /** * Set timeout diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp index 4d7781b59df1..e69c9afc089b 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp @@ -31,6 +31,7 @@ #include #include "NdbImpl.hpp" #include "NdbDictionaryImpl.hpp" +#include "ProcessInfo.hpp" #include #ifdef VM_TRACE @@ -438,8 +439,10 @@ Ndb_cluster_connection_impl(const char * connect_string, m_latest_error(0), m_data_node_neighbour(0), m_multi_wait_group(0), - m_application_addr(0), - m_application_port(0) + m_uri_scheme(NULL), + m_uri_host(NULL), + m_uri_path(NULL), + m_uri_port(0) { DBUG_ENTER("Ndb_cluster_connection"); DBUG_PRINT("enter",("Ndb_cluster_connection this=0x%lx", (long) this)); @@ -593,6 +596,10 @@ Ndb_cluster_connection_impl::~Ndb_cluster_connection_impl() delete m_multi_wait_group; m_multi_wait_group = 0; + m_uri_scheme.clear(); + m_uri_path.clear(); + m_uri_host.clear(); + DBUG_VOID_RETURN; } @@ -903,11 +910,39 @@ Ndb_cluster_connection_impl::set_name(const char *name) ndb_mgm_set_name(h, name); } -void -Ndb_cluster_connection_impl::set_application_address(const char * addr, int port) +int +Ndb_cluster_connection_impl::set_service_uri(const char * scheme, + const char * host, + int port, const char * path) { - m_application_addr = addr; - m_application_port = port; + if(! ProcessInfo::isValidUri(scheme, path)) + { + return 1; + } + + /* Clear out existing values */ + m_uri_scheme.clear(); + m_uri_host.clear(); + m_uri_port = 0; + m_uri_path.clear(); + + /* If already connected, ClusterMgr will send new ProcessInfo reports. + Otherwise save a copy of values until connected. + */ + if(m_transporter_facade->theClusterMgr->getNoOfConnectedNodes()) + { + m_transporter_facade->theClusterMgr->setProcessInfoUri(scheme, host, + port, path); + } + else + { + m_uri_scheme.assign(scheme); + m_uri_host.assign(host); + m_uri_port = port; + m_uri_path.assign(path); + } + + return 0; } int @@ -1226,9 +1261,11 @@ void Ndb_cluster_connection::set_name(const char *name) m_impl.set_name(name); } -void Ndb_cluster_connection::set_application_address(const char * addr, int port) +int Ndb_cluster_connection::set_service_uri(const char * scheme, + const char * host, int port, + const char * path) { - m_impl.set_application_address(addr, port); + return m_impl.set_service_uri(scheme, host, port, path); } const char * Ndb_cluster_connection::get_system_name() const @@ -1301,11 +1338,10 @@ int Ndb_cluster_connection_impl::connect(int no_retries, ndb_mgm_destroy_configuration(props); DBUG_RETURN(-1); } - NdbMgmHandle mgm_handle = m_config_retriever->get_mgmHandle(); - const char * name = ndb_mgm_get_name(mgm_handle); - m_transporter_facade->theClusterMgr->setProcessInfo(name, - m_application_addr, - m_application_port); + m_transporter_facade->theClusterMgr->setProcessInfoUri(m_uri_scheme.c_str(), + m_uri_host.c_str(), + m_uri_port, + m_uri_path.c_str()); ndb_mgm_destroy_configuration(props); m_transporter_facade->connected(); m_latest_error = 0; diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp index 823c82de6a56..45e8e71ddc1a 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp @@ -117,7 +117,7 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection int configure(Uint32 nodeid, const ndb_mgm_configuration &config); void connect_thread(); void set_name(const char *name); - void set_application_address(const char *, int); + int set_service_uri(const char *, const char *, int, const char *); void set_data_node_neighbour(Uint32 neighbour_node); void adjust_node_proximity(Uint32 node_id, Int32 adjustment); Uint32 get_db_nodes(Uint8 nodesarray[MAX_NDB_NODES]) const; @@ -170,9 +170,12 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection NdbWaitGroup *m_multi_wait_group; - // Data for ndbinfo.processes - const char * m_application_addr; - int m_application_port; + // Service URI in ndbinfo.processes + BaseString m_uri_scheme, m_uri_host, m_uri_path; + int m_uri_port; + + // system.name copied from configuration + BaseString m_system_name; }; #endif