~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
243.1.17 by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.)
19
20
#ifndef ERROR_INJECT_SUPPORT
21
/**  
22
 * @file 
23
 *
24
 * Simple compile-time error injection module to enable easy 
25
 * error printing in case of a crash
26
 */
27
#ifndef DRIZZLE_SERVER_ERROR_INJECTION_H
28
#define DRIZZLE_SERVER_ERROR_INJECTION_H
29
30
/*
31
  Error injector Macros to enable easy testing of recovery after failures
32
  in various error cases.
33
*/
34
#define ERROR_INJECT(x) 0
35
#define ERROR_INJECT_ACTION(x,action) 0
36
#define ERROR_INJECT_CRASH(x) 0
37
#define ERROR_INJECT_VALUE(x) 0
38
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
39
#define ERROR_INJECT_VALUE_CRASH(x) 0
40
#define SET_ERROR_INJECT_VALUE(x)
41
42
#else
43
44
inline bool check_and_unset_keyword(const char *dbug_str)
45
{
46
  const char *extra_str= "-d,";
47
  char total_str[200];
48
  if (_db_strict_keyword_ (dbug_str))
49
  {
50
    strxmov(total_str, extra_str, dbug_str, NullS);
51
    return 1;
52
  }
53
  return 0;
54
}
55
56
57
inline bool
58
check_and_unset_inject_value(int value)
59
{
60
  THD *thd= current_thd;
61
  if (thd->error_inject_value == (uint)value)
62
  {
63
    thd->error_inject_value= 0;
64
    return 1;
65
  }
66
  return 0;
67
}
68
69
/*
70
  ERROR INJECT MODULE:
71
  --------------------
72
  These macros are used to insert macros from the application code.
73
  The event that activates those error injections can be activated
74
  from SQL by using:
75
  SET SESSION dbug=+d,code;
76
77
  After the error has been injected, the macros will automatically
78
  remove the debug code, thus similar to using:
79
  SET SESSION dbug=-d,code
80
  from SQL.
81
82
  ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
83
  is set when macro is called. ERROR_INJECT_CRASH can be used in
84
  if-statements, it will always return false unless of course it
85
  crashes in which case it doesn't return at all.
86
87
  ERROR_INJECT_ACTION will inject the action specified in the action
88
  parameter of the macro, before performing the action the code will
89
  be removed such that no more events occur. ERROR_INJECT_ACTION
90
  can also be used in if-statements and always returns FALSE.
91
  ERROR_INJECT can be used in a normal if-statement, where the action
92
  part is performed in the if-block. The macro returns TRUE if the
93
  error was activated and otherwise returns FALSE. If activated the
94
  code is removed.
95
96
  Sometimes it is necessary to perform error inject actions as a serie
97
  of events. In this case one can use one variable on the THD object.
98
  Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
99
  Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
100
  ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
101
  behaviour as the above described macros except that they use the
102
  error inject value instead of a code used by debug macros.
103
*/
104
#define SET_ERROR_INJECT_VALUE(x) \
105
  current_thd->error_inject_value= (x)
106
#define ERROR_INJECT_ACTION(code, action) \
107
  (check_and_unset_keyword(code) ? ((action), 0) : 0)
108
#define ERROR_INJECT(code) \
109
  check_and_unset_keyword(code)
110
#define ERROR_INJECT_VALUE(value) \
111
  check_and_unset_inject_value(value)
112
#define ERROR_INJECT_VALUE_ACTION(value,action) \
113
  (check_and_unset_inject_value(value) ? (action) : 0)
114
#define ERROR_INJECT_VALUE_CRASH(value) \
115
  ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
116
117
#endif /* DRIZZLE_SERVER_ERROR_INJECTION_H */
118
#endif /* ERROR_INJECT_SUPPORT */