| 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 | |
| 22 | extern my_bool maria_log_remove(const char *testdir); |
| 23 | extern char *create_tmpdir(const char *progname); |
| 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 | { |
| 38 | ulong i; |
| 39 | uchar long_tr_id[6]; |
| 40 | PAGECACHE pagecache; |
| 41 | LSN lsn; |
| 42 | LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; |
| 43 | uchar *long_buffer= malloc(LONG_BUFFER_SIZE); |
| 44 | |
| 45 | MY_INIT(argv[0]); |
| 46 | |
| 47 | plan(2); |
| 48 | |
| 49 | bzero(&pagecache, sizeof(pagecache)); |
| 50 | bzero(long_buffer, LONG_BUFFER_SIZE); |
| 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, |
| 82 | 0)) |
| 83 | { |
| 84 | fprintf(stderr, "Can't init loghandler (%d)\n" , errno); |
| 85 | exit(1); |
| 86 | } |
| 87 | /* Suppressing of automatic record writing */ |
| 88 | dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; |
| 89 | |
| 90 | /* write more then 1 file */ |
| 91 | int4store(long_tr_id, 0); |
| 92 | parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; |
| 93 | parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; |
| 94 | if (translog_write_record(&lsn, |
| 95 | LOGREC_FIXED_RECORD_0LSN_EXAMPLE, |
| 96 | &dummy_transaction_object, NULL, 6, |
| 97 | TRANSLOG_INTERNAL_PARTS + 1, |
| 98 | parts, NULL, NULL)) |
| 99 | { |
| 100 | fprintf(stderr, "Can't write record #0\n" ); |
| 101 | translog_destroy(); |
| 102 | exit(1); |
| 103 | } |
| 104 | |
| 105 | for(i= 0; i < LOG_FILE_SIZE/6 && LSN_FILE_NO(lsn) == 1; i++) |
| 106 | { |
| 107 | if (translog_write_record(&lsn, |
| 108 | LOGREC_FIXED_RECORD_0LSN_EXAMPLE, |
| 109 | &dummy_transaction_object, NULL, 6, |
| 110 | TRANSLOG_INTERNAL_PARTS + 1, |
| 111 | parts, NULL, NULL)) |
| 112 | { |
| 113 | fprintf(stderr, "Can't write record #0\n" ); |
| 114 | translog_destroy(); |
| 115 | exit(1); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | translog_destroy(); |
| 120 | end_pagecache(&pagecache, 1); |
| 121 | ma_control_file_end(); |
| 122 | |
| 123 | { |
| 124 | char file_name[FN_REFLEN]; |
| 125 | for (i= 1; i <= 2; i++) |
| 126 | { |
| 127 | translog_filename_by_fileno(i, file_name); |
| 128 | if (my_access(file_name, W_OK)) |
| 129 | { |
| 130 | fprintf(stderr, "No file '%s'\n" , file_name); |
| 131 | exit(1); |
| 132 | } |
| 133 | if (my_delete(file_name, MYF(MY_WME)) != 0) |
| 134 | { |
| 135 | fprintf(stderr, "Error %d during removing file'%s'\n" , |
| 136 | errno, file_name); |
| 137 | exit(1); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (ma_control_file_open(TRUE, TRUE)) |
| 143 | { |
| 144 | fprintf(stderr, "Can't init control file (%d)\n" , errno); |
| 145 | exit(1); |
| 146 | } |
| 147 | if (init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, |
| 148 | PCACHE_PAGE, 0, 0) == 0) |
| 149 | { |
| 150 | fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n" , errno); |
| 151 | exit(1); |
| 152 | } |
| 153 | if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, |
| 154 | LOG_FLAGS, 0, &translog_example_table_init, |
| 155 | 1)) |
| 156 | { |
| 157 | fprintf(stderr, "Can't init loghandler (%d)\n" , errno); |
| 158 | exit(1); |
| 159 | } |
| 160 | /* Suppressing of automatic record writing */ |
| 161 | dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; |
| 162 | |
| 163 | ok(1, "Log init OK" ); |
| 164 | |
| 165 | int4store(long_tr_id, 0); |
| 166 | parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; |
| 167 | parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; |
| 168 | if (translog_write_record(&lsn, |
| 169 | LOGREC_FIXED_RECORD_0LSN_EXAMPLE, |
| 170 | &dummy_transaction_object, NULL, 6, |
| 171 | TRANSLOG_INTERNAL_PARTS + 1, |
| 172 | parts, NULL, NULL)) |
| 173 | { |
| 174 | fprintf(stderr, "Can't write record #0\n" ); |
| 175 | translog_destroy(); |
| 176 | exit(1); |
| 177 | } |
| 178 | |
| 179 | translog_destroy(); |
| 180 | end_pagecache(&pagecache, 1); |
| 181 | ma_control_file_end(); |
| 182 | |
| 183 | if (!translog_is_file(3)) |
| 184 | { |
| 185 | fprintf(stderr, "No file #3\n" ); |
| 186 | exit(1); |
| 187 | } |
| 188 | |
| 189 | ok(1, "New log is OK" ); |
| 190 | |
| 191 | if (maria_log_remove(maria_data_root)) |
| 192 | exit(1); |
| 193 | |
| 194 | free(long_buffer); |
| 195 | |
| 196 | my_uuid_end(); |
| 197 | my_free_open_file_info(); |
| 198 | my_end(0); |
| 199 | |
| 200 | exit(0); |
| 201 | } |
| 202 | |
| 203 | #include "../ma_check_standalone.h" |
| 204 | |