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 example_loghandler_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(2);
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 #0\n");
102 0 : translog_destroy();
103 0 : exit(1);
104 : }
105 :
106 929908 : for(i= 0; i < LOG_FILE_SIZE/6 && LSN_FILE_NO(lsn) == 1; i++)
107 : {
108 929907 : if (translog_write_record(&lsn,
109 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
110 : &dummy_transaction_object, NULL, 6,
111 : TRANSLOG_INTERNAL_PARTS + 1,
112 : parts, NULL, NULL))
113 : {
114 0 : fprintf(stderr, "Can't write record #0\n");
115 0 : translog_destroy();
116 0 : exit(1);
117 : }
118 : }
119 :
120 1 : translog_destroy();
121 1 : end_pagecache(&pagecache, 1);
122 1 : ma_control_file_end();
123 :
124 : {
125 : char file_name[FN_REFLEN];
126 3 : for (i= 1; i <= 2; i++)
127 : {
128 2 : translog_filename_by_fileno(i, file_name);
129 2 : if (my_access(file_name, W_OK))
130 : {
131 0 : fprintf(stderr, "No file '%s'\n", file_name);
132 0 : exit(1);
133 : }
134 2 : if (my_delete(file_name, MYF(MY_WME)) != 0)
135 : {
136 0 : fprintf(stderr, "Error %d during removing file'%s'\n",
137 : errno, file_name);
138 0 : exit(1);
139 : }
140 : }
141 : }
142 :
143 1 : if (ma_control_file_open(TRUE, TRUE))
144 : {
145 0 : fprintf(stderr, "Can't init control file (%d)\n", errno);
146 0 : exit(1);
147 : }
148 1 : if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
149 : PCACHE_PAGE, 0)) == 0)
150 : {
151 0 : fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
152 0 : exit(1);
153 : }
154 1 : if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
155 : LOG_FLAGS, 0, &translog_example_table_init,
156 : 1))
157 : {
158 0 : fprintf(stderr, "Can't init loghandler (%d)\n", errno);
159 0 : exit(1);
160 : }
161 : /* Suppressing of automatic record writing */
162 1 : dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
163 :
164 1 : ok(1, "Log init OK");
165 :
166 1 : int4store(long_tr_id, 0);
167 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
168 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
169 1 : if (translog_write_record(&lsn,
170 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
171 : &dummy_transaction_object, NULL, 6,
172 : TRANSLOG_INTERNAL_PARTS + 1,
173 : parts, NULL, NULL))
174 : {
175 0 : fprintf(stderr, "Can't write record #0\n");
176 0 : translog_destroy();
177 0 : exit(1);
178 : }
179 :
180 1 : translog_destroy();
181 1 : end_pagecache(&pagecache, 1);
182 1 : ma_control_file_end();
183 :
184 1 : if (!translog_is_file(3))
185 : {
186 0 : fprintf(stderr, "No file #3\n");
187 0 : exit(1);
188 : }
189 :
190 1 : ok(1, "New log is OK");
191 :
192 1 : if (maria_log_remove())
193 0 : exit(1);
194 1 : exit(0);
195 : }
|