| 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 (1024L*1024L*1024L + 1024L*1024L*512) |
| 32 | #define LOG_FLAGS 0 |
| 33 | |
| 34 | static const char *base_first_translog_file= "aria_log.00000001" ; |
| 35 | static const char *base_file1_name= "page_cache_test_file_1" ; |
| 36 | static char file1_name[FN_REFLEN], first_translog_file[FN_REFLEN]; |
| 37 | |
| 38 | static PAGECACHE_FILE file1; |
| 39 | |
| 40 | |
| 41 | int main(int argc __attribute__((unused)), char *argv[]) |
| 42 | { |
| 43 | uchar long_tr_id[6]; |
| 44 | PAGECACHE pagecache; |
| 45 | LSN lsn; |
| 46 | my_off_t file_size; |
| 47 | LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1]; |
| 48 | MY_INIT(argv[0]); |
| 49 | |
| 50 | plan(1); |
| 51 | |
| 52 | bzero(&pagecache, sizeof(pagecache)); |
| 53 | maria_data_root= create_tmpdir(argv[0]); |
| 54 | if (maria_log_remove(0)) |
| 55 | exit(1); |
| 56 | fn_format(first_translog_file, base_first_translog_file, maria_data_root, "" , MYF(0)); |
| 57 | |
| 58 | bzero(long_tr_id, 6); |
| 59 | #ifndef DBUG_OFF |
| 60 | #if defined(__WIN__) |
| 61 | default_dbug_option= "d:t:i:O,\\ma_test_loghandler_pagecache.trace" ; |
| 62 | #else |
| 63 | default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler_pagecache.trace" ; |
| 64 | #endif |
| 65 | if (argc > 1) |
| 66 | { |
| 67 | DBUG_SET(default_dbug_option); |
| 68 | DBUG_SET_INITIAL(default_dbug_option); |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | if (ma_control_file_open(TRUE, TRUE)) |
| 73 | { |
| 74 | fprintf(stderr, "Can't init control file (%d)\n" , errno); |
| 75 | exit(1); |
| 76 | } |
| 77 | if (init_pagecache(&pagecache, PCACHE_SIZE, 0, 0, |
| 78 | PCACHE_PAGE, 0, 0) == 0) |
| 79 | { |
| 80 | fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n" , errno); |
| 81 | exit(1); |
| 82 | } |
| 83 | if (translog_init_with_table(maria_data_root, LOG_FILE_SIZE, 50112, 0, &pagecache, |
| 84 | LOG_FLAGS, 0, &translog_example_table_init, |
| 85 | 0)) |
| 86 | { |
| 87 | fprintf(stderr, "Can't init loghandler (%d)\n" , errno); |
| 88 | exit(1); |
| 89 | } |
| 90 | /* Suppressing of automatic record writing */ |
| 91 | dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID; |
| 92 | |
| 93 | if ((file1.file= my_open(first_translog_file, O_RDONLY, MYF(MY_WME))) < 0) |
| 94 | { |
| 95 | fprintf(stderr, "There is no %s (%d)\n" , first_translog_file, errno); |
| 96 | exit(1); |
| 97 | } |
| 98 | file_size= my_seek(file1.file, 0, SEEK_END, MYF(MY_WME)); |
| 99 | if (file_size != TRANSLOG_PAGE_SIZE) |
| 100 | { |
| 101 | fprintf(stderr, |
| 102 | "incorrect initial size of %s: %ld instead of %ld\n" , |
| 103 | first_translog_file, (long)file_size, (long)TRANSLOG_PAGE_SIZE); |
| 104 | exit(1); |
| 105 | } |
| 106 | my_close(file1.file, MYF(MY_WME)); |
| 107 | int4store(long_tr_id, 0); |
| 108 | parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id; |
| 109 | parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6; |
| 110 | dummy_transaction_object.first_undo_lsn= TRANSACTION_LOGGED_LONG_ID; |
| 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 | |
| 122 | fn_format(file1_name, base_file1_name, maria_data_root, "" , MYF(0)); |
| 123 | if ((file1.file= my_open(file1_name, |
| 124 | O_CREAT | O_TRUNC | O_RDWR, MYF(0))) == -1) |
| 125 | { |
| 126 | fprintf(stderr, "Got error during file1 creation from open() (errno: %d)\n" , |
| 127 | errno); |
| 128 | exit(1); |
| 129 | } |
| 130 | pagecache_file_set_null_hooks(&file1); |
| 131 | file1.flush_log_callback= maria_flush_log_for_page; |
| 132 | |
| 133 | if (my_chmod(file1_name, 0777, MYF(MY_WME))) |
| 134 | exit(1); |
| 135 | |
| 136 | { |
| 137 | uchar page[PCACHE_PAGE]; |
| 138 | |
| 139 | bzero(page, PCACHE_PAGE); |
| 140 | lsn_store(page, lsn); |
| 141 | pagecache_write(&pagecache, &file1, 0, 3, page, |
| 142 | PAGECACHE_LSN_PAGE, |
| 143 | PAGECACHE_LOCK_LEFT_UNLOCKED, |
| 144 | PAGECACHE_PIN_LEFT_UNPINNED, |
| 145 | PAGECACHE_WRITE_DELAY, |
| 146 | 0, LSN_IMPOSSIBLE); |
| 147 | flush_pagecache_blocks(&pagecache, &file1, FLUSH_RELEASE); |
| 148 | } |
| 149 | my_close(file1.file, MYF(MY_WME)); |
| 150 | if ((file1.file= my_open(first_translog_file, O_RDONLY, MYF(MY_WME))) < 0) |
| 151 | { |
| 152 | fprintf(stderr, "can't open %s (%d)\n" , first_translog_file, errno); |
| 153 | exit(1); |
| 154 | } |
| 155 | file_size= my_seek(file1.file, 0, SEEK_END, MYF(MY_WME)); |
| 156 | if (file_size != TRANSLOG_PAGE_SIZE * 2) |
| 157 | { |
| 158 | fprintf(stderr, |
| 159 | "incorrect initial size of %s: %ld instead of %ld\n" , |
| 160 | first_translog_file, |
| 161 | (long)file_size, (long)(TRANSLOG_PAGE_SIZE * 2)); |
| 162 | ok(0, "log triggered" ); |
| 163 | exit(1); |
| 164 | } |
| 165 | my_close(file1.file, MYF(MY_WME)); |
| 166 | ok(1, "log triggered" ); |
| 167 | |
| 168 | translog_destroy(); |
| 169 | end_pagecache(&pagecache, 1); |
| 170 | ma_control_file_end(); |
| 171 | my_delete(file1_name, MYF(MY_WME)); |
| 172 | |
| 173 | if (maria_log_remove(maria_data_root)) |
| 174 | exit(1); |
| 175 | |
| 176 | my_uuid_end(); |
| 177 | my_free_open_file_info(); |
| 178 | my_end(0); |
| 179 | |
| 180 | exit(0); |
| 181 | } |
| 182 | |
| 183 | #include "../ma_check_standalone.h" |
| 184 | |