CUBRID Engine  latest
log_2pc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // Log 2 phase commit
21 //
22 
23 #ifndef _LOG_2PC_H_
24 #define _LOG_2PC_H_
25 
26 #if !defined (SERVER_MODE) && !defined (SA_MODE)
27 #error Wrong module
28 #endif
29 
30 #include "log_comm.h"
31 #include "log_lsa.hpp"
32 #include "log_storage.hpp"
33 #include "thread_compat.hpp"
34 
35 #include <cstdio>
36 
37 // forward declarations
38 struct log_tdes;
39 
40 const int LOG_2PC_NULL_GTRID = -1;
41 const bool LOG_2PC_OBTAIN_LOCKS = true;
42 const bool LOG_2PC_DONT_OBTAIN_LOCKS = false;
43 
45 {
46  LOG_2PC_EXECUTE_FULL, /* For the root coordinator */
47  LOG_2PC_EXECUTE_PREPARE, /* For a participant that is also a non root coordinator execute the first phase of 2PC */
48  LOG_2PC_EXECUTE_COMMIT_DECISION, /* For a participant that is also a non root coordinator execute the second
49  * phase of 2PC. The root coordinator has decided a commit decision */
50  LOG_2PC_EXECUTE_ABORT_DECISION /* For a participant that is also a non root coordinator execute the second
51  * phase of 2PC. The root coordinator has decided an abort decision with or
52  * without going to the first phase (i.e., prepare) of the 2PC */
53 };
55 
58 { /* Global transaction user information */
60  void *info_data;
61 };
62 
65 { /* Coordinator maintains this info */
66  int num_particps; /* Number of participating sites */
67  int particp_id_length; /* Length of a participant identifier */
68  void *block_particps_ids; /* A block of participants identifiers */
69  int *ack_received; /* Acknowledgment received vector */
70 };
71 
72 char *log_2pc_sprintf_particp (void *particp_id);
73 void log_2pc_dump_participants (FILE * fp, int block_length, void *block_particps_ids);
74 bool log_2pc_send_prepare (int gtrid, int num_particps, void *block_particps_ids);
75 bool log_2pc_send_commit_decision (int gtrid, int num_particps, int *particps_indices, void *block_particps_ids);
76 bool log_2pc_send_abort_decision (int gtrid, int num_particps, int *particps_indices, void *block_particps_ids,
77  bool collect);
78 TRAN_STATE log_2pc_commit (THREAD_ENTRY * thread_p, log_tdes * tdes, LOG_2PC_EXECUTE execute_2pc_type, bool * decision);
79 int log_2pc_set_global_tran_info (THREAD_ENTRY * thread_p, int gtrid, void *info, int size);
80 int log_2pc_get_global_tran_info (THREAD_ENTRY * thread_p, int gtrid, void *buffer, int size);
81 int log_2pc_start (THREAD_ENTRY * thread_p);
83 int log_2pc_recovery_prepared (THREAD_ENTRY * thread_p, int gtrids[], int size);
84 int log_2pc_attach_global_tran (THREAD_ENTRY * thread_p, int gtrid);
85 
87 void log_2pc_read_prepare (THREAD_ENTRY * thread_p, int acquire_locks, log_tdes * tdes, LOG_LSA * lsa,
88  LOG_PAGE * log_pgptr);
89 void log_2pc_dump_gtrinfo (FILE * fp, int length, void *data);
90 void log_2pc_dump_acqobj_locks (FILE * fp, int length, void *data);
91 log_tdes *log_2pc_alloc_coord_info (log_tdes * tdes, int num_particps, int particp_id_length, void *block_particps_ids);
92 void log_2pc_free_coord_info (log_tdes * tdes);
93 void log_2pc_recovery_analysis_info (THREAD_ENTRY * thread_p, log_tdes * tdes, LOG_LSA * upto_chain_lsa);
94 void log_2pc_recovery (THREAD_ENTRY * thread_p);
97 
98 #endif // !_LOG_2PC_H_
bool log_2pc_send_prepare(int gtrid, int num_particps, void *block_particps_ids)
Definition: log_2pc.c:214
log_tdes * log_2pc_alloc_coord_info(log_tdes *tdes, int num_particps, int particp_id_length, void *block_particps_ids)
Definition: log_2pc.c:1581
char * log_2pc_sprintf_particp(void *particp_id)
Definition: log_2pc.c:162
int info_length
Definition: log_2pc.h:59
void log_2pc_read_prepare(THREAD_ENTRY *thread_p, int acquire_locks, log_tdes *tdes, LOG_LSA *lsa, LOG_PAGE *log_pgptr)
Definition: log_2pc.c:1349
const int LOG_2PC_NULL_GTRID
Definition: log_2pc.h:40
void * block_particps_ids
Definition: log_2pc.h:68
TRAN_STATE log_2pc_prepare_global_tran(THREAD_ENTRY *thread_p, int gtrid)
Definition: log_2pc.c:1162
const bool LOG_2PC_OBTAIN_LOCKS
Definition: log_2pc.h:41
void THREAD_ENTRY
log_2pc_execute
Definition: log_2pc.h:44
int log_2pc_attach_global_tran(THREAD_ENTRY *thread_p, int gtrid)
Definition: log_2pc.c:1080
bool log_2pc_send_abort_decision(int gtrid, int num_particps, int *particps_indices, void *block_particps_ids, bool collect)
Definition: log_2pc.c:295
bool log_2pc_clear_and_is_tran_distributed(log_tdes *tdes)
Definition: log_2pc.c:2412
void log_2pc_dump_gtrinfo(FILE *fp, int length, void *data)
Definition: log_2pc.c:1435
void log_2pc_recovery(THREAD_ENTRY *thread_p)
Definition: log_2pc.c:2262
int * ack_received
Definition: log_2pc.h:69
int log_2pc_recovery_prepared(THREAD_ENTRY *thread_p, int gtrids[], int size)
Definition: log_2pc.c:959
int log_2pc_get_global_tran_info(THREAD_ENTRY *thread_p, int gtrid, void *buffer, int size)
Definition: log_2pc.c:816
void * info_data
Definition: log_2pc.h:60
int log_2pc_start(THREAD_ENTRY *thread_p)
Definition: log_2pc.c:877
bool log_2pc_is_tran_distributed(log_tdes *tdes)
Definition: log_2pc.c:2373
void log_2pc_recovery_analysis_info(THREAD_ENTRY *thread_p, log_tdes *tdes, LOG_LSA *upto_chain_lsa)
Definition: log_2pc.c:1988
void log_2pc_free_coord_info(log_tdes *tdes)
Definition: log_2pc.c:1611
void log_2pc_dump_acqobj_locks(FILE *fp, int length, void *data)
Definition: log_2pc.c:1450
enum log_2pc_execute LOG_2PC_EXECUTE
Definition: log_2pc.h:54
int log_2pc_set_global_tran_info(THREAD_ENTRY *thread_p, int gtrid, void *info, int size)
Definition: log_2pc.c:749
void log_2pc_dump_participants(FILE *fp, int block_length, void *block_particps_ids)
Definition: log_2pc.c:184
TRAN_STATE log_2pc_prepare(THREAD_ENTRY *thread_p)
Definition: log_2pc.c:921
TRAN_STATE
Definition: log_comm.h:36
TRAN_STATE log_2pc_commit(THREAD_ENTRY *thread_p, log_tdes *tdes, LOG_2PC_EXECUTE execute_2pc_type, bool *decision)
Definition: log_2pc.c:676
const bool LOG_2PC_DONT_OBTAIN_LOCKS
Definition: log_2pc.h:42
bool log_2pc_send_commit_decision(int gtrid, int num_particps, int *particps_indices, void *block_particps_ids)
Definition: log_2pc.c:251