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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
15
16#include "../maria_def.h"
17#include <stdio.h>
18#include <errno.h>
19#include <tap.h>
20#include "../trnman.h"
21
22extern my_bool maria_log_remove(const char *testdir);
23extern char *create_tmpdir(const char *progname);
24extern void translog_example_table_init();
25
26#ifndef DBUG_OFF
27static const char *default_dbug_option;
28#endif
29
30#define PCACHE_SIZE (1024*1024*10)
31#define PCACHE_PAGE TRANSLOG_PAGE_SIZE
32#define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
33#define LOG_FLAGS 0
34
35
36int main(int argc __attribute__((unused)), char *argv[])
37{
38 uchar long_tr_id[6];
39 PAGECACHE pagecache;
40 LSN lsn, first_lsn, theor_lsn;
41 LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1];
42 MY_INIT(argv[0]);
43
44 plan(2);
45
46 bzero(&pagecache, sizeof(pagecache));
47 /*
48 Don't give an error if we can't create dir, as it may already exist from a previously aborted
49 run
50 */
51 maria_data_root= create_tmpdir(argv[0]);
52 if (maria_log_remove(0))
53 exit(1);
54
55 bzero(long_tr_id, 6);
56#ifndef DBUG_OFF
57#if defined(__WIN__)
58 default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
59#else
60 default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
61#endif
62 if (argc > 1)
63 {
64 DBUG_SET(default_dbug_option);
65 DBUG_SET_INITIAL(default_dbug_option);
66 }
67#endif
68
69 if (ma_control_file_open(TRUE, TRUE))
70 {
71 fprintf(stderr, "Can't init control file (%d)\n", errno);
72 exit(1);
73 }
74 if (init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
75 PCACHE_PAGE, 0, 0) == 0)
76 {
77 fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
78 exit(1);
79 }
80 if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache,
81 LOG_FLAGS, 0, &translog_example_table_init, 0))
82 {
83 fprintf(stderr, "Can't init loghandler (%d)\n", errno);
84 exit(1);
85 }
86 /* Suppressing of automatic record writing */
87 dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
88
89 theor_lsn= translog_first_theoretical_lsn();
90 if (theor_lsn == 1)
91 {
92 fprintf(stderr, "Error reading the first log file.");
93 translog_destroy();
94 exit(1);
95 }
96 if (theor_lsn == LSN_IMPOSSIBLE)
97 {
98 fprintf(stderr, "There is no first log file.");
99 translog_destroy();
100 exit(1);
101 }
102 first_lsn= translog_first_lsn_in_log();
103 if (first_lsn != LSN_IMPOSSIBLE)
104 {
105 fprintf(stderr, "Incorrect first lsn response " LSN_FMT ".",
106 LSN_IN_PARTS(first_lsn));
107 translog_destroy();
108 exit(1);
109 }
110 ok(1, "Empty log response");
111
112
113 int4store(long_tr_id, 0);
114 parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
115 parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
116 if (translog_write_record(&lsn,
117 LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
118 &dummy_transaction_object, NULL, 6,
119 TRANSLOG_INTERNAL_PARTS + 1,
120 parts, NULL, NULL))
121 {
122 fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
123 translog_destroy();
124 exit(1);
125 }
126
127 theor_lsn= translog_first_theoretical_lsn();
128 if (theor_lsn == 1)
129 {
130 fprintf(stderr, "Error reading the first log file\n");
131 translog_destroy();
132 exit(1);
133 }
134 if (theor_lsn == LSN_IMPOSSIBLE)
135 {
136 fprintf(stderr, "There is no first log file\n");
137 translog_destroy();
138 exit(1);
139 }
140 first_lsn= translog_first_lsn_in_log();
141 if (first_lsn != theor_lsn)
142 {
143 fprintf(stderr, "Incorrect first lsn: " LSN_FMT " "
144 " theoretical first: " LSN_FMT "\n",
145 LSN_IN_PARTS(first_lsn), LSN_IN_PARTS(theor_lsn));
146 translog_destroy();
147 exit(1);
148 }
149
150 ok(1, "Full log response");
151
152 translog_destroy();
153 end_pagecache(&pagecache, 1);
154 ma_control_file_end();
155 if (maria_log_remove(maria_data_root))
156 exit(1);
157
158 my_uuid_end();
159 my_free_open_file_info();
160 my_end(0);
161
162 exit(0);
163}
164
165#include "../ma_check_standalone.h"
166