sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,119 @@
|
|
1
|
+
/*
|
2
|
+
* File: pping.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#ifndef _PPING_H
|
8
|
+
#define _PPING_H
|
9
|
+
|
10
|
+
#include "common/sedna.h"
|
11
|
+
#include "common/base.h"
|
12
|
+
|
13
|
+
#include "common/u/usocket.h"
|
14
|
+
#include "common/u/uthread.h"
|
15
|
+
#include "common/u/usem.h"
|
16
|
+
|
17
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
18
|
+
#ifdef _WIN32
|
19
|
+
#include <windows.h>
|
20
|
+
#endif
|
21
|
+
#endif
|
22
|
+
|
23
|
+
|
24
|
+
#define PPING_ON
|
25
|
+
|
26
|
+
#define PPING_MAX_HOSTLEN 128
|
27
|
+
|
28
|
+
class pping_client
|
29
|
+
{
|
30
|
+
private:
|
31
|
+
int port;
|
32
|
+
char host[PPING_MAX_HOSTLEN];
|
33
|
+
int component;
|
34
|
+
USOCKET sock;
|
35
|
+
bool stop_keep_alive;
|
36
|
+
bool initialized;
|
37
|
+
UTHANDLE client_thread_handle;
|
38
|
+
UUnnamedSemaphore sem;
|
39
|
+
|
40
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
+
/// Timeout counter and flags.
|
42
|
+
/// Timer is implemented above pping since there is no portable way to implement good timer on POSIX systems.
|
43
|
+
int counter;
|
44
|
+
volatile int timeout;
|
45
|
+
volatile bool reset_flag;
|
46
|
+
volatile bool* signaled_flag;
|
47
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
+
|
49
|
+
void throw_exception(SednaUserException& e, bool is_soft);
|
50
|
+
void startup(SednaUserException& e, bool is_soft);
|
51
|
+
|
52
|
+
#if (defined(EL_DEBUG) && (EL_DEBUG == 1))
|
53
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
+
/// Exception logging.
|
55
|
+
#ifdef _WIN32
|
56
|
+
private:
|
57
|
+
volatile LPEXCEPTION_POINTERS exceptPtrs;
|
58
|
+
volatile DWORD except_thread_id;
|
59
|
+
volatile UFile stacktrace_fh;
|
60
|
+
public:
|
61
|
+
void WriteStackTraceFile(LPEXCEPTION_POINTERS exceptPtrs);
|
62
|
+
#endif
|
63
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
+
#endif
|
65
|
+
|
66
|
+
|
67
|
+
public:
|
68
|
+
pping_client(int _port_, int _component_, const char* _host_ = NULL);
|
69
|
+
pping_client(int _port_, int _component_, volatile bool* _signaled_flag_, const char* _host_ = NULL);
|
70
|
+
~pping_client();
|
71
|
+
|
72
|
+
void startup(SednaUserException& e);
|
73
|
+
void startup(SednaUserSoftException& e);
|
74
|
+
void shutdown();
|
75
|
+
|
76
|
+
void start_timer(int _timeout_);
|
77
|
+
void stop_timer();
|
78
|
+
|
79
|
+
friend U_THREAD_PROC(pping_client_thread_proc, arg);
|
80
|
+
};
|
81
|
+
|
82
|
+
|
83
|
+
#define PPING_SERVER_THREAD_TABLE_SIZE (2 * (MAX_SESSIONS_NUMBER + MAX_DBS_NUMBER))
|
84
|
+
|
85
|
+
|
86
|
+
class pping_server
|
87
|
+
{
|
88
|
+
public:
|
89
|
+
struct thread_table_t
|
90
|
+
{
|
91
|
+
UTHANDLE handle;
|
92
|
+
bool is_running;
|
93
|
+
bool is_empty;
|
94
|
+
};
|
95
|
+
|
96
|
+
private:
|
97
|
+
int port;
|
98
|
+
USOCKET sock;
|
99
|
+
int component;
|
100
|
+
bool initialized;
|
101
|
+
UTHANDLE server_lstn_thread_handle;
|
102
|
+
volatile bool close_lstn_thread;
|
103
|
+
thread_table_t thread_table[PPING_SERVER_THREAD_TABLE_SIZE];
|
104
|
+
|
105
|
+
public:
|
106
|
+
pping_server(int _port_, int _component_);
|
107
|
+
~pping_server();
|
108
|
+
|
109
|
+
void startup();
|
110
|
+
void shutdown();
|
111
|
+
|
112
|
+
friend U_THREAD_PROC(pping_server_cli_thread_proc, arg);
|
113
|
+
friend U_THREAD_PROC(pping_server_lstn_thread_proc_mt, arg);
|
114
|
+
friend U_THREAD_PROC(pping_server_lstn_thread_proc_st, arg);
|
115
|
+
friend int client_exception_handler(USOCKET sock, const pping_server *pps);
|
116
|
+
};
|
117
|
+
|
118
|
+
|
119
|
+
#endif
|
@@ -0,0 +1,273 @@
|
|
1
|
+
/*********************************************************************************************************
|
2
|
+
*
|
3
|
+
* Ok, here is the main plan:
|
4
|
+
* 1) Read cfg file in /data/rcvtest.cfg
|
5
|
+
* 2) If we have some previous saved state use it instead (/data/rcvstate.tmp)
|
6
|
+
* 3) When we step on macros RCV_TEST_CRASH rcvTestCrashPoint function is called
|
7
|
+
* 4) Check if we need to crash here by:
|
8
|
+
* a) check if function is in cfg table
|
9
|
+
* b) computing probability
|
10
|
+
* 5) If check is ok then decrementing number of tries, save state to rcvstate.tmp file and exit.
|
11
|
+
* 6) Else, continuing execution
|
12
|
+
*
|
13
|
+
* Config note: you must define all crash points in rcvtest.cfg along with crash probability
|
14
|
+
* (real from [0; 1]) and max number of tries (-1 for infinite number; 0 to disable crash).
|
15
|
+
*
|
16
|
+
********************************************************************************************************/
|
17
|
+
|
18
|
+
#include "common/rcv_test.h"
|
19
|
+
#include "common/errdbg/d_printf.h"
|
20
|
+
#include "common/u/uhdd.h"
|
21
|
+
|
22
|
+
#include <map>
|
23
|
+
#include <string>
|
24
|
+
|
25
|
+
typedef struct
|
26
|
+
{
|
27
|
+
int try_numbers;
|
28
|
+
double prob;
|
29
|
+
|
30
|
+
} rcvPointInfo;
|
31
|
+
|
32
|
+
using namespace std;
|
33
|
+
|
34
|
+
static map <string, rcvPointInfo *> fname_cfg_table;
|
35
|
+
typedef map <string, rcvPointInfo *>::iterator table_it;
|
36
|
+
|
37
|
+
// store current crash info into file; file name is relative to SEDNA_DATA
|
38
|
+
static void rcvSerializeInfoToFile(const char *file_name)
|
39
|
+
{
|
40
|
+
char tmp_file_name[U_MAX_PATH];
|
41
|
+
UFile tfh;
|
42
|
+
table_it it = fname_cfg_table.begin();
|
43
|
+
int written, err = 0, len;
|
44
|
+
|
45
|
+
sprintf(tmp_file_name, "%s/%s", SEDNA_DATA, file_name);
|
46
|
+
|
47
|
+
// delete old file (ignore error, if it doesn't exist)
|
48
|
+
uDeleteFile(tmp_file_name, __sys_call_error);
|
49
|
+
|
50
|
+
// create new file
|
51
|
+
tfh = uCreateFile(tmp_file_name, U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, 0, NULL, NULL);
|
52
|
+
if (tfh == U_INVALID_FD)
|
53
|
+
fprintf(stderr, "Cannot create temporary file to store rcv_crash info\n");
|
54
|
+
|
55
|
+
while (it != fname_cfg_table.end())
|
56
|
+
{
|
57
|
+
// get function name length
|
58
|
+
len = (it->first).size();
|
59
|
+
|
60
|
+
// store string length
|
61
|
+
if (uWriteFile(tfh, &len, sizeof len, &written, __sys_call_error) == 0 ||
|
62
|
+
written != sizeof len)
|
63
|
+
{
|
64
|
+
fprintf(stderr, "Cannot serialize recovery crash info\n");
|
65
|
+
err = 1;
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
|
69
|
+
// store current function name
|
70
|
+
if (uWriteFile(tfh, (it->first).c_str(), len, &written, __sys_call_error) == 0 ||
|
71
|
+
written != len)
|
72
|
+
{
|
73
|
+
fprintf(stderr, "Cannot serialize recovery crash info\n");
|
74
|
+
err = 1;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
|
78
|
+
// store the associated structure
|
79
|
+
if (uWriteFile(tfh, (it->second), sizeof(rcvPointInfo), &written, __sys_call_error) == 0 ||
|
80
|
+
written != sizeof(rcvPointInfo))
|
81
|
+
{
|
82
|
+
fprintf(stderr, "Cannot serialize recovery crash info\n");
|
83
|
+
err = 1;
|
84
|
+
break;
|
85
|
+
}
|
86
|
+
|
87
|
+
// next element
|
88
|
+
it++;
|
89
|
+
}
|
90
|
+
|
91
|
+
uCloseFile(tfh, __sys_call_error);
|
92
|
+
|
93
|
+
// delete tmp file in case of error
|
94
|
+
if (err == 1)
|
95
|
+
uDeleteFile(tmp_file_name, __sys_call_error);
|
96
|
+
}
|
97
|
+
|
98
|
+
// load current crash info from file; file name is relative to SEDNA_DATA
|
99
|
+
// Returns: 0 - all ok; 1 - some problem (file not found, etc.)
|
100
|
+
static int rcvLoadInfoFromFile(const char *file_name)
|
101
|
+
{
|
102
|
+
char tmp_file_name[U_MAX_PATH], func_buf[1024];
|
103
|
+
UFile tfh;
|
104
|
+
int readb, len;
|
105
|
+
rcvPointInfo *rcvInfo;
|
106
|
+
table_it it;
|
107
|
+
|
108
|
+
sprintf(tmp_file_name, "%s/%s", SEDNA_DATA, file_name);
|
109
|
+
|
110
|
+
// open temp file
|
111
|
+
tfh = uOpenFile(tmp_file_name, U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, 0, NULL);
|
112
|
+
// if we cannot open tmp file then read default cfg instead
|
113
|
+
if (tfh == U_INVALID_FD)
|
114
|
+
return 1;
|
115
|
+
|
116
|
+
while (1)
|
117
|
+
{
|
118
|
+
// load string length
|
119
|
+
if (uReadFile(tfh, &len, sizeof(len), &readb, __sys_call_error) == 0 ||
|
120
|
+
readb != sizeof(len))
|
121
|
+
break;
|
122
|
+
|
123
|
+
// load current function name
|
124
|
+
if (uReadFile(tfh, func_buf, len, &readb, __sys_call_error) == 0 ||
|
125
|
+
readb != len)
|
126
|
+
break;
|
127
|
+
|
128
|
+
// add trailing zero
|
129
|
+
func_buf[len] = '\0';
|
130
|
+
|
131
|
+
// allocate new info structure
|
132
|
+
if ((rcvInfo = (rcvPointInfo *)malloc(sizeof(rcvPointInfo))) == NULL)
|
133
|
+
throw SYSTEM_EXCEPTION("Cannot allocate memory!");
|
134
|
+
|
135
|
+
// load the associated structure
|
136
|
+
if (uReadFile(tfh, rcvInfo, sizeof(rcvPointInfo), &readb, __sys_call_error) == 0 ||
|
137
|
+
readb != sizeof(rcvPointInfo))
|
138
|
+
break;
|
139
|
+
|
140
|
+
// append info to the table
|
141
|
+
fname_cfg_table[func_buf] = rcvInfo;
|
142
|
+
}
|
143
|
+
|
144
|
+
uCloseFile(tfh, __sys_call_error);
|
145
|
+
|
146
|
+
// delete tmp file in case of error and clear read config
|
147
|
+
if (readb != 0)
|
148
|
+
{
|
149
|
+
uDeleteFile(tmp_file_name, __sys_call_error);
|
150
|
+
for (it = fname_cfg_table.begin(); it != fname_cfg_table.end(); it++)
|
151
|
+
free(it->second);
|
152
|
+
|
153
|
+
fname_cfg_table.clear();
|
154
|
+
|
155
|
+
return 1;
|
156
|
+
}
|
157
|
+
|
158
|
+
return 0;
|
159
|
+
}
|
160
|
+
|
161
|
+
void rcvTestCrashPoint(const char *func_name)
|
162
|
+
{
|
163
|
+
UFile r_fh;
|
164
|
+
rcvPointInfo *point_info;
|
165
|
+
table_it it;
|
166
|
+
char crash_info[256];
|
167
|
+
double prob;
|
168
|
+
int written;
|
169
|
+
|
170
|
+
// if we don't have points to crash then return
|
171
|
+
if (fname_cfg_table.empty()) return;
|
172
|
+
|
173
|
+
// try to find info about the point
|
174
|
+
it = fname_cfg_table.find(string(func_name));
|
175
|
+
|
176
|
+
// nope, so don't crash
|
177
|
+
if (it == fname_cfg_table.end()) return;
|
178
|
+
|
179
|
+
// ok, we've found it
|
180
|
+
point_info = it->second;
|
181
|
+
|
182
|
+
// check probability
|
183
|
+
if ((prob = ((double)rand() / (double)RAND_MAX)) < point_info->prob)
|
184
|
+
{
|
185
|
+
// print to elog
|
186
|
+
elog(EL_ERROR, ("\nTr is crashed in %s due to recovery testing\n", func_name));
|
187
|
+
// and to the console
|
188
|
+
d_printf2("\nTr is crashed in %s due to recovery testing\n", func_name);
|
189
|
+
|
190
|
+
// correct number of tries
|
191
|
+
if (point_info->try_numbers != -1)
|
192
|
+
point_info->try_numbers--;
|
193
|
+
|
194
|
+
// recovery file-flag
|
195
|
+
string rcv_fname = string(SEDNA_DATA) + string("/data/") + string("rcv_test_crash");
|
196
|
+
|
197
|
+
// create notification file, so that recovery driver could recognize recovery crash
|
198
|
+
uDeleteFile(rcv_fname.c_str(), __sys_call_error);
|
199
|
+
r_fh = uCreateFile(rcv_fname.c_str(), U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, 0, NULL, NULL);
|
200
|
+
if (r_fh == U_INVALID_FD)
|
201
|
+
fprintf(stderr, "Cannot create rcv_test_crash file\n");
|
202
|
+
|
203
|
+
// write some debug info in this file
|
204
|
+
sprintf(crash_info, "point=%s genp=%lf prob=%lf tryrem=%d", func_name, prob, point_info->prob,
|
205
|
+
point_info->try_numbers);
|
206
|
+
|
207
|
+
// write this info to the file (ignore errors)
|
208
|
+
uWriteFile(r_fh, crash_info, strlen(crash_info), &written, __sys_call_error);
|
209
|
+
|
210
|
+
uCloseFile(r_fh, NULL);
|
211
|
+
|
212
|
+
// if it is the last crash then delete record from config table
|
213
|
+
if (point_info->try_numbers == 0)
|
214
|
+
{
|
215
|
+
free(it->second);
|
216
|
+
fname_cfg_table.erase(it);
|
217
|
+
}
|
218
|
+
|
219
|
+
// serialize current config info to a rcvstate.tmp file to load it after recovery
|
220
|
+
rcvSerializeInfoToFile("/data/rcvstate.tmp");
|
221
|
+
|
222
|
+
// do abnormal exit (recovery crash)
|
223
|
+
_exit(1);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
// read recovery config in /data/rcvtest.cfg
|
228
|
+
void rcvReadTestCfg()
|
229
|
+
{
|
230
|
+
char rcv_file_name[U_MAX_PATH], read_str[1024], func_name[256];
|
231
|
+
int max_try;
|
232
|
+
double crash_prob;
|
233
|
+
FILE *fd;
|
234
|
+
rcvPointInfo *rcvInfo;
|
235
|
+
|
236
|
+
// init random seed
|
237
|
+
srand((unsigned)time(NULL));
|
238
|
+
|
239
|
+
// first, try to read saved state
|
240
|
+
if (rcvLoadInfoFromFile("/data/rcvstate.tmp") == 0)
|
241
|
+
return;
|
242
|
+
|
243
|
+
// else, try to read global recovery testing config
|
244
|
+
sprintf(rcv_file_name, "%s/data/rcvtest.cfg", SEDNA_DATA);
|
245
|
+
|
246
|
+
d_printf2("\nrcv_test_cfg_file=%s\n", rcv_file_name);
|
247
|
+
|
248
|
+
// open config file
|
249
|
+
fd = fopen(rcv_file_name, "r");
|
250
|
+
if (fd == NULL) return;
|
251
|
+
|
252
|
+
// parse it until EOF
|
253
|
+
while (fgets(read_str, 1024, fd))
|
254
|
+
// ignore comments and not well-defined strings
|
255
|
+
if (sscanf(read_str, "%s %lf %d\n", func_name, &crash_prob, &max_try) == 3 &&
|
256
|
+
func_name[0] != '#' && (max_try > 0 || max_try == -1))
|
257
|
+
{
|
258
|
+
// allocate new info structure
|
259
|
+
if ((rcvInfo = (rcvPointInfo *)malloc(sizeof(rcvPointInfo))) == NULL)
|
260
|
+
throw SYSTEM_EXCEPTION("Cannot allocate memory!");
|
261
|
+
|
262
|
+
rcvInfo->try_numbers = max_try;
|
263
|
+
rcvInfo->prob = crash_prob;
|
264
|
+
|
265
|
+
fname_cfg_table[func_name] = rcvInfo;
|
266
|
+
}
|
267
|
+
|
268
|
+
// if we've caught an error then complain
|
269
|
+
if (!feof(fd))
|
270
|
+
throw USER_EXCEPTION2(SE4044, "rcvtest.cfg");
|
271
|
+
|
272
|
+
fclose(fd);
|
273
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#ifndef __RCV_TEST_H__
|
2
|
+
#define __RCV_TEST_H__
|
3
|
+
|
4
|
+
//#define RCV_TEST_CRASH
|
5
|
+
|
6
|
+
#ifdef RCV_TEST_CRASH
|
7
|
+
#define RECOVERY_CRASH rcvTestCrashPoint(__SE_FUNCTION__)
|
8
|
+
#else
|
9
|
+
#define RECOVERY_CRASH
|
10
|
+
#endif
|
11
|
+
|
12
|
+
// read test_rcv.xml and parses it to a table
|
13
|
+
void rcvReadTestCfg();
|
14
|
+
|
15
|
+
// check if function name has been considered in cfg and crashes tr with some probability
|
16
|
+
void rcvTestCrashPoint(const char *func_name);
|
17
|
+
|
18
|
+
#endif
|
19
|
+
|
@@ -0,0 +1,128 @@
|
|
1
|
+
/*
|
2
|
+
* File: sedna.c
|
3
|
+
* Copyright (C) 2006 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
/*
|
7
|
+
#include "common/sedna.h"
|
8
|
+
#include "common/errdbg/d_printf.h"
|
9
|
+
#include "common/u/usecurity.h"
|
10
|
+
#include "common/u/uhdd.h"
|
11
|
+
#include "common/ipc_ops.h"
|
12
|
+
*/
|
13
|
+
#include <assert.h>
|
14
|
+
#include <stdio.h>
|
15
|
+
#include <string.h>
|
16
|
+
#include <errno.h>
|
17
|
+
#ifdef _WIN32
|
18
|
+
#include <windows.h>
|
19
|
+
#else
|
20
|
+
#include <sys/types.h>
|
21
|
+
#include <unistd.h>
|
22
|
+
#include <fcntl.h>
|
23
|
+
#endif
|
24
|
+
|
25
|
+
void DumpFaultInfo()
|
26
|
+
{
|
27
|
+
int processId = -1, bIsTrunc = 0;
|
28
|
+
const char *cmdline = "<failed to obtain cmdline>";
|
29
|
+
#ifdef _WIN32
|
30
|
+
/* very simple, isn't it? */
|
31
|
+
const char *cmdline2 = NULL;
|
32
|
+
processId = (int)GetCurrentProcessId();
|
33
|
+
cmdline2 = GetCommandLine();
|
34
|
+
if (cmdline2) cmdline = cmdline2;
|
35
|
+
#else
|
36
|
+
/* rather bloat
|
37
|
+
* - read command line from /proc/[PID]/cmdline
|
38
|
+
* - reconstruct command line (we get it already tokenized)
|
39
|
+
* - certain characters are escaped during reconstruction
|
40
|
+
* - operating on fixed size buffers thus having to truncate
|
41
|
+
* resulting string gracefully when ran out of buffer space */
|
42
|
+
pid_t pid = 0;
|
43
|
+
int fd = 0, bNeedQuotes = 0;
|
44
|
+
size_t sz = 0;
|
45
|
+
char path[64];
|
46
|
+
char buf[256], obuf[256];
|
47
|
+
char *a = NULL, *b = NULL, *aEnd = NULL, *bEnd = NULL;
|
48
|
+
|
49
|
+
pid = getpid();
|
50
|
+
sz = snprintf(path, sizeof path, "/proc/%d/cmdline", (int)pid);
|
51
|
+
if (sz==-1 || sz>=sizeof path)
|
52
|
+
{
|
53
|
+
/* buffer too small to hold the path */
|
54
|
+
}
|
55
|
+
else if (fd = open(path, O_RDONLY), fd==-1)
|
56
|
+
{
|
57
|
+
/* proc filesystem n/a */
|
58
|
+
}
|
59
|
+
else
|
60
|
+
{
|
61
|
+
a = buf;
|
62
|
+
aEnd = buf + sizeof(buf) - 1; /* space for \0 terminator */
|
63
|
+
b = obuf;
|
64
|
+
bEnd = obuf + sizeof (obuf) - 2; /* space for extra char & \0 */
|
65
|
+
|
66
|
+
for (sz=1; a!=aEnd && sz>0; )
|
67
|
+
{
|
68
|
+
/* have one extra byte after aEnd, to identify trunc */
|
69
|
+
sz = read(fd, a, aEnd - a + 1);
|
70
|
+
if (sz==-1)
|
71
|
+
{
|
72
|
+
if (errno == EINTR) sz=1; /* not an error */
|
73
|
+
}
|
74
|
+
else a+=sz;
|
75
|
+
}
|
76
|
+
close(fd);
|
77
|
+
/* read successfully? */
|
78
|
+
if (sz!=-1)
|
79
|
+
{
|
80
|
+
bIsTrunc = (a>aEnd);
|
81
|
+
if (!bIsTrunc) aEnd = a;
|
82
|
+
a=buf; *aEnd=0;
|
83
|
+
/* processing tokens one-by-one (\0 terminated)*/
|
84
|
+
while (a<aEnd && b<bEnd)
|
85
|
+
{
|
86
|
+
/* processing token */
|
87
|
+
bNeedQuotes = (*a==0); /* when token is "" */
|
88
|
+
if (bNeedQuotes) b++[0]='\"';
|
89
|
+
while (*a && b<bEnd)
|
90
|
+
{
|
91
|
+
switch (*a)
|
92
|
+
{
|
93
|
+
/* escape special chars */
|
94
|
+
case ' ':
|
95
|
+
case '\\':
|
96
|
+
case '\"':
|
97
|
+
/* we have 1 extra char
|
98
|
+
* after bEnd, so this is
|
99
|
+
* valid */
|
100
|
+
b++[0] = '\\';
|
101
|
+
}
|
102
|
+
b++[0] = *a;
|
103
|
+
++a;
|
104
|
+
}
|
105
|
+
bIsTrunc |= (bNeedQuotes && b>=bEnd);
|
106
|
+
if (b<bEnd && bNeedQuotes) b++[0]='\"';
|
107
|
+
/* a+1 points to next token, if one exists */
|
108
|
+
if (a+1<aEnd && b<bEnd) b++[0]=' ';
|
109
|
+
/* if we discard ' ' due to truncation we will
|
110
|
+
* leave outter loop prematurely and bIsTrunc
|
111
|
+
* flag is set outside (not all tokens
|
112
|
+
* processed) */
|
113
|
+
bIsTrunc |= (*a!=0);
|
114
|
+
++a;
|
115
|
+
}
|
116
|
+
bIsTrunc |= (a<aEnd); /* not all tokens processed */
|
117
|
+
bEnd = b; b=obuf; *bEnd=0;
|
118
|
+
cmdline = obuf;
|
119
|
+
}
|
120
|
+
processId = (int)pid;
|
121
|
+
}
|
122
|
+
#endif
|
123
|
+
assert (cmdline);
|
124
|
+
fprintf(stderr, "in process [%d] %s%s\n",
|
125
|
+
processId, cmdline,
|
126
|
+
bIsTrunc ? "...<truncated>":"");
|
127
|
+
};
|
128
|
+
|