1 /*
2    Copyright (c) 2003, 2021, Oracle and/or its affiliates.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NODE_INFO_HPP
26 #define NODE_INFO_HPP
27 
28 #include <NdbOut.hpp>
29 #include <mgmapi_config_parameters.h>
30 #include <ndb_version.h>
31 
32 #define JAM_FILE_ID 0
33 
34 
35 class NodeInfo {
36 public:
37   NodeInfo();
38 
39   /**
40    * NodeType
41    */
42   enum NodeType {
43     DB  = NODE_TYPE_DB,      ///< Database node
44     API = NODE_TYPE_API,      ///< NDB API node
45     MGM = NODE_TYPE_MGM,      ///< Management node  (incl. NDB API)
46     INVALID = 255 ///< Invalid type
47   };
48   NodeType getType() const;
49 
50   Uint32 m_version;       ///< Ndb version
51   Uint32 m_mysql_version; ///< MySQL version
52   Uint32 m_lqh_workers;   ///< LQH workers
53   Uint32 m_type;          ///< Node type
54   Uint32 m_connectCount;  ///< No of times connected
55   Uint32 m_connected;     ///< Node is connected
56 
57   friend NdbOut & operator<<(NdbOut&, const NodeInfo&);
58 };
59 
60 
61 inline
NodeInfo()62 NodeInfo::NodeInfo(){
63   m_version = 0;
64   m_mysql_version = 0;
65   m_lqh_workers = 0;
66   m_type = INVALID;
67   m_connectCount = 0;
68 }
69 
70 inline
71 NodeInfo::NodeType
getType() const72 NodeInfo::getType() const {
73   return (NodeType)m_type;
74 }
75 
76 
77 class NdbVersion {
78   Uint32 m_ver;
79 public:
NdbVersion(Uint32 ver)80   NdbVersion(Uint32 ver) : m_ver(ver) {};
81 
82   friend NdbOut& operator<<(NdbOut&, const NdbVersion&);
83 };
84 
85 
86 inline
87 NdbOut&
operator <<(NdbOut & ndbout,const NdbVersion & ver)88 operator<<(NdbOut& ndbout, const NdbVersion& ver){
89   ndbout.print("%d.%d.%d",
90                ndbGetMajor(ver.m_ver),
91                ndbGetMinor(ver.m_ver),
92                ndbGetBuild(ver.m_ver));
93   return ndbout;
94 }
95 
96 
97 inline
98 NdbOut &
operator <<(NdbOut & ndbout,const NodeInfo & info)99 operator<<(NdbOut& ndbout, const NodeInfo & info){
100   ndbout << "[NodeInfo: ";
101   switch(info.m_type){
102   case NodeInfo::DB:
103     ndbout << "DB";
104     break;
105   case NodeInfo::API:
106     ndbout << "API";
107     break;
108   case NodeInfo::MGM:
109     ndbout << "MGM";
110     break;
111   case NodeInfo::INVALID:
112     ndbout << "INVALID";
113     break;
114   default:
115     ndbout << "<Unknown: " << info.m_type << ">";
116     break;
117   }
118 
119   ndbout << " ndb version: " << NdbVersion(info.m_version)
120 	 << " mysql version: " << NdbVersion(info.m_mysql_version)
121 	 << " connect count: " << info.m_connectCount
122 	 << "]";
123   return ndbout;
124 }
125 
126 struct NodeVersionInfo
127 {
128   STATIC_CONST( DataLength = 6 );
129   struct
130   {
131     Uint32 m_min_version;
132     Uint32 m_max_version;
133   } m_type [3]; // Indexed as NodeInfo::Type
134 };
135 
136 
137 #undef JAM_FILE_ID
138 
139 #endif
140