Skip to content

Commit

Permalink
wl#9819 Version 2. Patch #6: Ndb_cluster_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jdduncan committed Mar 30, 2017
1 parent e7a0d99 commit 5c1ca07
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 25 deletions.
37 changes: 29 additions & 8 deletions storage/ndb/include/ndbapi/ndb_cluster_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 49 additions & 13 deletions storage/ndb/src/ndbapi/ndb_cluster_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <mgmapi_internal.h>
#include "NdbImpl.hpp"
#include "NdbDictionaryImpl.hpp"
#include "ProcessInfo.hpp"

#include <NdbMutex.h>
#ifdef VM_TRACE
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

0 comments on commit 5c1ca07

Please sign in to comment.