| 1 | /* Copyright (C) 2006,2007 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 | /* |
| 17 | WL#3071 Maria checkpoint |
| 18 | First version written by Guilhem Bichot on 2006-04-27. |
| 19 | Does not compile yet. |
| 20 | */ |
| 21 | |
| 22 | /* This is the interface of this module. */ |
| 23 | |
| 24 | typedef enum enum_ma_checkpoint_level { |
| 25 | CHECKPOINT_NONE= 0, |
| 26 | /* just write dirty_pages, transactions table and sync files */ |
| 27 | CHECKPOINT_INDIRECT, |
| 28 | /* also flush all dirty pages which were already dirty at prev checkpoint */ |
| 29 | CHECKPOINT_MEDIUM, |
| 30 | /* also flush all dirty pages */ |
| 31 | CHECKPOINT_FULL |
| 32 | } CHECKPOINT_LEVEL; |
| 33 | |
| 34 | C_MODE_START |
| 35 | int ma_checkpoint_init(ulong interval); |
| 36 | void ma_checkpoint_end(void); |
| 37 | int ma_checkpoint_execute(CHECKPOINT_LEVEL level, my_bool no_wait); |
| 38 | C_MODE_END |
| 39 | |
| 40 | /** |
| 41 | @brief reads some LSNs with special trickery |
| 42 | |
| 43 | If a 64-bit variable transitions between both halves being zero to both |
| 44 | halves being non-zero, and back, this function can be used to do a read of |
| 45 | it (without mutex, without atomic load) which always produces a correct |
| 46 | (though maybe slightly old) value (even on 32-bit CPUs). The value is at |
| 47 | least as new as the latest mutex unlock done by the calling thread. |
| 48 | The assumption is that the system sets both 4-byte halves either at the |
| 49 | same time, or one after the other (in any order), but NOT some bytes of the |
| 50 | first half then some bytes of the second half then the rest of bytes of the |
| 51 | first half. With this assumption, the function can detect when it is |
| 52 | seeing an inconsistent value. |
| 53 | |
| 54 | @param LSN pointer to the LSN variable to read |
| 55 | |
| 56 | @return LSN part (most significant byte always 0) |
| 57 | */ |
| 58 | #if ( SIZEOF_CHARP >= 8 ) |
| 59 | /* 64-bit CPU, 64-bit reads are atomic */ |
| 60 | #define lsn_read_non_atomic LSN_WITH_FLAGS_TO_LSN |
| 61 | #else |
| 62 | static inline LSN lsn_read_non_atomic_32(const volatile LSN *x) |
| 63 | { |
| 64 | /* |
| 65 | 32-bit CPU, 64-bit reads may give a mixed of old half and new half (old |
| 66 | low bits and new high bits, or the contrary). |
| 67 | */ |
| 68 | for (;;) /* loop until no atomicity problems */ |
| 69 | { |
| 70 | /* |
| 71 | Remove most significant byte in case this is a LSN_WITH_FLAGS object. |
| 72 | Those flags in TRN::first_undo_lsn break the condition on transitions so |
| 73 | they must be removed below. |
| 74 | */ |
| 75 | LSN y= LSN_WITH_FLAGS_TO_LSN(*x); |
| 76 | if (likely((y == LSN_IMPOSSIBLE) || LSN_VALID(y))) |
| 77 | return y; |
| 78 | } |
| 79 | } |
| 80 | #define lsn_read_non_atomic(x) lsn_read_non_atomic_32(&x) |
| 81 | #endif |
| 82 | |
| 83 | /** |
| 84 | prints a message from a task not connected to any user (checkpoint |
| 85 | and recovery for example). |
| 86 | |
| 87 | @param level 0 if error, ME_JUST_WARNING if warning, |
| 88 | ME_JUST_INFO if info |
| 89 | @param sentence text to write |
| 90 | */ |
| 91 | #define ma_message_no_user(level, sentence) \ |
| 92 | my_printf_error(HA_ERR_GENERIC, "Aria engine: %s", MYF(level), sentence) |
| 93 | |