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 :
34 :
35 : int main(int argc __attribute__((unused)), char *argv[])
36 1 : {
37 : ulong i;
38 : uint pagen;
39 : uchar long_tr_id[6];
40 : PAGECACHE pagecache;
41 1 : LSN lsn, max_lsn, last_lsn= LSN_IMPOSSIBLE;
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 :
53 1 : bzero(long_tr_id, 6);
54 : #ifndef DBUG_OFF
55 : #if defined(__WIN__)
56 : default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
57 : #else
58 1 : default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
59 : #endif
60 1 : if (argc > 1)
61 : {
62 0 : DBUG_SET(default_dbug_option);
63 0 : DBUG_SET_INITIAL(default_dbug_option);
64 : }
65 : #endif
66 :
67 1 : if (ma_control_file_open(TRUE, TRUE))
68 : {
69 0 : fprintf(stderr, "Can't init control file (%d)\n", errno);
70 0 : exit(1);
71 : }
72 1 : if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
73 : PCACHE_PAGE, 0)) == 0)
74 : {
75 0 : fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
76 0 : exit(1);
77 : }
78 1 : if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
79 : LOG_FLAGS, 0, &translog_example_table_init,
80 : 0))
81 : {
82 0 : fprintf(stderr, "Can't init loghandler (%d)\n", errno);
83 0 : exit(1);
84 : }
85 : /* Suppressing of automatic record writing */
86 1 : dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
87 :
88 1 : max_lsn= translog_get_file_max_lsn_stored(1);
89 1 : if (max_lsn == 1)
90 : {
91 0 : fprintf(stderr, "Error reading the first log file.");
92 0 : translog_destroy();
93 0 : exit(1);
94 : }
95 1 : if (max_lsn != LSN_IMPOSSIBLE)
96 : {
97 0 : fprintf(stderr, "Incorrect first lsn response (%lu,0x%lx).",
98 : LSN_IN_PARTS(max_lsn));
99 0 : translog_destroy();
100 0 : exit(1);
101 : }
102 1 : ok(1, "Empty log response");
103 :
104 :
105 : /* write more then 1 file */
106 1 : int4store(long_tr_id, 0);
107 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
108 1 : parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
109 1398102 : for(i= 0; i < LOG_FILE_SIZE/6; i++)
110 : {
111 1398101 : if (translog_write_record(&lsn,
112 : LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
113 : &dummy_transaction_object, NULL, 6,
114 : TRANSLOG_INTERNAL_PARTS + 1,
115 : parts, NULL, NULL))
116 : {
117 0 : fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
118 0 : translog_destroy();
119 0 : exit(1);
120 : }
121 1398101 : if (LSN_FILE_NO(lsn) == 1)
122 929907 : last_lsn= lsn;
123 : }
124 :
125 :
126 1 : max_lsn= translog_get_file_max_lsn_stored(1);
127 1 : if (max_lsn == 1)
128 : {
129 0 : fprintf(stderr, "Error reading the first log file\n");
130 0 : translog_destroy();
131 0 : exit(1);
132 : }
133 1 : if (max_lsn == LSN_IMPOSSIBLE)
134 : {
135 0 : fprintf(stderr, "Isn't first file still finished?!!\n");
136 0 : translog_destroy();
137 0 : exit(1);
138 : }
139 1 : if (max_lsn != last_lsn)
140 : {
141 0 : fprintf(stderr, "Incorrect max lsn: (%lu,0x%lx) "
142 : " last lsn on first file: (%lu,0x%lx)\n",
143 : LSN_IN_PARTS(max_lsn), LSN_IN_PARTS(last_lsn));
144 0 : translog_destroy();
145 0 : exit(1);
146 : }
147 :
148 1 : ok(1, "First file max LSN");
149 :
150 1 : translog_destroy();
151 1 : end_pagecache(&pagecache, 1);
152 1 : ma_control_file_end();
153 1 : if (maria_log_remove())
154 0 : exit(1);
155 1 : exit(0);
156 : }
|