Skip to content

Commit c4fe37a

Browse files
author
Magnus Svensson
committed
WL#4350 Extend Config class
1 parent b428a30 commit c4fe37a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

storage/ndb/src/mgmsrv/Config.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ Config::pack(UtilBuffer& buf) const
233233
}
234234

235235

236+
#include <base64.h>
237+
238+
bool
239+
Config::pack64(BaseString& encoded) const
240+
{
241+
UtilBuffer buf;
242+
if (m_configValues->m_config.pack(buf) == 0)
243+
return false;
244+
245+
// Expand the string to correct length by filling with Z
246+
encoded.assfmt("%*s",
247+
base64_needed_encoded_length(buf.length()),
248+
"Z");
249+
250+
if (base64_encode(buf.get_data(),
251+
buf.length(),
252+
(char*)encoded.c_str()))
253+
return false;
254+
return true;
255+
}
256+
236257

237258
enum diff_types {
238259
DT_DIFF, // Value differed
@@ -725,3 +746,34 @@ bool Config::illegal_change(const Config* other) const {
725746
return illegal_change(diff_list);
726747
}
727748

749+
750+
void Config::getConnectString(BaseString& connectstring,
751+
const BaseString& separator) const
752+
{
753+
bool first= true;
754+
ConfigIter it(this, CFG_SECTION_NODE);
755+
756+
for(;it.valid(); it.next())
757+
{
758+
/* Get type of Node */
759+
Uint32 nodeType;
760+
require(it.get(CFG_TYPE_OF_SECTION, &nodeType) == 0);
761+
762+
if (nodeType != NODE_TYPE_MGM)
763+
continue;
764+
765+
Uint32 port;
766+
const char* hostname;
767+
require(it.get(CFG_NODE_HOST, &hostname) == 0);
768+
require(it.get(CFG_MGM_PORT, &port) == 0);
769+
770+
if (!first)
771+
connectstring.append(separator);
772+
first= false;
773+
774+
connectstring.appfmt("%s:%d", hostname, port);
775+
776+
}
777+
ndbout << connectstring << endl;
778+
}
779+

storage/ndb/src/mgmsrv/Config.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class Config {
7272
*/
7373
Uint32 pack(UtilBuffer&) const;
7474

75+
/*
76+
Pack the config as base64
77+
*/
78+
bool pack64(BaseString&) const;
79+
7580
/*
7681
Compare against another config and return a list of
7782
differences in a Properties object
@@ -84,6 +89,15 @@ class Config {
8489
*/
8590
void print_diff(const Config* other) const;
8691

92+
93+
/*
94+
Get the full connectstring for this configuration. ie
95+
a list of all the mgmd servers and their port separated
96+
by separator.
97+
*/
98+
void getConnectString(BaseString&,
99+
const BaseString& separator = BaseString(";")) const;
100+
87101
/*
88102
Print the difference to string buffer
89103
*/
@@ -100,6 +114,7 @@ class Config {
100114
bool equal(const Config*, const unsigned* exclude = NULL) const;
101115

102116
struct ndb_mgm_configuration * m_configValues;
117+
struct ndb_mgm_configuration * values(void) const { return m_configValues; };
103118

104119
private:
105120
bool setValue(Uint32 section, Uint32 section_no,

0 commit comments

Comments
 (0)