CUBRID Engine  latest
log_writer.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_writer.h - DECLARATIONS FOR LOG WRITER (AT CLIENT & SERVER)
21  */
22 
23 #ifndef _LOG_WRITER_HEADER_
24 #define _LOG_WRITER_HEADER_
25 
26 #ident "$Id$"
27 
28 #include "client_credentials.hpp"
29 #include "log_archives.hpp"
30 #include "log_common_impl.h"
31 #include "log_lsa.hpp"
32 #include "tde.h"
33 #include "storage_common.h"
34 #if defined (SERVER_MODE)
35 #include "thread_compat.hpp"
36 #endif // SERVER_MODE
37 
38 #include <stdio.h>
39 
42 {
43  int rc;
45  bool shutdown;
46 };
47 
49 {
53 };
54 typedef enum logwr_mode LOGWR_MODE;
55 #define LOGWR_COPY_FROM_FIRST_PHY_PAGE_MASK (0x80000000)
56 
57 #if defined(CS_MODE)
58 enum logwr_action
59 {
60  LOGWR_ACTION_NONE = 0x00,
61  LOGWR_ACTION_DELAYED_WRITE = 0x01,
62  LOGWR_ACTION_ASYNC_WRITE = 0x02,
63  LOGWR_ACTION_HDR_WRITE = 0x04,
64  LOGWR_ACTION_ARCHIVING = 0x08
65 };
66 typedef enum logwr_action LOGWR_ACTION;
67 
68 typedef struct logwr_global LOGWR_GLOBAL;
69 struct logwr_global
70 {
71  LOG_HEADER hdr;
72  LOG_PAGE *loghdr_pgptr;
73 
74  char db_name[PATH_MAX];
75  char *hostname;
76  char log_path[PATH_MAX];
77  char loginf_path[PATH_MAX];
78  char active_name[PATH_MAX];
79  int append_vdes;
80 
81  char *logpg_area;
82  int logpg_area_size;
83  int logpg_fill_size;
84 
85  LOG_PAGE **toflush;
86  int max_toflush;
87  int num_toflush;
88 
90  LOGWR_ACTION action;
91 
92  LOG_PAGEID last_chkpt_pageid;
93  LOG_PAGEID last_recv_pageid;
94  LOG_PAGEID last_arv_fpageid;
95  LOG_PAGEID last_arv_lpageid;
96  int last_arv_num;
97 
98  bool force_flush;
99  struct timeval last_flush_time;
100  /* background log archiving info */
101  BACKGROUND_ARCHIVING_INFO bg_archive_info;
102  char bg_archive_name[PATH_MAX];
103 
104  /* original next logical page to archive */
105  LOG_PAGEID ori_nxarv_pageid;
106 
107  /* start pageid */
108  LOG_PAGEID start_pageid;
109 
110  bool reinit_copylog;
111 };
112 
113 #define LOGWR_AT_NEXT_ARCHIVE_PAGE_ID(pageid) \
114  (logwr_to_physical_pageid(pageid) == logwr_Gl.hdr.nxarv_phy_pageid)
115 
116 #define LOGWR_IS_ARCHIVE_PAGE(pageid) \
117  ((pageid) != LOGPB_HEADER_PAGE_ID && (pageid) < logwr_Gl.hdr.nxarv_pageid)
118 
119 #define LOGWR_AT_SERVER_ARCHIVING() \
120  (LOGWR_AT_NEXT_ARCHIVE_PAGE_ID(logwr_Gl.hdr.append_lsa.pageid) \
121  && (logwr_Gl.hdr.eof_lsa.pageid < logwr_Gl.hdr.append_lsa.pageid))
122 
123 extern LOGWR_GLOBAL logwr_Gl;
124 extern void logwr_flush_header_page (void);
125 extern int logwr_write_log_pages (void);
126 extern int logwr_set_hdr_and_flush_info (void);
127 #if !defined(WINDOWS)
128 extern int logwr_copy_log_header_check (const char *db_name, bool verbose, LOG_LSA * master_eof_lsa);
129 #endif /* !WINDOWS */
130 #else /* !CS_MODE = SERVER_MODE || SA_MODE */
132 {
138 };
140 
141 typedef struct logwr_entry LOGWR_ENTRY;
143 {
154 };
155 
156 typedef struct logwr_info LOGWR_INFO;
158 {
160  pthread_mutex_t wr_list_mutex;
161  pthread_cond_t flush_start_cond;
162  pthread_mutex_t flush_start_mutex;
163  pthread_cond_t flush_wait_cond;
164  pthread_mutex_t flush_wait_mutex;
165  pthread_cond_t flush_end_cond;
166  pthread_mutex_t flush_end_mutex;
169  bool is_init;
170 
171  /* to measure the time spent by the last LWT delaying LFT */
175 
176  // *INDENT-OFF*
178  : writer_list (NULL)
179  , wr_list_mutex PTHREAD_MUTEX_INITIALIZER
180  , flush_start_cond PTHREAD_COND_INITIALIZER
181  , flush_start_mutex PTHREAD_MUTEX_INITIALIZER
182  , flush_wait_cond PTHREAD_COND_INITIALIZER
183  , flush_wait_mutex PTHREAD_MUTEX_INITIALIZER
184  , flush_end_cond PTHREAD_COND_INITIALIZER
185  , flush_end_mutex PTHREAD_MUTEX_INITIALIZER
186  , skip_flush (false)
187  , flush_completed (false)
188  , is_init (false)
189  , trace_last_writer (false)
190  , last_writer_client_info ()
191  , last_writer_elapsed_time (0)
192  {
193  }
194  // *INDENT-ON*
195 };
196 #endif /* !CS_MODE = SERVER_MODE || SA_MODE */
197 
198 extern bool logwr_force_shutdown (void);
199 extern int logwr_copy_log_file (const char *db_name, const char *log_path, int mode, INT64 start_page_id);
200 extern LOG_PHY_PAGEID logwr_to_physical_pageid (LOG_PAGEID logical_pageid);
201 extern const char *logwr_log_ha_filestat_to_string (enum LOG_HA_FILESTAT val);
202 #if 0
203 extern TDE_ALGORITHM logwr_get_tde_algorithm (const LOG_PAGE * log_pgptr);
204 extern void logwr_set_tde_algorithm (THREAD_ENTRY * thread_p, LOG_PAGE * log_pgptr, const TDE_ALGORITHM tde_algo);
205 #endif
206 
207 #if defined(SERVER_MODE)
208 int xlogwr_get_log_pages (THREAD_ENTRY * thread_p, LOG_PAGEID first_pageid, LOGWR_MODE mode);
209 extern LOG_PAGEID logwr_get_min_copied_fpageid (void);
210 
211 #endif /* SERVER_MODE */
212 #endif /* _LOG_WRITER_HEADER_ */
logwr_mode
Definition: log_writer.h:48
THREAD_ENTRY * thread_p
Definition: log_writer.h:144
pthread_mutex_t flush_end_mutex
Definition: log_writer.h:166
LOG_PAGEID fpageid
Definition: log_writer.h:145
LOG_LSA tmp_last_sent_eof_lsa
Definition: log_writer.h:150
pthread_mutex_t flush_start_mutex
Definition: log_writer.h:162
INT64 last_writer_elapsed_time
Definition: log_writer.h:174
CLIENTIDS last_writer_client_info
Definition: log_writer.h:173
LOG_LSA eof_lsa
Definition: log_writer.h:148
PAGEID LOG_PHY_PAGEID
pthread_mutex_t wr_list_mutex
Definition: log_writer.h:160
LOG_PHY_PAGEID logwr_to_physical_pageid(LOG_PAGEID logical_pageid)
pthread_cond_t flush_start_cond
Definition: log_writer.h:161
pthread_cond_t flush_wait_cond
Definition: log_writer.h:163
LOGWR_MODE mode
Definition: log_writer.h:146
const char * logwr_log_ha_filestat_to_string(enum LOG_HA_FILESTAT val)
Definition: log_writer.c:2041
LOGWR_STATUS status
Definition: log_writer.h:147
void THREAD_ENTRY
bool flush_completed
Definition: log_writer.h:168
Definition: log_writer.h:142
TDE_ALGORITHM
Definition: tde.h:71
INT64 start_copy_time
Definition: log_writer.h:151
enum logwr_status LOGWR_STATUS
Definition: log_writer.h:139
LOG_HA_FILESTAT
static enum scanner_mode mode
bool skip_flush
Definition: log_writer.h:167
pthread_mutex_t flush_wait_mutex
Definition: log_writer.h:164
INT64 LOG_PAGEID
#define NULL
Definition: freelistheap.h:34
LOGWR_ENTRY * writer_list
Definition: log_writer.h:159
bool copy_from_first_phy_page
Definition: log_writer.h:152
pthread_cond_t flush_end_cond
Definition: log_writer.h:165
char * db_name
int logwr_copy_log_file(const char *db_name, const char *log_path, int mode, INT64 start_page_id)
Definition: log_writer.c:1960
bool is_init
Definition: log_writer.h:169
bool trace_last_writer
Definition: log_writer.h:172
enum logwr_mode LOGWR_MODE
Definition: log_writer.h:54
LOG_LSA last_sent_eof_lsa
Definition: log_writer.h:149
bool logwr_force_shutdown(void)
logwr_status
Definition: log_writer.h:131
LOGWR_ENTRY * next
Definition: log_writer.h:153