1 : /* Copyright (C) 2006-2008 MySQL AB
2 :
3 : This program is free software; you can redistribute it and/or modify
4 : it under the terms of the GNU General Public License as published by
5 : the Free Software Foundation; version 2 of the License.
6 :
7 : This program is distributed in the hope that it will be useful,
8 : but WITHOUT ANY WARRANTY; without even the implied warranty of
9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 : GNU General Public License for more details.
11 :
12 : You should have received a copy of the GNU General Public License
13 : along with this program; if not, write to the Free Software
14 : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15 :
16 : #include "../maria_def.h"
17 : #include <stdio.h>
18 : #include <errno.h>
19 : #include <tap.h>
20 : #include "../trnman.h"
21 :
22 : extern my_bool maria_log_remove();
23 : extern void translog_example_table_init();
24 :
25 : #ifndef DBUG_OFF
26 : static const char *default_dbug_option;
27 : #endif
28 :
29 : #define PCACHE_SIZE (1024*1024*10)
30 : #define PCACHE_PAGE TRANSLOG_PAGE_SIZE
31 : #define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
32 : #define LOG_FLAGS 0
33 :
34 : static char *first_translog_file= (char*)"maria_log.00000001";
35 :
36 : int main(int argc __attribute__((unused)), char *argv[])
37 1 : {
38 : uint pagen;
39 : uchar long_tr_id[6];
40 : PAGECACHE pagecache;
41 : LSN lsn, first_lsn, theor_lsn;
42 : LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1];
43 :
44 1 : MY_INIT(argv[0]);
45 :
46 1 : plan(2);
47 :
48 1 : bzero(&pagecache, sizeof(pagecache));
49 1 : maria_data_root= (char *)".";
50 1 : if (maria_log_remove())
51 0 : exit(1);
52 : /* be sure that we have no logs in the directory*/
53 1 : my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
54 1 : my_delete(first_translog_file, MYF(0));
55 :
56 1 : bzero(long_tr_id, 6);
57 : #ifndef DBUG_OFF
58 : #if defined(__WIN__)
59 : default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
60 : #else
61 1 : default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
62 : #endif
63 1 : if (argc > 1)
64 : {
65 0 : DBUG_SET(default_dbug_option);
66 0 : DBUG_SET_INITIAL(default_dbug_option);
67 : }
68 : #endif
69 :
70 1 : if (ma_control_file_open(TRUE, TRUE))
71 : {
72 0 : fprintf(stderr, "Can't init control file (%d)\n", errno);
73 0 : exit(1);
74 : }
75 1 : if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
76 : PCACHE_PAGE, 0)) == 0)
77 : {
78 0 : fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
79 0 : exit(1);
80 : }
81 1 : if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
82 : LOG_FLAGS, 0, &translog_example_table_init,
83 : 0))
84 : {
85 0 : fprintf(stderr, "Can't init loghandler (%d)\n", errno);
86 0 : exit(1);
87 : }
88 : /* Suppressing of automatic record writing */
89 1 : dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
90 :
91 1 : theor_lsn= translog_first_theoretical_lsn();
92 1 : if (theor_lsn == 1)
93 : {
94 0 : fprintf(stderr, "Error reading the first log file.");
95 0 : translog_destroy();
96 0 : exit(1);
97 : }
98 1 : if (theor_lsn == LSN_IMPOSSIBLE)
99 : {
100 0 : fprintf(stderr, "There is no first log file.");
101 0 : translog_destroy();
102 0 : exit(1);
103 : }
104 1 : first_lsn= translog_first_lsn_in_log();
105 1 : if (first_lsn != LSN_IMPOSSIBLE)
106 : {
107 0 : fprintf(stderr, "Incorrect first lsn response (%lu,0x%lx).",
108 : LSN_IN_PARTS(first_lsn));
109 0 : translog_destroy();
110 0 : exit(1);
111 : }
112 1 : ok(1, "Empty log response");
113 :
114 :
115 1 : int4store(long_tr_id, 0);
116 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
117 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
118 1 : if (translog_write_record(&lsn,
119 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
120 : &dummy_transaction_object, NULL, 6,
121 : TRANSLOG_INTERNAL_PARTS + 1,
122 : parts, NULL, NULL))
123 : {
124 0 : fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
125 0 : translog_destroy();
126 0 : exit(1);
127 : }
128 :
129 1 : theor_lsn= translog_first_theoretical_lsn();
130 1 : if (theor_lsn == 1)
131 : {
132 0 : fprintf(stderr, "Error reading the first log file\n");
133 0 : translog_destroy();
134 0 : exit(1);
135 : }
136 1 : if (theor_lsn == LSN_IMPOSSIBLE)
137 : {
138 0 : fprintf(stderr, "There is no first log file\n");
139 0 : translog_destroy();
140 0 : exit(1);
141 : }
142 1 : first_lsn= translog_first_lsn_in_log();
143 1 : if (first_lsn != theor_lsn)
144 : {
145 0 : fprintf(stderr, "Incorrect first lsn: (%lu,0x%lx) "
146 : " theoretical first: (%lu,0x%lx)\n",
147 : LSN_IN_PARTS(first_lsn), LSN_IN_PARTS(theor_lsn));
148 0 : translog_destroy();
149 0 : exit(1);
150 : }
151 :
152 1 : ok(1, "Full log response");
153 :
154 1 : translog_destroy();
155 1 : end_pagecache(&pagecache, 1);
156 1 : ma_control_file_end();
157 1 : if (maria_log_remove())
158 0 : exit(1);
159 1 : exit(0);
160 : }
|