| 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 | extern void translog_example_table_init(); |
| 25 | |
| 26 | #ifndef DBUG_OFF |
| 27 | static 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 (8*1024L*1024L) |
| 33 | #define LOG_FLAGS 0 |
| 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, max_lsn, last_lsn= LSN_IMPOSSIBLE; |
| 42 | LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; |
| 43 | MY_INIT(argv[0]); |
| 44 | |
| 45 | plan(2); |
| 46 | |
| 47 | bzero(&pagecache, sizeof(pagecache)); |
| 48 | |
| 49 | maria_data_root= create_tmpdir(argv[0]); |
| 50 | if (maria_log_remove(0)) |
| 51 | exit(1); |
| 52 | |
| 53 | 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 | default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace" ; |
| 59 | #endif |
| 60 | if (argc > 1) |
| 61 | { |
| 62 | DBUG_SET(default_dbug_option); |
| 63 | DBUG_SET_INITIAL(default_dbug_option); |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | if (ma_control_file_open(TRUE, TRUE)) |
| 68 | { |
| 69 | fprintf(stderr, "Can't init control file (%d)\n" , errno); |
| 70 | exit(1); |
| 71 | } |
| 72 | if (init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, |
| 73 | PCACHE_PAGE, 0, 0) == 0) |
| 74 | { |
| 75 | fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n" , errno); |
| 76 | exit(1); |
| 77 | } |
| 78 | if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, |
| 79 | LOG_FLAGS, 0, &translog_example_table_init, |
| 80 | 0)) |
| 81 | { |
| 82 | fprintf(stderr, "Can't init loghandler (%d)\n" , errno); |
| 83 | exit(1); |
| 84 | } |
| 85 | /* Suppressing of automatic record writing */ |
| 86 | dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; |
| 87 | |
| 88 | max_lsn= translog_get_file_max_lsn_stored(1); |
| 89 | if (max_lsn == 1) |
| 90 | { |
| 91 | fprintf(stderr, "Error reading the first log file." ); |
| 92 | translog_destroy(); |
| 93 | exit(1); |
| 94 | } |
| 95 | if (max_lsn != LSN_IMPOSSIBLE) |
| 96 | { |
| 97 | fprintf(stderr, "Incorrect first lsn response " LSN_FMT "." , |
| 98 | LSN_IN_PARTS(max_lsn)); |
| 99 | translog_destroy(); |
| 100 | exit(1); |
| 101 | } |
| 102 | ok(1, "Empty log response" ); |
| 103 | |
| 104 | |
| 105 | /* write more then 1 file */ |
| 106 | int4store(long_tr_id, 0); |
| 107 | parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; |
| 108 | parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; |
| 109 | for(i= 0; i < LOG_FILE_SIZE/6; i++) |
| 110 | { |
| 111 | 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 | fprintf(stderr, "Can't write record #%lu\n" , (ulong) 0); |
| 118 | translog_destroy(); |
| 119 | exit(1); |
| 120 | } |
| 121 | if (LSN_FILE_NO(lsn) == 1) |
| 122 | last_lsn= lsn; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | max_lsn= translog_get_file_max_lsn_stored(1); |
| 127 | if (max_lsn == 1) |
| 128 | { |
| 129 | fprintf(stderr, "Error reading the first log file\n" ); |
| 130 | translog_destroy(); |
| 131 | exit(1); |
| 132 | } |
| 133 | if (max_lsn == LSN_IMPOSSIBLE) |
| 134 | { |
| 135 | fprintf(stderr, "Isn't first file still finished?!!\n" ); |
| 136 | translog_destroy(); |
| 137 | exit(1); |
| 138 | } |
| 139 | if (max_lsn != last_lsn) |
| 140 | { |
| 141 | fprintf(stderr, "Incorrect max lsn: " LSN_FMT " " |
| 142 | " last lsn on first file: " LSN_FMT "\n" , |
| 143 | LSN_IN_PARTS(max_lsn), LSN_IN_PARTS(last_lsn)); |
| 144 | translog_destroy(); |
| 145 | exit(1); |
| 146 | } |
| 147 | |
| 148 | ok(1, "First file max LSN" ); |
| 149 | |
| 150 | translog_destroy(); |
| 151 | end_pagecache(&pagecache, 1); |
| 152 | ma_control_file_end(); |
| 153 | if (maria_log_remove(maria_data_root)) |
| 154 | exit(1); |
| 155 | |
| 156 | my_uuid_end(); |
| 157 | my_free_open_file_info(); |
| 158 | my_end(0); |
| 159 | |
| 160 | exit(0); |
| 161 | } |
| 162 | |
| 163 | #include "../ma_check_standalone.h" |
| 164 | |