File: 2pc.h

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (432 lines) | stat: -rw-r--r-- 10,436 bytes parent folder | download | duplicates (2)
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/*
 *  2pc.h
 *
 *  $Id$
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2012 OpenLink Software
 *
 *  This project 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; only version 2 of the License, dated June 1991.
 *
 *  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.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

#ifndef _TPC_H
#define _TPC_H

#include "util/uuid.h"
#include "wi_xid.h"

#ifndef XA_IMPL
#define XA_IMPL
#endif

#ifndef NO_2PC_TRACE
#ifdef DEBUG
#ifndef _2PC_TRACE
#define _2PC_TRACE
#endif
#endif
#endif

#define UUID_BY_PORT

#ifndef WIN32
#ifndef HRESULT
#define HRESULT long
#define S_OK                                   ((HRESULT)0x00000000L)
#define S_FALSE                                ((HRESULT)0x00000001L)
#endif

#ifndef UWORD
#define UWORD unsigned short
#endif

#ifndef DWORD
#define DWORD uint32
#endif
#endif

    /* message identities for main queue */
#define TP_PREPARE	1
#define TP_COMMIT	2
#define TP_ABORT	3
#define TP_ENLIST_END	4
#define TP_JOIN		5
#define TP_RESUME	6
#define TP_SUSPEND	7

#define SQL_TP_UNENLIST		((UWORD)0x000000F0L)
#define SQL_XA_UNENLIST		((UWORD)0x00000F00L)
#define SQL_TP_PREPARE		((UWORD)(TP_PREPARE | SQL_TP_UNENLIST ))
#define SQL_TP_COMMIT		((UWORD)(TP_COMMIT | SQL_TP_UNENLIST ))
#define SQL_TP_ABORT		((UWORD)(TP_ABORT | SQL_TP_UNENLIST ))
#define SQL_TP_ENLIST		((UWORD)( 4UL | SQL_TP_UNENLIST ))

#define SQL_XA_ENLIST		((UWORD)( 6UL | SQL_TP_UNENLIST ))
#define SQL_XA_PREPARE		((UWORD)( TP_PREPARE | SQL_XA_UNENLIST ))
#define SQL_XA_COMMIT		((UWORD)( TP_COMMIT | SQL_XA_UNENLIST ))
#define SQL_XA_ROLLBACK		((UWORD)( TP_ABORT | SQL_XA_UNENLIST ))
#define SQL_XA_ENLIST_END	((UWORD)( TP_ENLIST_END | SQL_XA_UNENLIST ))
#define SQL_XA_JOIN		((UWORD)( TP_JOIN | SQL_XA_UNENLIST))
#define SQL_XA_WAIT		((UWORD)( SQL_XA_UNENLIST))
#define SQL_XA_RESUME		((UWORD)( TP_RESUME | SQL_XA_UNENLIST))
#define SQL_XA_SUSPEND		((UWORD)( TP_SUSPEND | SQL_XA_UNENLIST))

  /* types of TP */
#define TP_VIRT_TYPE	1
#define TP_MTS_TYPE	2
#define TP_XA_TYPE	3

  /* states of transactions */
#define ENLISTED 1
#define SHOULD_BE_ENLISTED 2

  /* states of client connection */
  /* local transactions state */
#define CONNECTION_LOCAL 0
  /* remote transactions state */
#define CONNECTION_PREPARED 1
#define CONNECTION_ENLISTED 2
#define CONNECTION_FINISHED 3
  /* this flag indicates that transaction is killed
     during checkpoint */
#define TP_PREPARE_CHKPNT 1

struct tp_message_s;

typedef unsigned long (*tp_log_t) (struct tp_message_s * mm);
typedef unsigned long (*tp_func_t) (void *res, int trx_status);

    /* vtbl for message object */
typedef struct queue_vtbl_s
{
  tp_func_t prepare_done;
  tp_func_t commit_done;
  tp_func_t abort_done;
  tp_log_t prepare_set_log;
}
queue_vtbl_t;

typedef struct tp_queue_s
{
  basket_t mq_basket;
  dk_mutex_t *mq_mutex;
  semaphore_t *mq_semaphore;
#ifdef MQ_DEBUG
  unsigned long mq_aborts;
  unsigned long mq_commits;
  unsigned long mq_prepares;
  unsigned long mq_errors;
#endif
}
tp_queue_t;

    /* list of enlisted connections for  */
typedef struct tp_connection_s
{
  basket_t tcon_basket;
}
tp_connection_t;

struct tp_dtrx_s;
struct rds_connection_s;
struct query_instance_s;
struct lock_trx_s;
struct tp_dtrx_s;

typedef int (*enlist_func_t) (struct rds_connection_s * rcon,
    struct query_instance_s * qi);
typedef int (*commit_func_1_t) (struct lock_trx_s * lt, int is_commit);
typedef int (*commit_func_2_t) (caddr_t distr_trx, int is_commit);
typedef int (*exclude_func_t) (struct lock_trx_s * lt,
    struct rds_connection_s * rcon);
typedef void (*dealloc_func_t) (struct tp_dtrx_s * dtrx);

    /* transaction flow management */
typedef struct tp_trx_vtbl_s
{
  enlist_func_t enlist;
  commit_func_1_t commit_1;
  commit_func_2_t commit_2;
  exclude_func_t exclude;
  dealloc_func_t dealloc;
}
tp_trx_vtbl_t;

typedef struct tp_dtrx_s
{
  caddr_t dtrx_info;		/* for MTS mts_t, for VIRT list of rcons */
  tp_trx_vtbl_t *vtbl;
}
tp_dtrx_t;

    /* distr. transaction data of connection */
typedef struct tp_data_s
{
  int cli_tp_enlisted;
  semaphore_t *cli_tp_sem2;
  int cli_trx_type;
  void *cli_tp_trx;
  struct lock_trx_s *cli_tp_lt;
  int tpd_client_is_reset;
  int tpd_last_act;

  caddr_t tpd_trx_cookie;
#ifdef _DEBUG
  int fail_after_prepare;
#endif
  unsigned cli_free_after_unenlist:2;
  struct tp_data_s *next;
}
tp_data_t;

#define CFAU_NONE	0
#define CFAU_DIED	1

typedef struct tp_future_s
{
  ptrlong ft_result;
  semaphore_t *ft_sem;
  char ft_release;
}
tp_future_t;

typedef struct tp_message_s
{
  int mm_type;			/* abort or commit */
  tp_future_t * mm_resource;
  struct lock_trx_s *mm_trx;
  struct tp_data_s *mm_tp_data;
  queue_vtbl_t *vtbl;
}
tp_message_t;

/* temporary solution, should be changed to real UUID */
#define DTRX_IP 0
#define DTRX_PORT 1
#define DTRX_NUMBER_ID 2
#define DTRX_RM_ID 3
typedef struct tp_addr_s
{
  uint32 tpa_ip_addr;
  uint32 tpa_port;
}
tp_addr_t;

typedef struct dtransact_id_s
{
  struct parsed_s
  {
    tp_addr_t p_tp;
    uint32 p_number_id;
    uint32 p_rm_id;		/* filled at rm side */
  } dtid_parsed;
  caddr_t dtid_brick;
} dtransact_id_t;

/* holder for enlisted hdbcs */
typedef struct d_trx_info_s
{
  box_t d_trx_id;
  dk_set_t d_trx_hdbcs;
} d_trx_info_t;


typedef struct virt_tp_s
{
  dk_set_t vtp_trxs;
  struct client_connection_s *vtp_cli;
  struct uuid *vtp_uuid;
}
virt_tp_t;

typedef unsigned long virt_trx_id_t;
typedef unsigned long virt_branch_id_t;
struct virt_trx_s;
struct virt_rcon_s;
typedef struct virt_rcon_s *(*virt_branch_factory_t) (struct virt_trx_s *
    vtrx);
typedef int tp_result_t;

typedef struct virt_rcon_s
{
  virt_branch_id_t vtr_id;
  struct virt_trx_s *vtr_trx;

  int vtr_is_local;
  union
  {
    struct rds_connection_s *l_rmt;
    caddr_t r_cookie;
  } vtr_branch_handle;


  int vtr_is_finalized;
}
virt_rcon_t;



typedef struct virt_trx_s
{
  virt_trx_id_t vtx_id;
  dk_set_t vtx_cons;
  const char *vtx_curr_state;

  virt_tp_t *vtx_transaction_processor;

  virt_branch_factory_t vtx_branch_factory;

  caddr_t vtx_cookie;
  uuid_t *vtx_uuid;

  int vtx_needs_recovery;
}
virt_trx_t;

/* Error reporting */
#define TP_ERR_COMMON		(tp_result_t)(-100)
#define TP_ERR_NO_DISTR_TRX	(tp_result_t)(-101)
#define TP_ERR_DTRX_INIT	(tp_result_t)(-102)
#define TP_ERR_SYS_TABLE	(tp_result_t)(-103)



struct client_connection_s;

    /* wait for end of distr. transaction */
EXE_EXPORT (int, tp_retire, (struct query_instance_s * qi));
int tp_wait_commit (struct client_connection_s *cli);
    /* switch connection state */
int tp_connection_state (struct client_connection_s *cli);
void tp_queue_free (tp_queue_t * queue);
    /*
       main function which manages 2PC messages
       runs in its own thread */
int tp_message_hook (void *queue);
void tp_data_free (tp_data_t * tpd);
void tp_main_queue_init (void);
EXE_EXPORT (tp_message_t *, mq_create_message, (int type,
	void *enlistment, void *client_connection));
tp_message_t *mq_create_xa_message (int type, void *enlistment, void *tpd);
EXE_EXPORT (void, mq_add_message, (tp_queue_t * mq, void *message));
EXE_EXPORT (tp_queue_t *, tp_get_main_queue, (void));
EXE_EXPORT (void, DoSQLError, (SQLHDBC hdbc, SQLHSTMT hstmt));

#define _LOG_INFO   0
#define _LOG_ERROR  1

EXE_EXPORT (void, twopc_log, (int log_level, char *message));

int lt_2pc_prepare (struct lock_trx_s *lt);

tp_dtrx_t *virt_trx_allocate (void);
caddr_t tp_add_enlisted_connection (struct dk_session_s *ses,
    dtransact_id_t * trx);
dtransact_id_t *dtransact_id_allocate (void);
void virt_tp_store_connections (struct lock_trx_s *lt);
extern tp_queue_t *tp_main_queue;

/* #define _2PC_TRACE */

#ifdef _2PC_TRACE
#define _2pc_printf(x) log_info x
#else
#define _2pc_printf(x)
#endif

/* #ifndef _MTX_ */
/* X/Open global transactions supporting functions */

/* #define XA_CLIENT (struct client_connection_s *)(-1) */

#define VXA_AGAIN	(-2)
#define VXA_ERROR	(-1)
#define VXA_OK		0

#ifdef TUXEDO
#define virtXID XID
#endif

typedef struct xa_id_s
{
  virtXID xid;
  semaphore_t *xid_sem;
  struct client_connection_s *xid_cli;
  struct tp_data_s *xid_tp_data;
  int xid_op;
} xa_id_t;

typedef struct virt_xa_map_s
{
  id_hash_t *xm_xids;
  id_hash_t *xm_log_xids;
  dk_mutex_t *xm_mtx;
  id_hash_iterator_t xm_hit;

} virt_xa_map_t;

extern virt_xa_map_t *global_xa_map;

int virt_xa_set_client (void *xid, struct client_connection_s *cli);
void virt_xa_suspend_lt (void *xid, struct client_connection_s *cli);
int virt_xa_client (void *xid_str, struct client_connection_s *cli, struct tp_data_s **tpd, int op);
void virt_xa_remove_xid (void *xid);
void *virt_xa_id (char *xid_str);
caddr_t virt_xa_xid_in_log (void *xid);
int virt_xa_replay_trx (void *xid, caddr_t trx, struct client_connection_s *cli);
int virt_xa_add_trx (void *xid, struct lock_trx_s * lt);

int xa_wait_commit (struct tp_data_s *tpd);
/* #endif _MTX_ */


/*
  xa transaction persistent info structures
*/
typedef struct txa_entry_s
{
  char *txe_id;
  char *txe_path;
  caddr_t txe_offset;
  char *txe_res;
} txa_entry_t;
/*
   info: id, file_path, offsets, res
   res = "PRP", "CMT", "RLL",
*/
typedef struct txa_info_s
{
  char *txi_trx_file;
  int txi_fd;
  caddr_t *txi_info;
  txa_entry_t **txi_parsed_info;
} txa_info_t;
#define TXE_ITEMS	4
void txa_from_trx (struct lock_trx_s *lt, char *log_file_name);
void txa_remove_entry (void *xid, int check);
txa_entry_t *txa_search_trx (void *xid);
int lt_2pc_commit (struct lock_trx_s *lt);
void virt_xa_tp_set_xid (tp_data_t * tpd, void *xid);

#define IS_ENLISTED_TXN(qi) \
    ( ((TP_MTS_TYPE == (qi)->qi_trx->lt_2pc._2pc_type)) || \
       ((qi)->qi_client->cli_tp_data && \
	(CONNECTION_ENLISTED == (qi)->qi_client->cli_tp_data->cli_tp_enlisted)) )

EXE_EXPORT (int, server_logmsg_ap, (int level, char *file, int line, int mask,
	char *format, va_list ap));
#endif /* TPC_H */