| 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 (1024L*1024L*1024L + 1024L*1024L*512) |
| 33 | #define LOG_FLAGS 0 |
| 34 | |
| 35 | int main(int argc __attribute__((unused)), char *argv[]) |
| 36 | { |
| 37 | int rc= 1; |
| 38 | uchar long_tr_id[6]; |
| 39 | PAGECACHE pagecache; |
| 40 | LSN first_lsn; |
| 41 | TRANSLOG_HEADER_BUFFER rec; |
| 42 | LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; |
| 43 | translog_size_t len; |
| 44 | |
| 45 | MY_INIT(argv[0]); |
| 46 | |
| 47 | plan(1); |
| 48 | |
| 49 | bzero(&pagecache, sizeof(pagecache)); |
| 50 | maria_data_root= create_tmpdir(argv[0]); |
| 51 | if (maria_log_remove(0)) |
| 52 | exit(1); |
| 53 | |
| 54 | bzero(long_tr_id, 6); |
| 55 | #ifndef DBUG_OFF |
| 56 | #if defined(__WIN__) |
| 57 | default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace" ; |
| 58 | #else |
| 59 | default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace" ; |
| 60 | #endif |
| 61 | if (argc > 1) |
| 62 | { |
| 63 | DBUG_SET(default_dbug_option); |
| 64 | DBUG_SET_INITIAL(default_dbug_option); |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | if (ma_control_file_open(TRUE, TRUE)) |
| 69 | { |
| 70 | fprintf(stderr, "Can't init control file (%d)\n" , errno); |
| 71 | exit(1); |
| 72 | } |
| 73 | if (init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, |
| 74 | PCACHE_PAGE, 0, 0) == 0) |
| 75 | { |
| 76 | fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n" , errno); |
| 77 | exit(1); |
| 78 | } |
| 79 | if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, |
| 80 | LOG_FLAGS, 0, &translog_example_table_init, |
| 81 | 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 | int4store(long_tr_id, 0); |
| 90 | long_tr_id[5]= 0xff; |
| 91 | parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; |
| 92 | parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; |
| 93 | if (translog_write_record(&first_lsn, |
| 94 | LOGREC_FIXED_RECORD_0LSN_EXAMPLE, |
| 95 | &dummy_transaction_object, NULL, 6, |
| 96 | TRANSLOG_INTERNAL_PARTS + 1, |
| 97 | parts, NULL, NULL)) |
| 98 | { |
| 99 | fprintf(stderr, "Can't write record #%lu\n" , (ulong) 0); |
| 100 | translog_destroy(); |
| 101 | exit(1); |
| 102 | } |
| 103 | |
| 104 | len= translog_read_record_header(first_lsn, &rec); |
| 105 | if (len == 0) |
| 106 | { |
| 107 | fprintf(stderr, "translog_read_record_header failed (%d)\n" , errno); |
| 108 | goto err; |
| 109 | } |
| 110 | if (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE || rec.short_trid != 0 || |
| 111 | rec.record_length != 6 || uint4korr(rec.header) != 0 || |
| 112 | ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF || |
| 113 | first_lsn != rec.lsn) |
| 114 | { |
| 115 | fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE " |
| 116 | "data read(0)\n" |
| 117 | "type: %u (%d) strid: %u (%d) len: %u (%d) i: %u (%d), " |
| 118 | "4: %u (%d) 5: %u (%d) " |
| 119 | "lsn" LSN_FMT " (%d)\n" , |
| 120 | (uint) rec.type, (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE), |
| 121 | (uint) rec.short_trid, (rec.short_trid != 0), |
| 122 | (uint) rec.record_length, (rec.record_length != 6), |
| 123 | (uint) uint4korr(rec.header), (uint4korr(rec.header) != 0), |
| 124 | (uint) rec.header[4], (((uchar)rec.header[4]) != 0), |
| 125 | (uint) rec.header[5], (((uchar)rec.header[5]) != 0xFF), |
| 126 | LSN_IN_PARTS(rec.lsn), (first_lsn != rec.lsn)); |
| 127 | goto err; |
| 128 | } |
| 129 | |
| 130 | ok(1, "read OK" ); |
| 131 | rc= 0; |
| 132 | |
| 133 | err: |
| 134 | translog_destroy(); |
| 135 | end_pagecache(&pagecache, 1); |
| 136 | ma_control_file_end(); |
| 137 | if (maria_log_remove(maria_data_root)) |
| 138 | exit(1); |
| 139 | |
| 140 | my_uuid_end(); |
| 141 | my_free_open_file_info(); |
| 142 | my_end(0); |
| 143 | |
| 144 | exit(rc); |
| 145 | } |
| 146 | |
| 147 | #include "../ma_check_standalone.h" |
| 148 | |