mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / src / NDBT_Error.cpp
blob0a708ddf69096a303a917644a6ac8616f574d7cf
1 /* Copyright (c) 2003-2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 /* NDBT_Error.cpp */
17 /* This program deals with error handling */
19 #include <ndb_global.h>
20 #include <NdbMain.h>
21 #include <NdbOut.hpp>
22 #include <NdbTest.hpp>
23 #include <NDBT_Error.hpp>
24 #include <NdbSleep.h>
27 ErrorData::ErrorData()
29 errorCountArray = new Uint32[6000];
30 resetErrorCounters();
32 key_error = false;
33 temporary_resource_error = true;
34 insufficient_space_error = false;
35 node_recovery_error = true;
36 overload_error = true;
37 timeout_error = true;
38 internal_error = true;
39 user_error = true;
40 application_error = false;
43 ErrorData::~ErrorData()
45 delete [] errorCountArray;
49 //-------------------------------------------------------------------
50 // Error Handling routines
51 //-------------------------------------------------------------------
53 int ErrorData::handleErrorCommon(const NdbError & error)
55 int retValue = 1;
56 if (error.code > 6000) {
57 if (user_error == true) {
58 retValue = 0;
59 }//if
60 return retValue;
61 }//if
62 errorCountArray[error.code]++;
63 switch(error.classification){
64 case NdbError::NoDataFound:
65 case NdbError::ConstraintViolation:
66 if (key_error == true) {
67 retValue = 0;
68 }//if
69 break;
70 case NdbError::TemporaryResourceError:
71 if (temporary_resource_error == true) {
72 retValue = 0;
73 }//if
74 break;
75 case NdbError::InsufficientSpace:
76 if (insufficient_space_error == true) {
77 retValue = 0;
78 }//if
79 break;
80 case NdbError::NodeRecoveryError:
81 if (node_recovery_error == true) {
82 retValue = 0;
83 }//if
84 break;
86 case NdbError::UnknownResultError:
87 if(error.code == 4012){
88 retValue = 0;
90 if(error.code == 4115){
91 retValue = 2;
93 if(error.code == 4007 && node_recovery_error == true){
94 retValue = 3;
96 break;
97 case NdbError::OverloadError:
98 if (overload_error == true) {
99 NdbSleep_MilliSleep(50);
100 retValue = 0;
101 }//if
102 break;
103 case NdbError::TimeoutExpired:
104 if (timeout_error == true) {
105 retValue = 0;
106 }//if
107 break;
108 case NdbError::InternalError:
109 if (internal_error == true) {
110 retValue = 0;
111 }//if
112 break;
113 case NdbError::ApplicationError:
114 if (application_error == true) {
115 retValue = 0;
116 }//if
117 break;
118 case NdbError::UserDefinedError:
119 if (user_error == true) {
120 retValue = 0;
121 }//if
122 break;
123 default:
124 break;
125 }//switch
126 if(error.status == NdbError::TemporaryError)
127 retValue = 0;
129 return retValue;
130 }//handleErrorCommon()
133 void ErrorData::printErrorCounters(NdbOut & out) const
135 int localLoop;
136 for (localLoop = 0; localLoop < 6000; localLoop++) {
137 int errCount = (int)errorCountArray[localLoop];
138 if (errCount > 0) {
139 out << "NDBT: ErrorCode = " << localLoop << " occurred ";
140 out << errCount << " times" << endl;
141 }//if
142 }//for
143 }//printErrorCounters()
146 void ErrorData::printSettings(NdbOut & out)
148 out << "Key Errors are ";
149 if (key_error == false) {
150 out << "disallowed" << endl;
151 } else {
152 out << "allowed" << endl;
153 }//if
154 out << "Temporary Resource Errors are ";
155 if (temporary_resource_error == false) {
156 out << "disallowed" << endl;
157 } else {
158 out << "allowed" << endl;
159 }//if
160 if (internal_error == true) {
161 out << "Insufficient Space Errors are ";
163 if (insufficient_space_error == false) {
164 out << "disallowed" << endl;
165 } else {
166 out << "allowed" << endl;
167 }//if
168 out << "Node Recovery Errors are ";
169 if (node_recovery_error == false) {
170 out << "disallowed" << endl;
171 } else {
172 out << "allowed" << endl;
173 }//if
174 out << "Overload Errors are ";
175 if (overload_error == false) {
176 out << "disallowed" << endl;
177 } else {
178 out << "allowed" << endl;
179 }//if
180 out << "Timeout Errors are ";
181 if (timeout_error == false) {
182 out << "disallowed" << endl;
183 } else {
184 out << "allowed" << endl;
185 }//if
186 out << "Internal NDB Errors are ";
187 if (internal_error == false) {
188 out << "disallowed" << endl;
189 } else {
190 out << "allowed" << endl;
191 }//if
192 out << "User logic reported Errors are ";
193 if (user_error == false) {
194 out << "disallowed" << endl;
195 } else {
196 out << "allowed" << endl;
197 }//if
198 out << "Application Errors are ";
199 if (application_error == false) {
200 out << "disallowed" << endl;
201 } else {
202 out << "allowed" << endl;
203 }//if
204 }//printSettings
207 void ErrorData::printCmdLineArgs(NdbOut & out)
209 out << " -key_err Allow key errors" << endl;
210 out << " -no_key_err Disallow key errors (default)" << endl;
211 out << " -temp_res_err Allow temporary resource errors (default)";
212 out << endl;
213 out << " -no_temp_res_err Disallow temporary resource errors" << endl;
214 out << " -ins_space_err Allow insufficient space errors" << endl;
215 out << " -no_ins_space_err Disallow insufficient space errors (default)";
216 out << endl;
217 out << " -noderec_err Allow Node Recovery errors (default)" << endl;
218 out << " -no_noderec_err Disallow Node Recovery errors" << endl;
219 out << " -overload_err Allow Overload errors (default)" << endl;
220 out << " -no_overload_err Disallow Overload errors" << endl;
221 out << " -timeout_err Allow Time-out errors (default)" << endl;
222 out << " -no_timeout_err Disallow Time-out errors" << endl;
223 out << " -internal_err Allow Internal NDB errors" << endl;
224 out << " -no_internal_err Disallow Internal NDB errors (default)";
225 out << " -user_err Allow user logic reported errors (default)";
226 out << endl;
227 out << " -no_user_err Disallow user logic reported errors";
228 out << endl;
230 }//printCmdLineArgs()
233 bool ErrorData::parseCmdLineArg(const char** argv, int & i)
235 bool ret_Value = true;
236 if (strcmp(argv[i], "-key_err") == 0){
237 key_error = true;
238 } else if (strcmp(argv[i], "-no_key_err") == 0){
239 key_error = false;
240 } else if (strcmp(argv[i], "-temp_res_err") == 0){
241 temporary_resource_error = true;
242 } else if (strcmp(argv[i], "-no_temp_res_err") == 0){
243 temporary_resource_error = false;
244 } else if (strcmp(argv[i], "-ins_space_err") == 0){
245 insufficient_space_error = true;
246 } else if (strcmp(argv[i], "-no_ins_space_err") == 0){
247 insufficient_space_error = false;
248 } else if (strcmp(argv[i], "-noderec_err") == 0){
249 node_recovery_error = true;
250 } else if (strcmp(argv[i], "-no_noderec_err") == 0){
251 node_recovery_error = false;
252 } else if (strcmp(argv[i], "-overload_err") == 0){
253 overload_error = true;
254 } else if (strcmp(argv[i], "-no_overload_err") == 0){
255 overload_error = false;
256 } else if (strcmp(argv[i], "-timeout_err") == 0){
257 timeout_error = true;
258 } else if (strcmp(argv[i], "-no_timeout_err") == 0){
259 timeout_error = false;
260 } else if (strcmp(argv[i], "-internal_err") == 0){
261 internal_error = true;
262 } else if (strcmp(argv[i], "-no_internal_err") == 0){
263 internal_error = false;
264 } else if (strcmp(argv[i], "-user_err") == 0){
265 user_error = true;
266 } else if (strcmp(argv[i], "-no_user_err") == 0){
267 user_error = false;
268 } else {
269 ret_Value = false;
270 }//if
271 return ret_Value;
272 }//bool parseCmdline
274 void ErrorData::resetErrorCounters()
276 for (int i = 0; i < 6000; i++){
277 errorCountArray[i] = 0 ;