1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/* Copyright (c) 2003-2005, 2007 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#include <ndb_version.h>
#include <version.h>
#include <basestring_vsnprintf.h>
#include <NdbEnv.h>
#include <NdbOut.hpp>
Uint32 ndbGetMajor(Uint32 version) {
return (version >> 16) & 0xFF;
}
Uint32 ndbGetMinor(Uint32 version) {
return (version >> 8) & 0xFF;
}
Uint32 ndbGetBuild(Uint32 version) {
return (version >> 0) & 0xFF;
}
Uint32 ndbMakeVersion(Uint32 major, Uint32 minor, Uint32 build) {
return NDB_MAKE_VERSION(major, minor, build);
}
const char * ndbGetOwnVersionString()
{
static char ndb_version_string_buf[NDB_VERSION_STRING_BUF_SZ];
return ndbGetVersionString(NDB_VERSION, NDB_VERSION_STATUS,
ndb_version_string_buf,
sizeof(ndb_version_string_buf));
}
const char * ndbGetVersionString(Uint32 version, const char * status,
char *buf, unsigned sz)
{
if (status && status[0] != 0)
basestring_snprintf(buf, sz,
"Version %d.%d.%d (%s)",
getMajor(version),
getMinor(version),
getBuild(version),
status);
else
basestring_snprintf(buf, sz,
"Version %d.%d.%d",
getMajor(version),
getMinor(version),
getBuild(version));
return buf;
}
typedef enum {
UG_Null,
UG_Range,
UG_Exact
} UG_MatchType;
struct NdbUpGradeCompatible {
Uint32 ownVersion;
Uint32 otherVersion;
UG_MatchType matchType;
};
/*#define TEST_VERSION*/
#define HAVE_NDB_SETVERSION
#ifdef HAVE_NDB_SETVERSION
Uint32 ndbOwnVersionTesting = 0;
void
ndbSetOwnVersion() {
char buf[256];
if (NdbEnv_GetEnv("NDB_SETVERSION", buf, sizeof(buf))) {
Uint32 _v1,_v2,_v3;
if (sscanf(buf, "%u.%u.%u", &_v1, &_v2, &_v3) == 3) {
ndbOwnVersionTesting = MAKE_VERSION(_v1,_v2,_v3);
ndbout_c("Testing: Version set to 0x%x", ndbOwnVersionTesting);
}
}
}
#else
void ndbSetOwnVersion() {}
#endif
#ifndef TEST_VERSION
struct NdbUpGradeCompatible ndbCompatibleTable_full[] = {
{ MAKE_VERSION(5,1,NDB_VERSION_BUILD), MAKE_VERSION(5,1,18), UG_Range},
{ MAKE_VERSION(5,1,17), MAKE_VERSION(5,1,0), UG_Range},
{ MAKE_VERSION(5,0,NDB_VERSION_BUILD), MAKE_VERSION(5,0,12), UG_Range},
{ MAKE_VERSION(5,0,11), MAKE_VERSION(5,0,2), UG_Range},
{ MAKE_VERSION(4,1,NDB_VERSION_BUILD), MAKE_VERSION(4,1,15), UG_Range },
{ MAKE_VERSION(4,1,14), MAKE_VERSION(4,1,10), UG_Range },
{ MAKE_VERSION(4,1,10), MAKE_VERSION(4,1,9), UG_Exact },
{ MAKE_VERSION(4,1,9), MAKE_VERSION(4,1,8), UG_Exact },
{ MAKE_VERSION(3,5,2), MAKE_VERSION(3,5,1), UG_Exact },
{ 0, 0, UG_Null }
};
struct NdbUpGradeCompatible ndbCompatibleTable_upgrade[] = {
{ MAKE_VERSION(5,0,12), MAKE_VERSION(5,0,11), UG_Exact },
{ MAKE_VERSION(5,0,2), MAKE_VERSION(4,1,8), UG_Exact },
{ MAKE_VERSION(4,1,15), MAKE_VERSION(4,1,14), UG_Exact },
{ MAKE_VERSION(3,5,4), MAKE_VERSION(3,5,3), UG_Exact },
{ 0, 0, UG_Null }
};
#else /* testing purposes */
struct NdbUpGradeCompatible ndbCompatibleTable_full[] = {
{ MAKE_VERSION(4,1,5), MAKE_VERSION(4,1,0), UG_Range },
{ MAKE_VERSION(3,6,9), MAKE_VERSION(3,6,1), UG_Range },
{ MAKE_VERSION(3,6,2), MAKE_VERSION(3,6,1), UG_Range },
{ MAKE_VERSION(3,5,7), MAKE_VERSION(3,5,0), UG_Range },
{ MAKE_VERSION(3,5,1), MAKE_VERSION(3,5,0), UG_Range },
{ NDB_VERSION_D , MAKE_VERSION(NDB_VERSION_MAJOR,NDB_VERSION_MINOR,2), UG_Range },
{ 0, 0, UG_Null }
};
struct NdbUpGradeCompatible ndbCompatibleTable_upgrade[] = {
{ MAKE_VERSION(4,1,5), MAKE_VERSION(3,6,9), UG_Exact },
{ MAKE_VERSION(3,6,2), MAKE_VERSION(3,5,7), UG_Exact },
{ MAKE_VERSION(3,5,1), NDB_VERSION_D , UG_Exact },
{ 0, 0, UG_Null }
};
#endif
void ndbPrintVersion()
{
printf("Version: %u.%u.%u\n",
getMajor(ndbGetOwnVersion()),
getMinor(ndbGetOwnVersion()),
getBuild(ndbGetOwnVersion()));
}
Uint32
ndbGetOwnVersion()
{
#ifdef HAVE_NDB_SETVERSION
if (ndbOwnVersionTesting == 0)
return NDB_VERSION_D;
else
return ndbOwnVersionTesting;
#else
return NDB_VERSION_D;
#endif
}
int
ndbSearchUpgradeCompatibleTable(Uint32 ownVersion, Uint32 otherVersion,
struct NdbUpGradeCompatible table[])
{
int i;
for (i = 0; table[i].ownVersion != 0 && table[i].otherVersion != 0; i++) {
if (table[i].ownVersion == ownVersion ||
table[i].ownVersion == (Uint32) ~0) {
switch (table[i].matchType) {
case UG_Range:
if (otherVersion >= table[i].otherVersion){
return 1;
}
break;
case UG_Exact:
if (otherVersion == table[i].otherVersion){
return 1;
}
break;
default:
break;
}
}
}
return 0;
}
int
ndbCompatible(Uint32 ownVersion, Uint32 otherVersion, struct NdbUpGradeCompatible table[])
{
if (otherVersion >= ownVersion) {
return 1;
}
return ndbSearchUpgradeCompatibleTable(ownVersion, otherVersion, table);
}
int
ndbCompatible_full(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible(ownVersion, otherVersion, ndbCompatibleTable_full);
}
int
ndbCompatible_upgrade(Uint32 ownVersion, Uint32 otherVersion)
{
if (ndbCompatible_full(ownVersion, otherVersion))
return 1;
return ndbCompatible(ownVersion, otherVersion, ndbCompatibleTable_upgrade);
}
int
ndbCompatible_mgmt_ndb(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_upgrade(ownVersion, otherVersion);
}
int
ndbCompatible_mgmt_api(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_upgrade(ownVersion, otherVersion);
}
int
ndbCompatible_ndb_mgmt(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_full(ownVersion, otherVersion);
}
int
ndbCompatible_api_mgmt(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_full(ownVersion, otherVersion);
}
int
ndbCompatible_api_ndb(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_full(ownVersion, otherVersion);
}
int
ndbCompatible_ndb_api(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_upgrade(ownVersion, otherVersion);
}
int
ndbCompatible_ndb_ndb(Uint32 ownVersion, Uint32 otherVersion)
{
return ndbCompatible_upgrade(ownVersion, otherVersion);
}
|