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 (8*1024L*1024L)
32 : #define LOG_FLAGS 0
33 : #define LONG_BUFFER_SIZE (LOG_FILE_SIZE + LOG_FILE_SIZE / 2)
34 :
35 :
36 : int main(int argc __attribute__((unused)), char *argv[])
37 1 : {
38 : ulong i;
39 : uint pagen;
40 : uchar long_tr_id[6];
41 : PAGECACHE pagecache;
42 : LSN lsn;
43 : LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1];
44 1 : uchar *long_buffer= malloc(LONG_BUFFER_SIZE);
45 :
46 1 : MY_INIT(argv[0]);
47 :
48 1 : plan(4);
49 :
50 1 : bzero(&pagecache, sizeof(pagecache));
51 1 : bzero(long_buffer, LONG_BUFFER_SIZE);
52 1 : maria_data_root= (char *)".";
53 1 : if (maria_log_remove())
54 0 : exit(1);
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 : /* write more then 1 file */
92 1 : int4store(long_tr_id, 0);
93 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
94 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
95 1 : if (translog_write_record(&lsn,
96 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
97 : &dummy_transaction_object, NULL, 6,
98 : TRANSLOG_INTERNAL_PARTS + 1,
99 : parts, NULL, NULL))
100 : {
101 0 : fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
102 0 : translog_destroy();
103 0 : exit(1);
104 : }
105 :
106 1 : translog_purge(lsn);
107 1 : if (!translog_is_file(1))
108 : {
109 0 : fprintf(stderr, "First file was removed after first record\n");
110 0 : translog_destroy();
111 0 : exit(1);
112 : }
113 1 : ok(1, "First is not removed");
114 :
115 929908 : for(i= 0; i < LOG_FILE_SIZE/6 && LSN_FILE_NO(lsn) == 1; i++)
116 : {
117 929907 : if (translog_write_record(&lsn,
118 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
119 : &dummy_transaction_object, NULL, 6,
120 : TRANSLOG_INTERNAL_PARTS + 1,
121 : parts, NULL, NULL))
122 : {
123 0 : fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
124 0 : translog_destroy();
125 0 : exit(1);
126 : }
127 : }
128 :
129 1 : translog_purge(lsn);
130 1 : if (translog_is_file(1))
131 : {
132 0 : fprintf(stderr, "First file was not removed.\n");
133 0 : translog_destroy();
134 0 : exit(1);
135 : }
136 :
137 1 : ok(1, "First file is removed");
138 :
139 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_buffer;
140 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= LONG_BUFFER_SIZE;
141 1 : if (translog_write_record(&lsn,
142 : LOGREC_VARIABLE_RECORD_0LSN_EXAMPLE,
143 : &dummy_transaction_object, NULL, LONG_BUFFER_SIZE,
144 : TRANSLOG_INTERNAL_PARTS + 1, parts, NULL, NULL))
145 : {
146 0 : fprintf(stderr, "Can't write variable record\n");
147 0 : translog_destroy();
148 0 : exit(1);
149 : }
150 :
151 1 : translog_purge(lsn);
152 1 : if (!translog_is_file(2) || !translog_is_file(3))
153 : {
154 0 : fprintf(stderr, "Second file (%d) or third file (%d) is not present.\n",
155 : translog_is_file(2), translog_is_file(3));
156 0 : translog_destroy();
157 0 : exit(1);
158 : }
159 :
160 1 : ok(1, "Second and third files are not removed");
161 :
162 1 : int4store(long_tr_id, 0);
163 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
164 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
165 1 : if (translog_write_record(&lsn,
166 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
167 : &dummy_transaction_object, NULL, 6,
168 : TRANSLOG_INTERNAL_PARTS + 1,
169 : parts, NULL, NULL))
170 : {
171 0 : fprintf(stderr, "Can't write last record\n");
172 0 : translog_destroy();
173 0 : exit(1);
174 : }
175 :
176 1 : translog_purge(lsn);
177 1 : if (translog_is_file(2))
178 : {
179 0 : fprintf(stderr, "Second file is not removed\n");
180 0 : translog_destroy();
181 0 : exit(1);
182 : }
183 :
184 1 : ok(1, "Second file is removed");
185 :
186 1 : translog_destroy();
187 1 : end_pagecache(&pagecache, 1);
188 1 : ma_control_file_end();
189 1 : if (maria_log_remove())
190 0 : exit(1);
191 1 : exit(0);
192 : }
|