-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathGSErrors.c
289 lines (259 loc) · 7.52 KB
/
GSErrors.c
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown
* at http://oss.oracle.com/licenses/upl
*/
/****************************************************************************
*
* TimesTen Scaleout sample programs - GridSample
*
* GSErrors.c - error related data and functions
*
****************************************************************************/
#include "GridSample.h"
/*
* Error array. Used to get the error messge corresponding to an error code.
*/
static char const * const
errMsgs[] =
{
ERRM_NO_ERROR, // 0
ERRM_HELP, // 1
ERRM_PARAM_INTERNAL, // 2
ERRM_STATE_INTERNAL, // 3
ERRM_TYPE_MISMATCH_INTERNAL, // 4
ERRM_NOMEM, // 5
ERRM_PARAM, // 6
ERRM_SIGNAL, // 7
ERRM_USER, // 8
ERRM_DATA, // 9
ERRM_ODBC_NO_DATA, // 10
ERRM_ODBC_NOINFO, // 11
ERRM_ODBC_NORMAL, // 12
ERRM_ODBC_RETRYABLE, // 13
ERRM_ODBC_FAILOVER // 14
}; // errMsgs
// minimum valid error code
static int
minErr = 1;
// number of entries in the error message array
static int
maxErr = ( (sizeof( errMsgs ) / sizeof( char * )) - 1 );
/*
* Retryable error array. Defines the ODBC errors that can be retried.
*/
static odbcerr_t
retryableErrors[] =
{
{ NULL, NULL, TT_ERR_SQLSTATE_RETRY, NULL,
TT_ERR_NATIVE_NONE, DFLT_RETRY_DELAY },
{ NULL, NULL, TT_ERR_SQLSTATE_NULL, NULL,
TT_ERR_NATIVE_DEADLOCK, DFLT_RETRY_DELAY },
{ NULL, NULL, TT_ERR_SQLSTATE_NULL, NULL,
TT_ERR_NATIVE_LOCKTIMEOUT, DFLT_RETRY_DELAY }
}; // retryableErrors
// number of entries in the retryableErrors array
static int
numRetryableErrors = sizeof(retryableErrors) / sizeof(odbcerr_t);
/*
* C/S failover error array. Defines the ODBC errors that indicate a
* connection failover event.
*/
static odbcerr_t
csFailoverErrors[] =
{
{ NULL, NULL, TT_ERR_SQLSTATE_NULL, NULL,
TT_ERR_NATIVE_FAILOVER, DFLT_FAILOVER_DELAY },
{ NULL, NULL, TT_ERR_SQLSTATE_GENERAL, NULL,
TT_ERR_NATIVE_NONE, DFLT_FAILOVER_DELAY }
}; // csFailoverErrors
// number of entries in the csFailoverErrors array
static int
numCsFailoverErrors = sizeof(csFailoverErrors) / sizeof(odbcerr_t);
/****************************************************************************
*
* Internal functions
*
****************************************************************************/
/*
* Check if an ODBC error represents a retryable error.
*
* INPUTS:
* err - pointer to an odbcerr_t structure
*
* OUTPUTS:
* delay - pointer to an integer to receive the retry delay value if this
* error is retryable (can be NULL if the value is not required)
*
* RETURNS:
* True if the error is a retryable error, false otherwise.
*/
static boolean
isRetryableError(
odbcerr_t const * err,
int * delay
)
{
int i;
if ( err != NULL )
{
for (i = 0; i < numRetryableErrors; i++)
{
if (
(!retryableErrors[i].sqlstate[0] ||
(strcmp(retryableErrors[i].sqlstate,err->sqlstate)== 0))
&&
((retryableErrors[i].native_error == TT_ERR_NATIVE_NONE) ||
(retryableErrors[i].native_error == err->native_error))
)
{
if ( delay != NULL )
*delay = retryableErrors[i].retry_delay;
return true;
}
}
}
return false;
} // isRetryableError
/*
* Check if an ODBC error represents a failover error.
*
* INPUTS:
* err - pointer to an odbcerr_t structure
*
* OUTPUTS:
* delay - pointer to an integer to receive the retry delay value if this
* error is a failover (can be NULL if the value is not required)
*
* RETURNS:
* True if the error is a failover error, false otherwise.
*/
static boolean
isCsFailoverError(
odbcerr_t const * err,
int * delay
)
{
int i;
if ( err != NULL )
{
for (i = 0; i < numCsFailoverErrors; i++)
{
if (
(!csFailoverErrors[i].sqlstate[0] ||
(strcmp(csFailoverErrors[i].sqlstate,err->sqlstate)== 0))
&&
((csFailoverErrors[i].native_error == TT_ERR_NATIVE_NONE) ||
(csFailoverErrors[i].native_error == err->native_error))
)
{
if ( delay != NULL )
*delay = csFailoverErrors[i].retry_delay;
return true;
}
}
}
return false;
} // isCsFailover
/****************************************************************************
*
* Public functions
*
****************************************************************************/
/*
* Translate an error code into an error message.
*
* INPUTS:
* errorCode - a valid error code
* ctxt - a pointer to a valid context_t
*
* OUTPUTS: None
*
* RETURNS:
* A pointer to the error message textt that corresponds to the
* error code. The data pointed to is read only and statically allocated.
*/
char const *
errorMessage(
int errorCode,
context_t * ctxt
)
{
char const * emsg = ERRM_UNKNOWN;
if ( (errorCode >= 0) && (errorCode <= maxErr) )
{
if ( (errorCode == ERR_USER) && (ctxt != NULL) )
emsg = ctxt->msgBuff;
else
emsg = errMsgs[ errorCode ];
}
return emsg;
} // errorMessage
/*
* Check if an error and associated error stack represents a retryable error.
*
* INPUTS:
* err - error code
* errstack - ODBC error stack
*
* OUTPUTS:
* delay - pointer to an integer to receive the retry delay value if this
* error is retryable (can be NULL if the value is not required)
*
* RETURNS:
* True if the error is a retryable error, false otherwise.
*/
boolean
isRetryable(
int err,
odbcerrlist_t * errstack,
int * delay
)
{
odbcerr_t * esp = NULL;
if ( (err != ERR_ODBC_NORMAL) || (errstack == NULL) )
return false;
esp = errstack->first;
while ( esp != NULL )
{
if ( isRetryableError( esp, delay ) )
return true;
esp = esp->next;
}
return false;
} // isRetryable
/*
* Check if an error and associated error stack represents a connection
* failover error (client/server mode only).
*
* INPUTS:
* err - error code
* errstack - ODBC error stack
*
* OUTPUTS:
* delay - pointer to an integer to receive the retry delay value if this
* error is a failover (can be NULL if the value is not required)
*
* RETURNS:
* True if the error is a failover error, false otherwise.
*/
boolean
isFailover(
int err,
odbcerrlist_t * errstack,
int * delay
)
{
odbcerr_t * esp = NULL;
if ( (err != ERR_ODBC_NORMAL) || (errstack == NULL) )
return false;
esp = errstack->first;
while ( esp != NULL )
{
if ( isCsFailoverError( esp, delay ) )
return true;
esp = esp->next;
}
return false;
} // isFailover