Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
1add7651
Commit
1add7651
authored
Aug 09, 2004
by
joreland@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug#4529
parent
ad325516
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
305 additions
and
408 deletions
+305
-408
ndb/include/mgmcommon/ConfigRetriever.hpp
ndb/include/mgmcommon/ConfigRetriever.hpp
+21
-24
ndb/include/mgmcommon/LocalConfig.hpp
ndb/include/mgmcommon/LocalConfig.hpp
+10
-24
ndb/src/common/mgmcommon/ConfigRetriever.cpp
ndb/src/common/mgmcommon/ConfigRetriever.cpp
+99
-169
ndb/src/common/mgmcommon/LocalConfig.cpp
ndb/src/common/mgmcommon/LocalConfig.cpp
+30
-64
ndb/src/kernel/main.cpp
ndb/src/kernel/main.cpp
+6
-5
ndb/src/kernel/vm/Configuration.cpp
ndb/src/kernel/vm/Configuration.cpp
+55
-17
ndb/src/kernel/vm/Configuration.hpp
ndb/src/kernel/vm/Configuration.hpp
+1
-0
ndb/src/mgmapi/mgmapi.cpp
ndb/src/mgmapi/mgmapi.cpp
+5
-16
ndb/src/mgmclient/main.cpp
ndb/src/mgmclient/main.cpp
+3
-7
ndb/src/mgmsrv/MgmtSrvr.cpp
ndb/src/mgmsrv/MgmtSrvr.cpp
+16
-13
ndb/src/mgmsrv/MgmtSrvr.hpp
ndb/src/mgmsrv/MgmtSrvr.hpp
+3
-2
ndb/src/mgmsrv/MgmtSrvrConfig.cpp
ndb/src/mgmsrv/MgmtSrvrConfig.cpp
+3
-4
ndb/src/mgmsrv/Services.cpp
ndb/src/mgmsrv/Services.cpp
+16
-25
ndb/src/mgmsrv/main.cpp
ndb/src/mgmsrv/main.cpp
+5
-18
ndb/src/ndbapi/TransporterFacade.cpp
ndb/src/ndbapi/TransporterFacade.cpp
+32
-20
No files found.
ndb/include/mgmcommon/ConfigRetriever.hpp
View file @
1add7651
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
#include <ndb_types.h>
#include <ndb_types.h>
#include <mgmapi.h>
#include <mgmapi.h>
#include <BaseString.hpp>
#include <LocalConfig.hpp>
/**
/**
* @class ConfigRetriever
* @class ConfigRetriever
...
@@ -26,15 +28,16 @@
...
@@ -26,15 +28,16 @@
*/
*/
class
ConfigRetriever
{
class
ConfigRetriever
{
public:
public:
ConfigRetriever
();
ConfigRetriever
(
Uint32
version
,
Uint32
nodeType
);
ConfigRetriever
(
const
int
id
,
const
char
*
remoteHost
,
const
int
port
);
~
ConfigRetriever
();
~
ConfigRetriever
();
/**
/**
* Read local config
* Read local config
* @return Own node id, -1 means fail
* @return Own node id, -1 means fail
*/
*/
int
init
(
bool
onlyNodeId
=
false
);
int
init
();
int
do_connect
();
/**
/**
* Get configuration for current (nodeId given in local config file) node.
* Get configuration for current (nodeId given in local config file) node.
...
@@ -47,7 +50,7 @@ public:
...
@@ -47,7 +50,7 @@ public:
* @return ndb_mgm_configuration object if succeeded,
* @return ndb_mgm_configuration object if succeeded,
* NULL if erroneous local config file or configuration error.
* NULL if erroneous local config file or configuration error.
*/
*/
struct
ndb_mgm_configuration
*
getConfig
(
int
versionId
,
int
nodeType
);
struct
ndb_mgm_configuration
*
getConfig
();
const
char
*
getErrorString
();
const
char
*
getErrorString
();
...
@@ -61,29 +64,22 @@ public:
...
@@ -61,29 +64,22 @@ public:
*/
*/
void
setLocalConfigFileName
(
const
char
*
connectString
);
void
setLocalConfigFileName
(
const
char
*
connectString
);
/**
* Sets connectstring which can be used instead of local config file
* environment variables and Ndb.cfg has precidence over this
*/
void
setDefaultConnectString
(
const
char
*
defaultConnectString
);
/**
/**
* @return Node id of this node (as stated in local config or connectString)
* @return Node id of this node (as stated in local config or connectString)
*/
*/
inline
Uint32
getOwnNodeId
()
{
return
_ownNodeId
;
}
Uint32
allocNodeId
();
/**
/**
* Get config using socket
* Get config using socket
*/
*/
struct
ndb_mgm_configuration
*
getConfig
(
const
char
*
mgmhost
,
short
port
,
struct
ndb_mgm_configuration
*
getConfig
(
NdbMgmHandle
handle
);
int
versionId
,
int
nodetype
);
/**
/**
* Get config from file
* Get config from file
*/
*/
struct
ndb_mgm_configuration
*
getConfig
(
const
char
*
file
,
int
versionId
);
struct
ndb_mgm_configuration
*
getConfig
(
const
char
*
file
);
private:
private:
char
*
errorString
;
BaseString
errorString
;
enum
ErrorType
{
enum
ErrorType
{
CR_ERROR
=
0
,
CR_ERROR
=
0
,
CR_RETRY
=
1
CR_RETRY
=
1
...
@@ -92,19 +88,20 @@ private:
...
@@ -92,19 +88,20 @@ private:
void
setError
(
ErrorType
,
const
char
*
errorMsg
);
void
setError
(
ErrorType
,
const
char
*
errorMsg
);
char
*
_localConfigFileName
;
BaseString
_localConfigFileName
;
struct
LocalConfig
*
_localConfig
;
struct
LocalConfig
_localConfig
;
int
_ownNodeId
;
int
_ownNodeId
;
char
*
m_connectString
;
BaseString
m_connectString
;
char
*
m_defaultConnectString
;
Uint32
m_version
;
Uint32
m_node_type
;
NdbMgmHandle
m_handle
;
NdbMgmHandle
m_handle
;
/**
/**
* Verify config
* Verify config
*/
*/
bool
verifyConfig
(
const
struct
ndb_mgm_configuration
*
,
int
type
);
bool
verifyConfig
(
const
struct
ndb_mgm_configuration
*
);
};
};
#endif
#endif
...
...
ndb/
src/common
/mgmcommon/LocalConfig.hpp
→
ndb/
include
/mgmcommon/LocalConfig.hpp
View file @
1add7651
...
@@ -32,49 +32,35 @@ enum MgmtSrvrId_Type {
...
@@ -32,49 +32,35 @@ enum MgmtSrvrId_Type {
struct
MgmtSrvrId
{
struct
MgmtSrvrId
{
MgmtSrvrId_Type
type
;
MgmtSrvrId_Type
type
;
union
{
BaseString
name
;
struct
{
char
*
remoteHost
;
unsigned
int
port
;
unsigned
int
port
;
}
tcp
;
struct
{
char
*
filename
;
}
file
;
}
data
;
};
};
struct
LocalConfig
{
struct
LocalConfig
{
int
_ownNodeId
;
int
_ownNodeId
;
Vector
<
MgmtSrvrId
>
ids
;
int
size
;
int
items
;
MgmtSrvrId
**
ids
;
int
error_line
;
int
error_line
;
char
error_msg
[
256
];
char
error_msg
[
256
];
LocalConfig
();
LocalConfig
();
~
LocalConfig
();
~
LocalConfig
();
bool
init
(
bool
onlyNodeId
=
false
,
bool
init
(
const
char
*
connectString
=
0
,
const
char
*
connectString
=
0
,
const
char
*
fileName
=
0
);
const
char
*
fileName
=
0
,
const
char
*
defaultConnectString
=
0
);
void
add
(
MgmtSrvrId
*
i
);
void
printError
()
const
;
void
printError
()
const
;
void
printUsage
()
const
;
void
printUsage
()
const
;
void
setError
(
int
lineNumber
,
const
char
*
_msg
);
void
setError
(
int
lineNumber
,
const
char
*
_msg
);
bool
readConnectString
(
const
char
*
connectString
,
bool
onlyNodeId
=
false
);
bool
readConnectString
(
const
char
*
);
bool
readFile
(
const
char
*
file
name
,
bool
&
fopenError
,
bool
onlyNodeId
=
false
);
bool
readFile
(
const
char
*
file
,
bool
&
fopenError
);
bool
parseLine
(
char
*
line
,
int
lineNumber
);
bool
parseLine
(
char
*
line
,
int
lineNumber
);
bool
parseNodeId
(
const
char
*
buf
);
bool
parseNodeId
(
const
char
*
buf
);
bool
parseHostName
(
const
char
*
buf
);
bool
parseHostName
(
const
char
*
buf
);
bool
parseFileName
(
const
char
*
buf
);
bool
parseFileName
(
const
char
*
buf
);
bool
parseString
(
const
char
*
buf
,
bool
onlyNodeId
,
char
*
line
);
bool
parseString
(
const
char
*
buf
,
char
*
line
);
};
};
#endif // LocalConfig_H
#endif // LocalConfig_H
...
...
ndb/src/common/mgmcommon/ConfigRetriever.cpp
View file @
1add7651
...
@@ -43,33 +43,14 @@
...
@@ -43,33 +43,14 @@
//****************************************************************************
//****************************************************************************
//****************************************************************************
//****************************************************************************
ConfigRetriever
::
ConfigRetriever
()
{
ConfigRetriever
::
ConfigRetriever
(
Uint32
version
,
Uint32
node_type
)
{
_localConfigFileName
=
0
;
m_defaultConnectString
=
0
;
errorString
=
0
;
_localConfig
=
new
LocalConfig
();
m_connectString
=
0
;
m_handle
=
0
;
m_handle
=
0
;
m_version
=
version
;
m_node_type
=
node_type
;
}
}
ConfigRetriever
::~
ConfigRetriever
(){
ConfigRetriever
::~
ConfigRetriever
(){
if
(
_localConfigFileName
!=
0
)
free
(
_localConfigFileName
);
if
(
m_defaultConnectString
!=
0
)
free
(
m_defaultConnectString
);
if
(
m_connectString
!=
0
)
free
(
m_connectString
);
if
(
errorString
!=
0
)
free
(
errorString
);
delete
_localConfig
;
if
(
m_handle
)
{
if
(
m_handle
)
{
ndb_mgm_disconnect
(
m_handle
);
ndb_mgm_disconnect
(
m_handle
);
...
@@ -82,68 +63,51 @@ ConfigRetriever::~ConfigRetriever(){
...
@@ -82,68 +63,51 @@ ConfigRetriever::~ConfigRetriever(){
//****************************************************************************
//****************************************************************************
int
int
ConfigRetriever
::
init
(
bool
onlyNodeId
)
{
ConfigRetriever
::
init
()
{
if
(
_localConfig
->
init
(
onlyNodeId
,
m_connectString
,
_localConfigFileName
,
m_defaultConnectString
))
{
if
(
!
_localConfig
.
init
(
m_connectString
.
c_str
(),
return
_ownNodeId
=
(
*
_localConfig
).
_ownNodeId
;
_localConfigFileName
.
c_str
())){
}
setError
(
CR_ERROR
,
"error in retrieving contact info for mgmtsrvr"
);
setError
(
CR_ERROR
,
"error in retrieving contact info for mgmtsrvr"
);
_localConfig
->
printError
();
_localConfig
.
printError
();
_localConfig
->
printUsage
();
_localConfig
.
printUsage
();
return
-
1
;
return
-
1
;
}
return
_ownNodeId
=
_localConfig
.
_ownNodeId
;
}
}
//****************************************************************************
int
//****************************************************************************
ConfigRetriever
::
do_connect
(){
//****************************************************************************
//****************************************************************************
struct
ndb_mgm_configuration
*
ConfigRetriever
::
getConfig
(
int
verId
,
int
nodeType
)
{
int
res
=
init
();
if
(
!
m_handle
)
if
(
res
==
-
1
)
{
m_handle
=
ndb_mgm_create_handle
();
return
0
;
}
if
(
_localConfig
->
items
==
0
)
{
if
(
m_handle
==
0
)
{
setError
(
CR_ERROR
,
"No Management Servers configured in local config fi
le"
);
setError
(
CR_ERROR
,
"Unable to allocate mgm hand
le"
);
return
0
;
return
-
1
;
}
}
int
retry
=
1
;
int
retry
=
1
;
int
retry_max
=
12
;
// Max number of retry attempts
int
retry_max
=
12
;
// Max number of retry attempts
int
retry_interval
=
5
;
// Seconds between each retry
int
retry_interval
=
5
;
// Seconds between each retry
do
{
while
(
retry
<
retry_max
)
{
Uint32
type
=
CR_ERROR
;
Uint32
type
=
CR_ERROR
;
for
(
int
i
=
0
;
i
<
_localConfig
->
items
;
i
++
){
BaseString
tmp
;
MgmtSrvrId
*
m
=
_localConfig
->
ids
[
i
];
for
(
int
i
=
0
;
i
<
_localConfig
.
ids
.
size
();
i
++
){
struct
ndb_mgm_configuration
*
p
=
0
;
MgmtSrvrId
*
m
=
&
_localConfig
.
ids
[
i
]
;
switch
(
m
->
type
){
switch
(
m
->
type
){
case
MgmId_TCP
:
case
MgmId_TCP
:
p
=
getConfig
(
m
->
data
.
tcp
.
remoteHost
,
m
->
data
.
tcp
.
port
,
tmp
.
assfmt
(
"%s:%d"
,
m
->
name
.
c_str
(),
m
->
port
);
verId
,
nodeType
);
if
(
ndb_mgm_connect
(
m_handle
,
tmp
.
c_str
())
==
0
)
{
break
;
return
0
;
}
setError
(
CR_RETRY
,
ndb_mgm_get_latest_error_desc
(
m_handle
));
case
MgmId_File
:
case
MgmId_File
:
p
=
getConfig
(
m
->
data
.
file
.
filename
,
verId
);
break
;
break
;
default:
setError
(
CR_ERROR
,
"Unknown error type"
);
break
;
}
if
(
p
!=
0
)
{
if
(
!
verifyConfig
(
p
,
nodeType
)){
free
(
p
);
return
0
;
}
}
return
p
;
}
}
if
(
latestErrorType
==
CR_RETRY
)
type
=
CR_RETRY
;
}
// for
if
(
t
ype
==
CR_RETRY
){
if
(
latestErrorT
ype
==
CR_RETRY
){
REPORT_WARNING
(
"Failed to retrieve cluster configuration"
);
REPORT_WARNING
(
"Failed to retrieve cluster configuration"
);
ndbout
<<
"(Cause of failure: "
<<
getErrorString
()
<<
")"
<<
endl
;
ndbout
<<
"(Cause of failure: "
<<
getErrorString
()
<<
")"
<<
endl
;
ndbout
<<
"Attempt "
<<
retry
<<
" of "
<<
retry_max
<<
". "
ndbout
<<
"Attempt "
<<
retry
<<
" of "
<<
retry_max
<<
". "
...
@@ -154,82 +118,63 @@ ConfigRetriever::getConfig(int verId, int nodeType) {
...
@@ -154,82 +118,63 @@ ConfigRetriever::getConfig(int verId, int nodeType) {
break
;
break
;
}
}
retry
++
;
retry
++
;
}
}
while
(
retry
<=
retry_max
);
ndb_mgm_destroy_handle
(
&
m_handle
);
m_handle
=
0
;
return
0
;
return
-
1
;
}
}
ndb_mgm_configuration
*
//****************************************************************************
ConfigRetriever
::
getConfig
(
const
char
*
mgmhost
,
//****************************************************************************
short
port
,
//****************************************************************************
int
versionId
,
//****************************************************************************
int
nodetype
){
struct
ndb_mgm_configuration
*
if
(
m_handle
)
{
ConfigRetriever
::
getConfig
()
{
ndb_mgm_disconnect
(
m_handle
);
ndb_mgm_destroy_handle
(
&
m_handle
);
}
m_handle
=
ndb_mgm_create_handle
()
;
struct
ndb_mgm_configuration
*
p
=
0
;
if
(
m_handle
==
0
)
{
if
(
m_handle
!=
0
){
setError
(
CR_ERROR
,
"Unable to allocate mgm handle"
);
p
=
getConfig
(
m_handle
);
return
0
;
}
else
{
for
(
int
i
=
0
;
i
<
_localConfig
.
ids
.
size
();
i
++
){
MgmtSrvrId
*
m
=
&
_localConfig
.
ids
[
i
];
switch
(
m
->
type
){
case
MgmId_File
:
p
=
getConfig
(
m
->
name
.
c_str
());
break
;
case
MgmId_TCP
:
break
;
}
}
if
(
p
)
BaseString
tmp
;
break
;
tmp
.
assfmt
(
"%s:%d"
,
mgmhost
,
port
);
if
(
ndb_mgm_connect
(
m_handle
,
tmp
.
c_str
())
!=
0
)
{
setError
(
CR_RETRY
,
ndb_mgm_get_latest_error_desc
(
m_handle
));
ndb_mgm_destroy_handle
(
&
m_handle
);
m_handle
=
0
;
return
0
;
}
}
}
ndb_mgm_configuration
*
conf
=
ndb_mgm_get_configuration
(
m_handle
,
versionId
);
if
(
p
==
0
)
if
(
conf
==
0
){
setError
(
CR_ERROR
,
ndb_mgm_get_latest_error_desc
(
m_handle
));
ndb_mgm_disconnect
(
m_handle
);
ndb_mgm_destroy_handle
(
&
m_handle
);
m_handle
=
0
;
return
0
;
return
0
;
if
(
!
verifyConfig
(
p
)){
free
(
p
);
p
=
0
;
}
}
{
return
p
;
unsigned
nodeid
=
getOwnNodeId
();
}
int
res
=
ndb_mgm_alloc_nodeid
(
m_handle
,
versionId
,
&
nodeid
,
nodetype
);
ndb_mgm_configuration
*
if
(
res
!=
0
)
{
ConfigRetriever
::
getConfig
(
NdbMgmHandle
m_handle
){
ndb_mgm_configuration
*
conf
=
ndb_mgm_get_configuration
(
m_handle
,
m_version
);
if
(
conf
==
0
){
setError
(
CR_ERROR
,
ndb_mgm_get_latest_error_desc
(
m_handle
));
setError
(
CR_ERROR
,
ndb_mgm_get_latest_error_desc
(
m_handle
));
ndb_mgm_disconnect
(
m_handle
);
ndb_mgm_destroy_handle
(
&
m_handle
);
m_handle
=
0
;
return
0
;
return
0
;
}
}
_ownNodeId
=
nodeid
;
}
return
conf
;
return
conf
;
#if 0
bool compatible;
if (global_ndb_check)
compatible = ndbCompatible_ndb_mgmt(versionId, version);
else
compatible = ndbCompatible_api_mgmt(versionId, version);
if(!compatible){ // if(version != versionId){
NDB_CLOSE_SOCKET(sockfd);
snprintf(err_buf, sizeof(err_buf), "Management Server: Invalid version. "
"Version from server: %d Own version: %d", version, versionId);
setError(CR_ERROR, err_buf);
return 0;
}
#endif
}
}
ndb_mgm_configuration
*
ndb_mgm_configuration
*
ConfigRetriever
::
getConfig
(
const
char
*
filename
,
int
versionId
){
ConfigRetriever
::
getConfig
(
const
char
*
filename
){
struct
stat
sbuf
;
struct
stat
sbuf
;
const
int
res
=
stat
(
filename
,
&
sbuf
);
const
int
res
=
stat
(
filename
,
&
sbuf
);
...
@@ -272,60 +217,29 @@ ConfigRetriever::getConfig(const char * filename, int versionId){
...
@@ -272,60 +217,29 @@ ConfigRetriever::getConfig(const char * filename, int versionId){
void
void
ConfigRetriever
::
setError
(
ErrorType
et
,
const
char
*
s
){
ConfigRetriever
::
setError
(
ErrorType
et
,
const
char
*
s
){
if
(
errorString
!=
0
){
errorString
.
assign
(
s
?
s
:
""
);
free
(
errorString
);
}
if
(
s
==
0
)
errorString
=
0
;
else
errorString
=
strdup
(
s
);
latestErrorType
=
et
;
latestErrorType
=
et
;
}
}
const
char
*
const
char
*
ConfigRetriever
::
getErrorString
(){
ConfigRetriever
::
getErrorString
(){
return
errorString
;
return
errorString
.
c_str
()
;
}
}
void
void
ConfigRetriever
::
setLocalConfigFileName
(
const
char
*
localConfigFileName
)
{
ConfigRetriever
::
setLocalConfigFileName
(
const
char
*
localConfigFileName
)
{
if
(
_localConfigFileName
!=
0
)
_localConfigFileName
.
assign
(
localConfigFileName
?
localConfigFileName
:
""
);
free
(
_localConfigFileName
);
if
(
localConfigFileName
!=
0
)
_localConfigFileName
=
strdup
(
localConfigFileName
);
else
_localConfigFileName
=
0
;
}
}
void
void
ConfigRetriever
::
setConnectString
(
const
char
*
connectString
)
{
ConfigRetriever
::
setConnectString
(
const
char
*
connectString
)
{
if
(
m_connectString
!=
0
)
m_connectString
.
assign
(
connectString
?
connectString
:
""
);
free
(
m_connectString
);
if
(
connectString
!=
0
)
{
m_connectString
=
strdup
(
connectString
);
}
else
{
m_connectString
=
0
;
}
}
/**
* @note Do not use! Use the one above if possible. /elathal
*/
void
ConfigRetriever
::
setDefaultConnectString
(
const
char
*
defaultConnectString
)
{
if
(
m_defaultConnectString
!=
0
)
free
(
m_defaultConnectString
);
if
(
defaultConnectString
!=
0
)
{
m_defaultConnectString
=
strdup
(
defaultConnectString
);
}
else
{
m_defaultConnectString
=
0
;
}
}
}
bool
bool
ConfigRetriever
::
verifyConfig
(
const
struct
ndb_mgm_configuration
*
conf
,
ConfigRetriever
::
verifyConfig
(
const
struct
ndb_mgm_configuration
*
conf
){
int
type
){
char
buf
[
255
];
char
buf
[
255
];
ndb_mgm_configuration_iterator
*
it
;
ndb_mgm_configuration_iterator
*
it
;
it
=
ndb_mgm_create_configuration_iterator
((
struct
ndb_mgm_configuration
*
)
conf
,
CFG_SECTION_NODE
);
it
=
ndb_mgm_create_configuration_iterator
((
struct
ndb_mgm_configuration
*
)
conf
,
CFG_SECTION_NODE
);
...
@@ -338,8 +252,8 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf,
...
@@ -338,8 +252,8 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf,
}
}
NdbAutoPtr
<
ndb_mgm_configuration_iterator
>
ptr
(
it
);
NdbAutoPtr
<
ndb_mgm_configuration_iterator
>
ptr
(
it
);
if
(
ndb_mgm_find
(
it
,
CFG_NODE_ID
,
getOwnNodeId
()
)
!=
0
){
if
(
ndb_mgm_find
(
it
,
CFG_NODE_ID
,
_ownNodeId
)
!=
0
){
snprintf
(
buf
,
255
,
"Unable to find node with id: %d"
,
getOwnNodeId
()
);
snprintf
(
buf
,
255
,
"Unable to find node with id: %d"
,
_ownNodeId
);
setError
(
CR_ERROR
,
buf
);
setError
(
CR_ERROR
,
buf
);
return
false
;
return
false
;
}
}
...
@@ -396,11 +310,27 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf,
...
@@ -396,11 +310,27 @@ ConfigRetriever::verifyConfig(const struct ndb_mgm_configuration * conf,
return
false
;
return
false
;
}
}
if
(
_type
!=
type
){
if
(
_type
!=
m_node_
type
){
snprintf
(
buf
,
255
,
"Supplied node type(%d) and config node type(%d) "
snprintf
(
buf
,
255
,
"Supplied node type(%d) and config node type(%d) "
" don't match"
,
type
,
_type
);
" don't match"
,
m_node_
type
,
_type
);
setError
(
CR_ERROR
,
buf
);
setError
(
CR_ERROR
,
buf
);
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
Uint32
ConfigRetriever
::
allocNodeId
(){
unsigned
nodeid
=
_ownNodeId
;
if
(
m_handle
!=
0
){
int
res
=
ndb_mgm_alloc_nodeid
(
m_handle
,
m_version
,
&
nodeid
,
m_node_type
);
if
(
res
!=
0
)
{
setError
(
CR_ERROR
,
ndb_mgm_get_latest_error_desc
(
m_handle
));
return
0
;
}
}
return
_ownNodeId
=
nodeid
;
}
ndb/src/common/mgmcommon/LocalConfig.cpp
View file @
1add7651
...
@@ -20,16 +20,13 @@
...
@@ -20,16 +20,13 @@
#include <NdbAutoPtr.hpp>
#include <NdbAutoPtr.hpp>
LocalConfig
::
LocalConfig
(){
LocalConfig
::
LocalConfig
(){
ids
=
0
;
size
=
0
;
items
=
0
;
error_line
=
0
;
error_msg
[
0
]
=
0
;
error_line
=
0
;
error_msg
[
0
]
=
0
;
_ownNodeId
=
0
;
_ownNodeId
=
0
;
}
}
bool
bool
LocalConfig
::
init
(
bool
onlyNodeId
,
LocalConfig
::
init
(
const
char
*
connectString
,
const
char
*
connectString
,
const
char
*
fileName
)
{
const
char
*
fileName
,
const
char
*
defaultConnectString
)
{
/**
/**
* Escalation:
* Escalation:
* 1. Check connectString
* 1. Check connectString
...
@@ -41,8 +38,8 @@ LocalConfig::init(bool onlyNodeId,
...
@@ -41,8 +38,8 @@ LocalConfig::init(bool onlyNodeId,
*/
*/
//1. Check connectString
//1. Check connectString
if
(
connectString
!=
0
)
{
if
(
connectString
!=
0
&&
connectString
[
0
]
!=
0
)
{
if
(
readConnectString
(
connectString
,
onlyNodeId
)){
if
(
readConnectString
(
connectString
)){
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -51,7 +48,7 @@ LocalConfig::init(bool onlyNodeId,
...
@@ -51,7 +48,7 @@ LocalConfig::init(bool onlyNodeId,
//2. Check given filename
//2. Check given filename
if
(
fileName
&&
strlen
(
fileName
)
>
0
)
{
if
(
fileName
&&
strlen
(
fileName
)
>
0
)
{
bool
fopenError
;
bool
fopenError
;
if
(
readFile
(
fileName
,
fopenError
,
onlyNodeId
)){
if
(
readFile
(
fileName
,
fopenError
)){
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -61,7 +58,7 @@ LocalConfig::init(bool onlyNodeId,
...
@@ -61,7 +58,7 @@ LocalConfig::init(bool onlyNodeId,
char
buf
[
255
];
char
buf
[
255
];
if
(
NdbEnv_GetEnv
(
"NDB_CONNECTSTRING"
,
buf
,
sizeof
(
buf
))
&&
if
(
NdbEnv_GetEnv
(
"NDB_CONNECTSTRING"
,
buf
,
sizeof
(
buf
))
&&
strlen
(
buf
)
!=
0
){
strlen
(
buf
)
!=
0
){
if
(
readConnectString
(
buf
,
onlyNodeId
)){
if
(
readConnectString
(
buf
)){
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
@@ -72,7 +69,7 @@ LocalConfig::init(bool onlyNodeId,
...
@@ -72,7 +69,7 @@ LocalConfig::init(bool onlyNodeId,
bool
fopenError
;
bool
fopenError
;
char
*
buf
=
NdbConfig_NdbCfgName
(
1
/*true*/
);
char
*
buf
=
NdbConfig_NdbCfgName
(
1
/*true*/
);
NdbAutoPtr
<
char
>
tmp_aptr
(
buf
);
NdbAutoPtr
<
char
>
tmp_aptr
(
buf
);
if
(
readFile
(
buf
,
fopenError
,
onlyNodeId
))
if
(
readFile
(
buf
,
fopenError
))
return
true
;
return
true
;
if
(
!
fopenError
)
if
(
!
fopenError
)
return
false
;
return
false
;
...
@@ -83,24 +80,17 @@ LocalConfig::init(bool onlyNodeId,
...
@@ -83,24 +80,17 @@ LocalConfig::init(bool onlyNodeId,
bool
fopenError
;
bool
fopenError
;
char
*
buf
=
NdbConfig_NdbCfgName
(
0
/*false*/
);
char
*
buf
=
NdbConfig_NdbCfgName
(
0
/*false*/
);
NdbAutoPtr
<
char
>
tmp_aptr
(
buf
);
NdbAutoPtr
<
char
>
tmp_aptr
(
buf
);
if
(
readFile
(
buf
,
fopenError
,
onlyNodeId
))
if
(
readFile
(
buf
,
fopenError
))
return
true
;
return
true
;
if
(
!
fopenError
)
if
(
!
fopenError
)
return
false
;
return
false
;
}
}
//6. Check defaultConnectString
if
(
defaultConnectString
!=
0
)
{
if
(
readConnectString
(
defaultConnectString
,
onlyNodeId
))
return
true
;
return
false
;
}
//7. Check
//7. Check
{
{
char
buf
[
256
];
char
buf
[
256
];
snprintf
(
buf
,
sizeof
(
buf
),
"host=localhost:%u"
,
NDB_BASE_PORT
);
snprintf
(
buf
,
sizeof
(
buf
),
"host=localhost:%u"
,
NDB_BASE_PORT
);
if
(
readConnectString
(
buf
,
onlyNodeId
))
if
(
readConnectString
(
buf
))
return
true
;
return
true
;
}
}
...
@@ -110,28 +100,6 @@ LocalConfig::init(bool onlyNodeId,
...
@@ -110,28 +100,6 @@ LocalConfig::init(bool onlyNodeId,
}
}
LocalConfig
::~
LocalConfig
(){
LocalConfig
::~
LocalConfig
(){
for
(
int
i
=
0
;
i
<
items
;
i
++
){
if
(
ids
[
i
]
->
type
==
MgmId_TCP
)
free
(
ids
[
i
]
->
data
.
tcp
.
remoteHost
);
else
if
(
ids
[
i
]
->
type
==
MgmId_File
)
free
(
ids
[
i
]
->
data
.
file
.
filename
);
delete
ids
[
i
];
}
if
(
ids
!=
0
)
delete
[]
ids
;
}
void
LocalConfig
::
add
(
MgmtSrvrId
*
i
){
if
(
items
==
size
){
MgmtSrvrId
**
tmp
=
new
MgmtSrvrId
*
[
size
+
10
];
if
(
ids
!=
0
){
memcpy
(
tmp
,
ids
,
items
*
sizeof
(
MgmtSrvrId
*
));
delete
[]
ids
;
}
ids
=
tmp
;
}
ids
[
items
]
=
i
;
items
++
;
}
}
void
LocalConfig
::
setError
(
int
lineNumber
,
const
char
*
_msg
)
{
void
LocalConfig
::
setError
(
int
lineNumber
,
const
char
*
_msg
)
{
...
@@ -162,13 +130,13 @@ void LocalConfig::printUsage() const {
...
@@ -162,13 +130,13 @@ void LocalConfig::printUsage() const {
<<
endl
<<
endl
;
<<
endl
<<
endl
;
}
}
char
*
nodeIdTokens
[]
=
{
c
onst
c
har
*
nodeIdTokens
[]
=
{
"OwnProcessId %i"
,
"OwnProcessId %i"
,
"nodeid=%i"
,
"nodeid=%i"
,
0
0
};
};
char
*
hostNameTokens
[]
=
{
c
onst
c
har
*
hostNameTokens
[]
=
{
"host://%[^:]:%i"
,
"host://%[^:]:%i"
,
"host=%[^:]:%i"
,
"host=%[^:]:%i"
,
"%[^:]:%i"
,
"%[^:]:%i"
,
...
@@ -176,7 +144,7 @@ char *hostNameTokens[] = {
...
@@ -176,7 +144,7 @@ char *hostNameTokens[] = {
0
0
};
};
char
*
fileNameTokens
[]
=
{
c
onst
c
har
*
fileNameTokens
[]
=
{
"file://%s"
,
"file://%s"
,
"file=%s"
,
"file=%s"
,
0
0
...
@@ -196,11 +164,11 @@ LocalConfig::parseHostName(const char * buf){
...
@@ -196,11 +164,11 @@ LocalConfig::parseHostName(const char * buf){
int
port
;
int
port
;
for
(
int
i
=
0
;
hostNameTokens
[
i
]
!=
0
;
i
++
)
{
for
(
int
i
=
0
;
hostNameTokens
[
i
]
!=
0
;
i
++
)
{
if
(
sscanf
(
buf
,
hostNameTokens
[
i
],
tempString
,
&
port
)
==
2
)
{
if
(
sscanf
(
buf
,
hostNameTokens
[
i
],
tempString
,
&
port
)
==
2
)
{
MgmtSrvrId
*
mgmtSrvrId
=
new
MgmtSrvrId
()
;
MgmtSrvrId
mgmtSrvrId
;
mgmtSrvrId
->
type
=
MgmId_TCP
;
mgmtSrvrId
.
type
=
MgmId_TCP
;
mgmtSrvrId
->
data
.
tcp
.
remoteHost
=
strdup
(
tempString
);
mgmtSrvrId
.
name
.
assign
(
tempString
);
mgmtSrvrId
->
data
.
tcp
.
port
=
port
;
mgmtSrvrId
.
port
=
port
;
add
(
mgmtSrvrId
);
ids
.
push_back
(
mgmtSrvrId
);
return
true
;
return
true
;
}
}
}
}
...
@@ -212,10 +180,10 @@ LocalConfig::parseFileName(const char * buf){
...
@@ -212,10 +180,10 @@ LocalConfig::parseFileName(const char * buf){
char
tempString
[
1024
];
char
tempString
[
1024
];
for
(
int
i
=
0
;
fileNameTokens
[
i
]
!=
0
;
i
++
)
{
for
(
int
i
=
0
;
fileNameTokens
[
i
]
!=
0
;
i
++
)
{
if
(
sscanf
(
buf
,
fileNameTokens
[
i
],
tempString
)
==
1
)
{
if
(
sscanf
(
buf
,
fileNameTokens
[
i
],
tempString
)
==
1
)
{
MgmtSrvrId
*
mgmtSrvrId
=
new
MgmtSrvrId
()
;
MgmtSrvrId
mgmtSrvrId
;
mgmtSrvrId
->
type
=
MgmId_File
;
mgmtSrvrId
.
type
=
MgmId_File
;
mgmtSrvrId
->
data
.
file
.
filename
=
strdup
(
tempString
);
mgmtSrvrId
.
name
.
assign
(
tempString
);
add
(
mgmtSrvrId
);
ids
.
push_back
(
mgmtSrvrId
);
return
true
;
return
true
;
}
}
}
}
...
@@ -223,7 +191,7 @@ LocalConfig::parseFileName(const char * buf){
...
@@ -223,7 +191,7 @@ LocalConfig::parseFileName(const char * buf){
}
}
bool
bool
LocalConfig
::
parseString
(
const
char
*
connectString
,
bool
onlyNodeId
,
char
*
line
){
LocalConfig
::
parseString
(
const
char
*
connectString
,
char
*
line
){
char
*
for_strtok
;
char
*
for_strtok
;
char
*
copy
=
strdup
(
connectString
);
char
*
copy
=
strdup
(
connectString
);
NdbAutoPtr
<
char
>
tmp_aptr
(
copy
);
NdbAutoPtr
<
char
>
tmp_aptr
(
copy
);
...
@@ -231,8 +199,7 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
...
@@ -231,8 +199,7 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
bool
b_nodeId
=
false
;
bool
b_nodeId
=
false
;
bool
found_other
=
false
;
bool
found_other
=
false
;
for
(
char
*
tok
=
strtok_r
(
copy
,
";"
,
&
for_strtok
);
for
(
char
*
tok
=
strtok_r
(
copy
,
";"
,
&
for_strtok
);
tok
!=
0
;
tok
!=
0
&&
!
(
onlyNodeId
&&
b_nodeId
);
tok
=
strtok_r
(
NULL
,
";"
,
&
for_strtok
))
{
tok
=
strtok_r
(
NULL
,
";"
,
&
for_strtok
))
{
if
(
tok
[
0
]
==
'#'
)
continue
;
if
(
tok
[
0
]
==
'#'
)
continue
;
...
@@ -240,8 +207,6 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
...
@@ -240,8 +207,6 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
if
(
!
b_nodeId
)
// only one nodeid definition allowed
if
(
!
b_nodeId
)
// only one nodeid definition allowed
if
(
b_nodeId
=
parseNodeId
(
tok
))
if
(
b_nodeId
=
parseNodeId
(
tok
))
continue
;
continue
;
if
(
onlyNodeId
)
continue
;
if
(
found_other
=
parseHostName
(
tok
))
if
(
found_other
=
parseHostName
(
tok
))
continue
;
continue
;
if
(
found_other
=
parseFileName
(
tok
))
if
(
found_other
=
parseFileName
(
tok
))
...
@@ -252,16 +217,17 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
...
@@ -252,16 +217,17 @@ LocalConfig::parseString(const char * connectString, bool onlyNodeId, char *line
return
false
;
return
false
;
}
}
if
(
!
onlyNodeId
&&
!
found_other
)
{
if
(
!
found_other
)
{
if
(
line
)
if
(
line
)
snprintf
(
line
,
150
,
"Missing host/file name extry in
\"
%s
\"
"
,
connectString
);
snprintf
(
line
,
150
,
"Missing host/file name extry in
\"
%s
\"
"
,
connectString
);
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
bool
LocalConfig
::
readFile
(
const
char
*
filename
,
bool
&
fopenError
,
bool
onlyNodeId
)
bool
LocalConfig
::
readFile
(
const
char
*
filename
,
bool
&
fopenError
)
{
{
char
line
[
150
],
line2
[
150
];
char
line
[
150
],
line2
[
150
];
...
@@ -292,7 +258,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod
...
@@ -292,7 +258,7 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod
strcat
(
theString
,
line
);
strcat
(
theString
,
line
);
}
}
bool
return_value
=
parseString
(
theString
,
onlyNodeId
,
line
);
bool
return_value
=
parseString
(
theString
,
line
);
if
(
!
return_value
)
{
if
(
!
return_value
)
{
snprintf
(
line2
,
150
,
"Reading %s: %s"
,
filename
,
line
);
snprintf
(
line2
,
150
,
"Reading %s: %s"
,
filename
,
line
);
...
@@ -305,9 +271,9 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod
...
@@ -305,9 +271,9 @@ bool LocalConfig::readFile(const char * filename, bool &fopenError, bool onlyNod
}
}
bool
bool
LocalConfig
::
readConnectString
(
const
char
*
connectString
,
bool
onlyNodeId
){
LocalConfig
::
readConnectString
(
const
char
*
connectString
){
char
line
[
150
],
line2
[
150
];
char
line
[
150
],
line2
[
150
];
bool
return_value
=
parseString
(
connectString
,
onlyNodeId
,
line
);
bool
return_value
=
parseString
(
connectString
,
line
);
if
(
!
return_value
)
{
if
(
!
return_value
)
{
snprintf
(
line2
,
150
,
"Reading NDB_CONNECTSTRING
\"
%s
\"
: %s"
,
connectString
,
line
);
snprintf
(
line2
,
150
,
"Reading NDB_CONNECTSTRING
\"
%s
\"
: %s"
,
connectString
,
line
);
setError
(
0
,
line2
);
setError
(
0
,
line2
);
...
...
ndb/src/kernel/main.cpp
View file @
1add7651
...
@@ -69,7 +69,8 @@ NDB_MAIN(ndb_kernel){
...
@@ -69,7 +69,8 @@ NDB_MAIN(ndb_kernel){
}
}
{
// Do configuration
{
// Do configuration
theConfig
->
setupConfiguration
();
signal
(
SIGPIPE
,
SIG_IGN
);
theConfig
->
fetch_configuration
();
}
}
if
(
theConfig
->
getDaemonMode
())
{
if
(
theConfig
->
getDaemonMode
())
{
...
@@ -88,8 +89,6 @@ NDB_MAIN(ndb_kernel){
...
@@ -88,8 +89,6 @@ NDB_MAIN(ndb_kernel){
/**
/**
* Parent
* Parent
*/
*/
theConfig
->
closeConfiguration
();
catchsigs
(
true
);
catchsigs
(
true
);
int
status
=
0
;
int
status
=
0
;
...
@@ -132,9 +131,11 @@ NDB_MAIN(ndb_kernel){
...
@@ -132,9 +131,11 @@ NDB_MAIN(ndb_kernel){
exit
(
0
);
exit
(
0
);
}
}
g_eventLogger
.
info
(
"Ndb has terminated (pid %d) restarting"
,
child
);
g_eventLogger
.
info
(
"Ndb has terminated (pid %d) restarting"
,
child
);
theConfig
->
fetch_configuration
();
}
}
g_eventLogger
.
info
(
"Angel pid: %d ndb pid: %d"
,
getppid
(),
getpid
());
g_eventLogger
.
info
(
"Angel pid: %d ndb pid: %d"
,
getppid
(),
getpid
());
theConfig
->
setupConfiguration
();
systemInfo
(
*
theConfig
,
*
theConfig
->
m_logLevel
);
systemInfo
(
*
theConfig
,
*
theConfig
->
m_logLevel
);
// Load blocks
// Load blocks
...
...
ndb/src/kernel/vm/Configuration.cpp
View file @
1add7651
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include <ndb_limits.h>
#include <ndb_limits.h>
#include "pc.hpp"
#include "pc.hpp"
#include <LogLevel.hpp>
#include <LogLevel.hpp>
#include <NdbSleep.h>
extern
"C"
{
extern
"C"
{
void
ndbSetOwnVersion
();
void
ndbSetOwnVersion
();
...
@@ -153,19 +154,45 @@ Configuration::closeConfiguration(){
...
@@ -153,19 +154,45 @@ Configuration::closeConfiguration(){
}
}
void
void
Configuration
::
setupC
onfiguration
(){
Configuration
::
fetch_c
onfiguration
(){
/**
/**
* Fetch configuration from management server
* Fetch configuration from management server
*/
*/
if
(
m_config_retriever
)
{
if
(
m_config_retriever
)
{
delete
m_config_retriever
;
delete
m_config_retriever
;
}
}
m_config_retriever
=
new
ConfigRetriever
();
m_config_retriever
=
new
ConfigRetriever
(
NDB_VERSION
,
NODE_TYPE_DB
);
m_config_retriever
->
setConnectString
(
_connectString
?
_connectString
:
""
);
if
(
m_config_retriever
->
init
()
==
-
1
||
m_config_retriever
->
do_connect
()
==
-
1
){
const
char
*
s
=
m_config_retriever
->
getErrorString
();
if
(
s
==
0
)
s
=
"No error given!"
;
/* Set stop on error to true otherwise NDB will
go into an restart loop...
*/
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Could connect to ndb_mgmd"
,
s
);
}
ConfigRetriever
&
cr
=
*
m_config_retriever
;
ConfigRetriever
&
cr
=
*
m_config_retriever
;
cr
.
setConnectString
(
_connectString
);
if
((
globalData
.
ownId
=
cr
.
allocNodeId
())
==
0
){
stopOnError
(
true
);
for
(
Uint32
i
=
0
;
i
<
3
;
i
++
){
ndb_mgm_configuration
*
p
=
cr
.
getConfig
(
NDB_VERSION
,
NODE_TYPE_DB
);
NdbSleep_SecSleep
(
3
);
if
(
globalData
.
ownId
=
cr
.
allocNodeId
())
break
;
}
}
if
(
globalData
.
ownId
==
0
){
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Unable to alloc node id"
,
m_config_retriever
->
getErrorString
());
}
ndb_mgm_configuration
*
p
=
cr
.
getConfig
();
if
(
p
==
0
){
if
(
p
==
0
){
const
char
*
s
=
cr
.
getErrorString
();
const
char
*
s
=
cr
.
getErrorString
();
if
(
s
==
0
)
if
(
s
==
0
)
...
@@ -178,14 +205,31 @@ Configuration::setupConfiguration(){
...
@@ -178,14 +205,31 @@ Configuration::setupConfiguration(){
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Could not fetch configuration"
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Could not fetch configuration"
"/invalid configuration"
,
s
);
"/invalid configuration"
,
s
);
}
}
if
(
m_clusterConfig
)
free
(
m_clusterConfig
);
m_clusterConfig
=
p
;
ndb_mgm_configuration_iterator
iter
(
*
p
,
CFG_SECTION_NODE
);
if
(
iter
.
find
(
CFG_NODE_ID
,
globalData
.
ownId
)){
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Invalid configuration fetched"
,
"DB missing"
);
}
Uint32
nodeId
=
globalData
.
ownId
=
cr
.
getOwnNodeId
();
if
(
iter
.
get
(
CFG_DB_STOP_ON_ERROR
,
&
_stopOnError
)){
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Invalid configuration fetched"
,
"StopOnError missing"
);
}
}
void
Configuration
::
setupConfiguration
(){
ndb_mgm_configuration
*
p
=
m_clusterConfig
;
/**
/**
* Configure transporters
* Configure transporters
*/
*/
{
{
int
res
=
IPCConfig
::
configureTransporters
(
nodeId
,
int
res
=
IPCConfig
::
configureTransporters
(
globalData
.
ownId
,
*
p
,
*
p
,
globalTransporterRegistry
);
globalTransporterRegistry
);
if
(
res
<=
0
){
if
(
res
<=
0
){
...
@@ -247,11 +291,6 @@ Configuration::setupConfiguration(){
...
@@ -247,11 +291,6 @@ Configuration::setupConfiguration(){
}
}
}
}
if
(
iter
.
get
(
CFG_DB_STOP_ON_ERROR
,
&
_stopOnError
)){
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Invalid configuration fetched"
,
"StopOnError missing"
);
}
if
(
iter
.
get
(
CFG_DB_STOP_ON_ERROR_INSERT
,
&
m_restartOnErrorInsert
)){
if
(
iter
.
get
(
CFG_DB_STOP_ON_ERROR_INSERT
,
&
m_restartOnErrorInsert
)){
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Invalid configuration fetched"
,
ERROR_SET
(
fatal
,
ERR_INVALID_CONFIG
,
"Invalid configuration fetched"
,
"RestartOnErrorInsert missing"
);
"RestartOnErrorInsert missing"
);
...
@@ -268,7 +307,6 @@ Configuration::setupConfiguration(){
...
@@ -268,7 +307,6 @@ Configuration::setupConfiguration(){
ConfigValues
*
cf
=
ConfigValuesFactory
::
extractCurrentSection
(
iter
.
m_config
);
ConfigValues
*
cf
=
ConfigValuesFactory
::
extractCurrentSection
(
iter
.
m_config
);
m_clusterConfig
=
p
;
m_clusterConfigIter
=
ndb_mgm_create_configuration_iterator
m_clusterConfigIter
=
ndb_mgm_create_configuration_iterator
(
p
,
CFG_SECTION_NODE
);
(
p
,
CFG_SECTION_NODE
);
...
...
ndb/src/kernel/vm/Configuration.hpp
View file @
1add7651
...
@@ -32,6 +32,7 @@ public:
...
@@ -32,6 +32,7 @@ public:
*/
*/
bool
init
(
int
argc
,
const
char
**
argv
);
bool
init
(
int
argc
,
const
char
**
argv
);
void
fetch_configuration
();
void
setupConfiguration
();
void
setupConfiguration
();
void
closeConfiguration
();
void
closeConfiguration
();
...
...
ndb/src/mgmapi/mgmapi.cpp
View file @
1add7651
...
@@ -1438,11 +1438,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) {
...
@@ -1438,11 +1438,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) {
const
Properties
*
prop
;
const
Properties
*
prop
;
prop
=
ndb_mgm_call
(
handle
,
reply
,
"get config"
,
&
args
);
prop
=
ndb_mgm_call
(
handle
,
reply
,
"get config"
,
&
args
);
CHECK_REPLY
(
prop
,
0
);
if
(
prop
==
NULL
)
{
SET_ERROR
(
handle
,
EIO
,
"Unable to fetch config"
);
return
0
;
}
do
{
do
{
const
char
*
buf
;
const
char
*
buf
;
...
@@ -1537,17 +1533,14 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodei
...
@@ -1537,17 +1533,14 @@ ndb_mgm_alloc_nodeid(NdbMgmHandle handle, unsigned int version, unsigned *pnodei
const
Properties
*
prop
;
const
Properties
*
prop
;
prop
=
ndb_mgm_call
(
handle
,
reply
,
"get nodeid"
,
&
args
);
prop
=
ndb_mgm_call
(
handle
,
reply
,
"get nodeid"
,
&
args
);
CHECK_REPLY
(
prop
,
-
1
);
if
(
prop
==
NULL
)
{
SET_ERROR
(
handle
,
EIO
,
"Unable to alloc nodeid"
);
return
-
1
;
}
int
res
=
-
1
;
int
res
=
-
1
;
do
{
do
{
const
char
*
buf
;
const
char
*
buf
;
if
(
!
prop
->
get
(
"result"
,
&
buf
)
||
strcmp
(
buf
,
"Ok"
)
!=
0
){
if
(
!
prop
->
get
(
"result"
,
&
buf
)
||
strcmp
(
buf
,
"Ok"
)
!=
0
){
ndbout_c
(
"ERROR Message: %s
\n
"
,
buf
);
setError
(
handle
,
NDB_MGM_COULD_NOT_CONNECT_TO_SOCKET
,
__LINE__
,
"Could not alloc node id: %s"
,
buf
);
break
;
break
;
}
}
if
(
!
prop
->
get
(
"nodeid"
,
pnodeid
)
!=
0
){
if
(
!
prop
->
get
(
"nodeid"
,
pnodeid
)
!=
0
){
...
@@ -1621,11 +1614,7 @@ ndb_mgm_set_int_parameter(NdbMgmHandle handle,
...
@@ -1621,11 +1614,7 @@ ndb_mgm_set_int_parameter(NdbMgmHandle handle,
const
Properties
*
prop
;
const
Properties
*
prop
;
prop
=
ndb_mgm_call
(
handle
,
reply
,
"set parameter"
,
&
args
);
prop
=
ndb_mgm_call
(
handle
,
reply
,
"set parameter"
,
&
args
);
CHECK_REPLY
(
prop
,
-
1
);
if
(
prop
==
NULL
)
{
SET_ERROR
(
handle
,
EIO
,
"Unable set parameter"
);
return
-
1
;
}
int
res
=
-
1
;
int
res
=
-
1
;
do
{
do
{
...
...
ndb/src/mgmclient/main.cpp
View file @
1add7651
...
@@ -47,10 +47,6 @@ handler(int sig){
...
@@ -47,10 +47,6 @@ handler(int sig){
int
main
(
int
argc
,
const
char
**
argv
){
int
main
(
int
argc
,
const
char
**
argv
){
int
optind
=
0
;
int
optind
=
0
;
char
_default_connectstring_buf
[
256
];
snprintf
(
_default_connectstring_buf
,
sizeof
(
_default_connectstring_buf
),
"host=localhost:%u"
,
NDB_BASE_PORT
);
const
char
*
_default_connectstring
=
_default_connectstring_buf
;
const
char
*
_host
=
0
;
const
char
*
_host
=
0
;
int
_port
=
0
;
int
_port
=
0
;
int
_help
=
0
;
int
_help
=
0
;
...
@@ -79,9 +75,9 @@ int main(int argc, const char** argv){
...
@@ -79,9 +75,9 @@ int main(int argc, const char** argv){
_port
=
atoi
(
argv
[
1
]);
_port
=
atoi
(
argv
[
1
]);
}
}
}
else
{
}
else
{
if
(
cfg
.
init
(
false
,
0
,
0
,
_default_connectstring
)
&&
cfg
.
items
>
0
&&
cfg
.
ids
[
0
]
->
type
==
MgmId_TCP
){
if
(
cfg
.
init
(
0
,
0
)
&&
cfg
.
ids
.
size
()
>
0
&&
cfg
.
ids
[
0
].
type
==
MgmId_TCP
){
_host
=
cfg
.
ids
[
0
]
->
data
.
tcp
.
remoteHost
;
_host
=
cfg
.
ids
[
0
]
.
name
.
c_str
()
;
_port
=
cfg
.
ids
[
0
]
->
data
.
tcp
.
port
;
_port
=
cfg
.
ids
[
0
].
port
;
}
else
{
}
else
{
cfg
.
printError
();
cfg
.
printError
();
cfg
.
printUsage
();
cfg
.
printUsage
();
...
...
ndb/src/mgmsrv/MgmtSrvr.cpp
View file @
1add7651
...
@@ -584,18 +584,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
...
@@ -584,18 +584,11 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
_ownNodeId
=
0
;
_ownNodeId
=
0
;
NodeId
tmp
=
nodeId
;
NodeId
tmp
=
nodeId
;
if
(
getFreeNodeId
(
&
tmp
,
NDB_MGM_NODE_TYPE_MGM
,
0
,
0
)){
if
(
!
alloc_node_id
(
&
tmp
,
NDB_MGM_NODE_TYPE_MGM
,
0
,
0
)){
_ownNodeId
=
tmp
;
ndbout
<<
"Unable to obtain requested nodeid "
<<
nodeId
;
if
(
nodeId
!=
0
&&
nodeId
!=
tmp
)
{
ndbout
<<
"Unable to obtain requested nodeid "
<<
nodeId
<<
" nodeid "
<<
tmp
<<
" available
\n
"
;
_ownNodeId
=
0
;
// did not get nodeid requested
}
m_allocated_resources
.
reserve_node
(
_ownNodeId
);
}
else
{
ndbout_c
(
"Unable to retrieve own node id"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
_ownNodeId
=
tmp
;
}
}
...
@@ -2301,10 +2294,19 @@ MgmtSrvr::getNodeType(NodeId nodeId) const
...
@@ -2301,10 +2294,19 @@ MgmtSrvr::getNodeType(NodeId nodeId) const
return
nodeTypes
[
nodeId
];
return
nodeTypes
[
nodeId
];
}
}
#ifdef NDB_WIN32
static
NdbMutex
&
f_node_id_mutex
=
*
NdbMutex_Create
();
#else
static
NdbMutex
f_node_id_mutex
=
NDB_MUTEX_INITIALIZER
;
#endif
bool
bool
MgmtSrvr
::
getFreeNodeId
(
NodeId
*
nodeId
,
enum
ndb_mgm_node_type
type
,
MgmtSrvr
::
alloc_node_id
(
NodeId
*
nodeId
,
struct
sockaddr
*
client_addr
,
socklen_t
*
client_addr_len
)
const
enum
ndb_mgm_node_type
type
,
struct
sockaddr
*
client_addr
,
socklen_t
*
client_addr_len
)
{
{
Guard
g
(
&
f_node_id_mutex
);
#if 0
#if 0
ndbout << "MgmtSrvr::getFreeNodeId type=" << type
ndbout << "MgmtSrvr::getFreeNodeId type=" << type
<< " *nodeid=" << *nodeId << endl;
<< " *nodeid=" << *nodeId << endl;
...
@@ -2365,6 +2367,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type,
...
@@ -2365,6 +2367,7 @@ MgmtSrvr::getFreeNodeId(NodeId * nodeId, enum ndb_mgm_node_type type,
}
}
}
}
*
nodeId
=
tmp
;
*
nodeId
=
tmp
;
m_reserved_nodes
.
set
(
tmp
);
#if 0
#if 0
ndbout << "MgmtSrvr::getFreeNodeId found type=" << type
ndbout << "MgmtSrvr::getFreeNodeId found type=" << type
<< " *nodeid=" << *nodeId << endl;
<< " *nodeid=" << *nodeId << endl;
...
@@ -2769,6 +2772,7 @@ MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m)
...
@@ -2769,6 +2772,7 @@ MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m)
MgmtSrvr
::
Allocated_resources
::~
Allocated_resources
()
MgmtSrvr
::
Allocated_resources
::~
Allocated_resources
()
{
{
Guard
g
(
&
f_node_id_mutex
);
m_mgmsrv
.
m_reserved_nodes
.
bitANDC
(
m_reserved_nodes
);
m_mgmsrv
.
m_reserved_nodes
.
bitANDC
(
m_reserved_nodes
);
}
}
...
@@ -2776,7 +2780,6 @@ void
...
@@ -2776,7 +2780,6 @@ void
MgmtSrvr
::
Allocated_resources
::
reserve_node
(
NodeId
id
)
MgmtSrvr
::
Allocated_resources
::
reserve_node
(
NodeId
id
)
{
{
m_reserved_nodes
.
set
(
id
);
m_reserved_nodes
.
set
(
id
);
m_mgmsrv
.
m_reserved_nodes
.
set
(
id
);
}
}
int
int
...
...
ndb/src/mgmsrv/MgmtSrvr.hpp
View file @
1add7651
...
@@ -78,6 +78,7 @@ public:
...
@@ -78,6 +78,7 @@ public:
// methods to reserve/allocate resources which
// methods to reserve/allocate resources which
// will be freed when running destructor
// will be freed when running destructor
void
reserve_node
(
NodeId
id
);
void
reserve_node
(
NodeId
id
);
bool
is_reserved
(
NodeId
nodeId
)
{
return
m_reserved_nodes
.
get
(
nodeId
);}
private:
private:
MgmtSrvr
&
m_mgmsrv
;
MgmtSrvr
&
m_mgmsrv
;
NodeBitmask
m_reserved_nodes
;
NodeBitmask
m_reserved_nodes
;
...
@@ -465,8 +466,8 @@ public:
...
@@ -465,8 +466,8 @@ public:
* @return false if none found
* @return false if none found
*/
*/
bool
getNextNodeId
(
NodeId
*
_nodeId
,
enum
ndb_mgm_node_type
type
)
const
;
bool
getNextNodeId
(
NodeId
*
_nodeId
,
enum
ndb_mgm_node_type
type
)
const
;
bool
getFreeNodeI
d
(
NodeId
*
_nodeId
,
enum
ndb_mgm_node_type
type
,
bool
alloc_node_i
d
(
NodeId
*
_nodeId
,
enum
ndb_mgm_node_type
type
,
struct
sockaddr
*
client_addr
,
socklen_t
*
client_addr_len
)
const
;
struct
sockaddr
*
client_addr
,
socklen_t
*
client_addr_len
);
/**
/**
*
*
...
...
ndb/src/mgmsrv/MgmtSrvrConfig.cpp
View file @
1add7651
...
@@ -288,10 +288,9 @@ MgmtSrvr::readConfig() {
...
@@ -288,10 +288,9 @@ MgmtSrvr::readConfig() {
Config
*
Config
*
MgmtSrvr
::
fetchConfig
()
{
MgmtSrvr
::
fetchConfig
()
{
ConfigRetriever
cr
;
ConfigRetriever
cr
(
NDB_VERSION
,
NODE_TYPE_MGM
)
;
cr
.
setLocalConfigFileName
(
m_localNdbConfigFilename
.
c_str
());
cr
.
setLocalConfigFileName
(
m_localNdbConfigFilename
.
c_str
());
struct
ndb_mgm_configuration
*
tmp
=
cr
.
getConfig
(
NDB_VERSION
,
struct
ndb_mgm_configuration
*
tmp
=
cr
.
getConfig
();
NODE_TYPE_MGM
);
if
(
tmp
!=
0
){
if
(
tmp
!=
0
){
Config
*
conf
=
new
Config
();
Config
*
conf
=
new
Config
();
conf
->
m_configValues
=
tmp
;
conf
->
m_configValues
=
tmp
;
...
...
ndb/src/mgmsrv/Services.cpp
View file @
1add7651
...
@@ -401,32 +401,24 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
...
@@ -401,32 +401,24 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
struct
sockaddr
addr
;
struct
sockaddr
addr
;
socklen_t
addrlen
=
sizeof
(
addr
);
socklen_t
addrlen
=
sizeof
(
addr
);
int
r
;
int
r
=
getpeername
(
m_socket
,
&
addr
,
&
addrlen
)
;
if
(
r
=
getpeername
(
m_socket
,
&
addr
,
&
addrlen
)
)
{
if
(
r
!=
0
)
{
m_output
->
println
(
cmd
);
m_output
->
println
(
cmd
);
m_output
->
println
(
"result: getpeername(%d) failed, err= %d"
,
m_socket
,
r
);
m_output
->
println
(
"result: getpeername(%d) failed, err= %d"
,
m_socket
,
r
);
m_output
->
println
(
""
);
m_output
->
println
(
""
);
return
;
return
;
}
}
NodeId
free_id
=
0
;
NodeId
tmp
=
nodeid
;
NodeId
tmp
=
nodeid
;
if
(
m_mgmsrv
.
getFreeNodeId
(
&
tmp
,
(
enum
ndb_mgm_node_type
)
nodetype
,
&
addr
,
&
addrlen
))
if
(
tmp
==
0
||
!
m_allocated_resources
->
is_reserved
(
tmp
)){
free_id
=
tmp
;
if
(
!
m_mgmsrv
.
alloc_node_id
(
&
tmp
,
(
enum
ndb_mgm_node_type
)
nodetype
,
&
addr
,
&
addrlen
)){
if
(
nodeid
!=
0
&&
free_id
!=
nodeid
){
m_output
->
println
(
cmd
);
m_output
->
println
(
cmd
);
m_output
->
println
(
"result: no free nodeid %d for nodetype %d"
,
m_output
->
println
(
"result: no free nodeid %d for nodetype %d"
,
nodeid
,
nodetype
);
nodeid
,
nodetype
);
m_output
->
println
(
""
);
m_output
->
println
(
""
);
return
;
return
;
}
}
if
(
free_id
==
0
){
m_output
->
println
(
cmd
);
m_output
->
println
(
"result: no free nodeid for nodetype %d"
,
nodetype
);
m_output
->
println
(
""
);
return
;
}
}
#if 0
#if 0
...
@@ -440,11 +432,10 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
...
@@ -440,11 +432,10 @@ MgmApiSession::get_nodeid(Parser_t::Context &,
#endif
#endif
m_output
->
println
(
cmd
);
m_output
->
println
(
cmd
);
m_output
->
println
(
"nodeid: %u"
,
free_id
);
m_output
->
println
(
"nodeid: %u"
,
tmp
);
m_output
->
println
(
"result: Ok"
);
m_output
->
println
(
"result: Ok"
);
m_output
->
println
(
""
);
m_output
->
println
(
""
);
m_allocated_resources
->
reserve_node
(
tmp
);
m_allocated_resources
->
reserve_node
(
free_id
);
return
;
return
;
}
}
...
...
ndb/src/mgmsrv/main.cpp
View file @
1add7651
...
@@ -16,8 +16,6 @@
...
@@ -16,8 +16,6 @@
#include <ndb_global.h>
#include <ndb_global.h>
#include <signal.h>
#include "MgmtSrvr.hpp"
#include "MgmtSrvr.hpp"
#include "EventLogger.hpp"
#include "EventLogger.hpp"
#include <Config.hpp>
#include <Config.hpp>
...
@@ -229,6 +227,7 @@ NDB_MAIN(mgmsrv){
...
@@ -229,6 +227,7 @@ NDB_MAIN(mgmsrv){
}
}
}
}
signal
(
SIGPIPE
,
SIG_IGN
);
if
(
!
glob
.
mgmObject
->
start
()){
if
(
!
glob
.
mgmObject
->
start
()){
ndbout_c
(
"Unable to start management server."
);
ndbout_c
(
"Unable to start management server."
);
ndbout_c
(
"Probably caused by illegal initial configuration file."
);
ndbout_c
(
"Probably caused by illegal initial configuration file."
);
...
@@ -312,14 +311,13 @@ MgmGlobals::~MgmGlobals(){
...
@@ -312,14 +311,13 @@ MgmGlobals::~MgmGlobals(){
static
bool
static
bool
readLocalConfig
(){
readLocalConfig
(){
// Read local config file
// Read local config file
ConfigRetriever
cr
;
LocalConfig
lc
;
cr
.
setLocalConfigFileName
(
glob
.
local_config_filename
);
int
nodeid
=
lc
.
init
(
glob
.
local_config_filename
);
int
nodeid
=
cr
.
init
(
true
);
if
(
nodeid
==
-
1
){
if
(
nodeid
==
-
1
){
return
false
;
return
false
;
}
}
glob
.
localNodeId
=
(
NodeId
)
nodeid
;
glob
.
localNodeId
=
nodeid
;
return
true
;
return
true
;
}
}
...
@@ -342,17 +340,6 @@ readGlobalConfig() {
...
@@ -342,17 +340,6 @@ readGlobalConfig() {
InitConfigFileParser
parser
;
InitConfigFileParser
parser
;
glob
.
cluster_config
=
parser
.
parseConfig
(
glob
.
config_filename
);
glob
.
cluster_config
=
parser
.
parseConfig
(
glob
.
config_filename
);
if
(
glob
.
cluster_config
==
0
){
if
(
glob
.
cluster_config
==
0
){
/**
* Try to get configuration from other MGM server
* Note: Only new format
*/
glob
.
cluster_config
=
new
Config
();
ConfigRetriever
cr
;
cr
.
setLocalConfigFileName
(
glob
.
local_config_filename
);
glob
.
cluster_config
->
m_configValues
=
cr
.
getConfig
(
NDB_VERSION
,
NODE_TYPE_MGM
);
if
(
glob
.
cluster_config
->
m_configValues
==
NULL
)
return
false
;
return
false
;
}
}
return
true
;
return
true
;
...
...
ndb/src/ndbapi/TransporterFacade.cpp
View file @
1add7651
...
@@ -343,27 +343,39 @@ TransporterFacade*
...
@@ -343,27 +343,39 @@ TransporterFacade*
TransporterFacade
::
start_instance
(
const
char
*
connectString
){
TransporterFacade
::
start_instance
(
const
char
*
connectString
){
// TransporterFacade used from API get config from mgmt srvr
// TransporterFacade used from API get config from mgmt srvr
s_config_retriever
=
new
ConfigRetriever
;
s_config_retriever
=
new
ConfigRetriever
(
NDB_VERSION
,
NODE_TYPE_API
);
s_config_retriever
->
setConnectString
(
connectString
);
const
char
*
error
=
0
;
do
{
if
(
s_config_retriever
->
init
()
==
-
1
)
break
;
if
(
s_config_retriever
->
do_connect
()
==
-
1
)
break
;
const
Uint32
nodeId
=
s_config_retriever
->
allocNodeId
();
if
(
nodeId
==
0
)
break
;
ndb_mgm_configuration
*
props
=
s_config_retriever
->
getConfig
();
if
(
props
==
0
)
break
;
TransporterFacade
*
tf
=
start_instance
(
nodeId
,
props
);
free
(
props
);
return
tf
;
}
while
(
0
);
ConfigRetriever
&
configRetriever
=
*
s_config_retriever
;
configRetriever
.
setConnectString
(
connectString
);
ndb_mgm_configuration
*
props
=
configRetriever
.
getConfig
(
NDB_VERSION
,
NODE_TYPE_API
);
if
(
props
==
0
)
{
ndbout
<<
"Configuration error: "
;
ndbout
<<
"Configuration error: "
;
const
char
*
erString
=
configRetriever
.
getErrorString
();
const
char
*
erString
=
s_config_retriever
->
getErrorString
();
if
(
erString
==
0
)
{
if
(
erString
==
0
)
{
erString
=
"No error specified!"
;
erString
=
"No error specified!"
;
}
}
ndbout
<<
erString
<<
endl
;
ndbout
<<
erString
<<
endl
;
return
0
;
return
0
;
}
const
int
nodeId
=
configRetriever
.
getOwnNodeId
();
TransporterFacade
*
tf
=
start_instance
(
nodeId
,
props
);
free
(
props
);
return
tf
;
}
}
TransporterFacade
*
TransporterFacade
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment