1 | /* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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 | /* This file is included by all internal maria files */ |
17 | |
18 | #include <my_global.h> |
19 | #include "maria.h" /* Structs & some defines */ |
20 | #include "ma_pagecache.h" |
21 | #include <myisampack.h> /* packing of keys */ |
22 | #include <my_tree.h> |
23 | #include <my_bitmap.h> |
24 | #include <my_pthread.h> |
25 | #include <thr_lock.h> |
26 | #include <hash.h> |
27 | #include "ma_loghandler.h" |
28 | #include "ma_control_file.h" |
29 | #include "ma_state.h" |
30 | #include <waiting_threads.h> |
31 | #include <mysql/psi/mysql_file.h> |
32 | |
33 | /* For testing recovery */ |
34 | #ifdef TO_BE_REMOVED |
35 | #define IDENTICAL_PAGES_AFTER_RECOVERY 1 |
36 | #endif |
37 | /* Do extra sanity checking */ |
38 | #define SANITY_CHECKS 1 |
39 | #ifdef EXTRA_DEBUG |
40 | #define EXTRA_DEBUG_KEY_CHANGES |
41 | #define EXTRA_STORE_FULL_PAGE_IN_KEY_CHANGES |
42 | #endif |
43 | |
44 | #define MAX_NONMAPPED_INSERTS 1000 |
45 | #define MARIA_MAX_TREE_LEVELS 32 |
46 | #define MARIA_MAX_RECORD_ON_STACK 16384 |
47 | |
48 | /* maria_open() flag, specific for maria_pack */ |
49 | #define HA_OPEN_IGNORE_MOVED_STATE (1U << 30) |
50 | |
51 | extern PAGECACHE maria_pagecache_var, *maria_pagecache; |
52 | int maria_assign_to_pagecache(MARIA_HA *info, ulonglong key_map, |
53 | PAGECACHE *key_cache); |
54 | void maria_change_pagecache(PAGECACHE *old_key_cache, |
55 | PAGECACHE *new_key_cache); |
56 | |
57 | typedef struct st_maria_sort_info |
58 | { |
59 | /* sync things */ |
60 | mysql_mutex_t mutex; |
61 | mysql_cond_t cond; |
62 | MARIA_HA *info, *new_info; |
63 | HA_CHECK *param; |
64 | char *buff; |
65 | SORT_KEY_BLOCKS *key_block, *key_block_end; |
66 | SORT_FT_BUF *ft_buf; |
67 | my_off_t filelength, dupp, buff_length; |
68 | pgcache_page_no_t page; |
69 | ha_rows max_records; |
70 | uint current_key, total_keys; |
71 | volatile uint got_error; |
72 | uint threads_running; |
73 | myf myf_rw; |
74 | enum data_file_type new_data_file_type, org_data_file_type; |
75 | } MARIA_SORT_INFO; |
76 | |
77 | typedef struct st_maria_sort_param |
78 | { |
79 | pthread_t thr; |
80 | IO_CACHE read_cache, tempfile, tempfile_for_exceptions; |
81 | DYNAMIC_ARRAY buffpek; |
82 | MARIA_BIT_BUFF bit_buff; /* For parallel repair of packrec. */ |
83 | |
84 | MARIA_KEYDEF *keyinfo; |
85 | MARIA_SORT_INFO *sort_info; |
86 | HA_KEYSEG *seg; |
87 | uchar **sort_keys; |
88 | uchar *rec_buff; |
89 | void *wordlist, *wordptr; |
90 | MEM_ROOT wordroot; |
91 | uchar *record; |
92 | MY_TMPDIR *tmpdir; |
93 | |
94 | /* |
95 | The next two are used to collect statistics, see maria_update_key_parts for |
96 | description. |
97 | */ |
98 | ulonglong unique[HA_MAX_KEY_SEG+1]; |
99 | ulonglong notnull[HA_MAX_KEY_SEG+1]; |
100 | ulonglong sortbuff_size; |
101 | |
102 | MARIA_RECORD_POS pos,max_pos,filepos,start_recpos, current_filepos; |
103 | uint key, key_length,real_key_length; |
104 | uint maxbuffers, keys, find_length, sort_keys_length; |
105 | my_bool fix_datafile, master; |
106 | my_bool calc_checksum; /* calculate table checksum */ |
107 | size_t rec_buff_size; |
108 | |
109 | int (*key_cmp)(struct st_maria_sort_param *, const void *, const void *); |
110 | int (*key_read)(struct st_maria_sort_param *, uchar *); |
111 | int (*key_write)(struct st_maria_sort_param *, const uchar *); |
112 | void (*lock_in_memory)(HA_CHECK *); |
113 | int (*write_keys)(struct st_maria_sort_param *, uchar **, |
114 | ulonglong , struct st_buffpek *, IO_CACHE *); |
115 | my_off_t (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint); |
116 | int (*write_key)(struct st_maria_sort_param *, IO_CACHE *,uchar *, |
117 | uint, ulonglong); |
118 | } MARIA_SORT_PARAM; |
119 | |
120 | int maria_write_data_suffix(MARIA_SORT_INFO *sort_info, my_bool fix_datafile); |
121 | |
122 | struct st_transaction; |
123 | |
124 | /* undef map from my_nosys; We need test-if-disk full */ |
125 | #undef my_write |
126 | |
127 | #define CRC_SIZE 4 |
128 | |
129 | typedef struct st_maria_state_info |
130 | { |
131 | struct |
132 | { /* Fileheader (24 bytes) */ |
133 | uchar file_version[4]; |
134 | uchar options[2]; |
135 | uchar [2]; |
136 | uchar state_info_length[2]; |
137 | uchar base_info_length[2]; |
138 | uchar base_pos[2]; |
139 | uchar key_parts[2]; /* Key parts */ |
140 | uchar unique_key_parts[2]; /* Key parts + unique parts */ |
141 | uchar keys; /* number of keys in file */ |
142 | uchar uniques; /* number of UNIQUE definitions */ |
143 | uchar not_used; /* Language for indexes */ |
144 | uchar fulltext_keys; |
145 | uchar data_file_type; |
146 | /* Used by mariapack to store the original data_file_type */ |
147 | uchar org_data_file_type; |
148 | } ; |
149 | |
150 | MARIA_STATUS_INFO state; |
151 | /* maria_ha->state points here for crash-safe but not versioned tables */ |
152 | MARIA_STATUS_INFO common; |
153 | ha_rows split; /* number of split blocks */ |
154 | my_off_t dellink; /* Link to next removed block */ |
155 | pgcache_page_no_t first_bitmap_with_space; |
156 | ulonglong auto_increment; |
157 | TrID create_trid; /* Minum trid for file */ |
158 | TrID last_change_trn; /* selfdescriptive */ |
159 | ulong update_count; /* Updated for each write lock */ |
160 | ulong status; |
161 | double *rec_per_key_part; |
162 | ulong *nulls_per_key_part; |
163 | ha_checksum checksum; /* Table checksum */ |
164 | my_off_t *key_root; /* Start of key trees */ |
165 | my_off_t key_del; /* delete links for index pages */ |
166 | my_off_t records_at_analyze; /* Rows when calculating rec_per_key */ |
167 | |
168 | ulong sec_index_changed; /* Updated when new sec_index */ |
169 | ulong sec_index_used; /* which extra index are in use */ |
170 | ulonglong key_map; /* Which keys are in use */ |
171 | ulong version; /* timestamp of create */ |
172 | time_t create_time; /* Time when created database */ |
173 | time_t recover_time; /* Time for last recover */ |
174 | time_t check_time; /* Time for last check */ |
175 | uint sortkey; /* sorted by this key (not used) */ |
176 | uint open_count; |
177 | uint changed; /* Changed since maria_chk */ |
178 | /** |
179 | Birthday of the table: no record in the log before this LSN should ever |
180 | be applied to the table. Updated when created, renamed, explicitly |
181 | repaired (REPAIR|OPTIMIZE TABLE, ALTER TABLE ENABLE KEYS, maria_chk). |
182 | */ |
183 | LSN create_rename_lsn; |
184 | /** @brief Log horizon when state was last updated on disk */ |
185 | TRANSLOG_ADDRESS is_of_horizon; |
186 | /** |
187 | REDO phase should ignore any record before this LSN. UNDO phase |
188 | shouldn't, this is the difference with create_rename_lsn. |
189 | skip_redo_lsn >= create_rename_lsn. |
190 | The distinction is for these cases: |
191 | - after a repair at end of bulk insert (enabling indices), REDO phase |
192 | should skip the table but UNDO phase should not, so only skip_redo_lsn is |
193 | increased, not create_rename_lsn |
194 | - if one table is corrupted and so recovery fails, user may repair the |
195 | table with maria_chk and let recovery restart: that recovery should then |
196 | skip the repaired table even in the UNDO phase, so create_rename_lsn is |
197 | increased. |
198 | */ |
199 | LSN skip_redo_lsn; |
200 | /* LSN when we wrote file id to the log */ |
201 | LSN logrec_file_id; |
202 | |
203 | uint8 dupp_key; /* Lastly processed index with */ |
204 | /* violated uniqueness constraint */ |
205 | |
206 | /* the following isn't saved on disk */ |
207 | uint state_diff_length; /* Should be 0 */ |
208 | uint state_length; /* Length of state header in file */ |
209 | ulong *key_info; |
210 | } MARIA_STATE_INFO; |
211 | |
212 | |
213 | /* Number of bytes written be _ma_state_info_write_sub() */ |
214 | #define MARIA_STATE_INFO_SIZE \ |
215 | (24 + 2 + LSN_STORE_SIZE*3 + 4 + 11*8 + 4*4 + 8 + 3*4 + 5*8) |
216 | #define MARIA_FILE_OPEN_COUNT_OFFSET 0 |
217 | #define MARIA_FILE_CHANGED_OFFSET 2 |
218 | #define MARIA_FILE_CREATE_RENAME_LSN_OFFSET 4 |
219 | #define MARIA_FILE_CREATE_TRID_OFFSET (4 + LSN_STORE_SIZE*3 + 11*8) |
220 | |
221 | #define MARIA_STATE_KEY_SIZE (8 + 4) |
222 | #define MARIA_STATE_KEYBLOCK_SIZE 8 |
223 | #define MARIA_STATE_KEYSEG_SIZE 12 |
224 | #define (MARIA_MAX_KEY*MARIA_STATE_KEY_SIZE + MARIA_MAX_KEY*HA_MAX_KEY_SEG*MARIA_STATE_KEYSEG_SIZE) |
225 | #define MARIA_KEYDEF_SIZE (2+ 5*2) |
226 | #define MARIA_UNIQUEDEF_SIZE (2+1+1) |
227 | #define HA_KEYSEG_SIZE (6+ 2*2 + 4*2) |
228 | #define MARIA_MAX_KEY_BUFF (HA_MAX_KEY_BUFF + MARIA_MAX_PACK_TRANSID_SIZE) |
229 | #define MARIA_COLUMNDEF_SIZE (2*7+1+1+4) |
230 | #define MARIA_BASE_INFO_SIZE (MY_UUID_SIZE + 5*8 + 6*4 + 11*2 + 6 + 5*2 + 1 + 16) |
231 | #define MARIA_INDEX_BLOCK_MARGIN 16 /* Safety margin for .MYI tables */ |
232 | #define MARIA_MAX_POINTER_LENGTH 7 /* Node pointer */ |
233 | /* Internal management bytes needed to store 2 transid/key on an index page */ |
234 | #define MARIA_MAX_PACK_TRANSID_SIZE (TRANSID_SIZE+1) |
235 | #define MARIA_TRANSID_PACK_OFFSET (256- TRANSID_SIZE - 1) |
236 | #define MARIA_MIN_TRANSID_PACK_OFFSET (MARIA_TRANSID_PACK_OFFSET-TRANSID_SIZE) |
237 | #define MARIA_INDEX_OVERHEAD_SIZE (MARIA_MAX_PACK_TRANSID_SIZE * 2 + \ |
238 | MARIA_MAX_POINTER_LENGTH) |
239 | #define MARIA_DELETE_KEY_NR 255 /* keynr for deleted blocks */ |
240 | |
241 | /* extra options */ |
242 | #define (1 << 0) |
243 | #define (1 << 1) |
244 | |
245 | /* |
246 | Basic information of the Maria table. This is stored on disk |
247 | and not changed (unless we do DLL changes). |
248 | */ |
249 | |
250 | typedef struct st_ma_base_info |
251 | { |
252 | my_off_t keystart; /* Start of keys */ |
253 | my_off_t max_data_file_length; |
254 | my_off_t max_key_file_length; |
255 | my_off_t margin_key_file_length; |
256 | ha_rows records, reloc; /* Create information */ |
257 | ulong mean_row_length; /* Create information */ |
258 | ulong reclength; /* length of unpacked record */ |
259 | ulong pack_reclength; /* Length of full packed rec */ |
260 | ulong min_pack_length; |
261 | ulong max_pack_length; /* Max possibly length of packed rec */ |
262 | ulong min_block_length; |
263 | uint fields; /* fields in table */ |
264 | uint fixed_not_null_fields; |
265 | uint fixed_not_null_fields_length; |
266 | uint max_field_lengths; |
267 | uint pack_fields; /* packed fields in table */ |
268 | uint varlength_fields; /* char/varchar/blobs */ |
269 | /* Number of bytes in the index used to refer to a row (2-8) */ |
270 | uint rec_reflength; |
271 | /* Number of bytes in the index used to refer to another index page (2-8) */ |
272 | uint key_reflength; /* = 2-8 */ |
273 | uint keys; /* same as in state.header */ |
274 | uint auto_key; /* Which key-1 is a auto key */ |
275 | uint blobs; /* Number of blobs */ |
276 | /* Length of packed bits (when table was created first time) */ |
277 | uint pack_bytes; |
278 | /* Length of null bits (when table was created first time) */ |
279 | uint original_null_bytes; |
280 | uint null_bytes; /* Null bytes in record */ |
281 | uint field_offsets; /* Number of field offsets */ |
282 | uint max_key_block_length; /* Max block length */ |
283 | uint max_key_length; /* Max key length */ |
284 | /* Extra allocation when using dynamic record format */ |
285 | uint ; |
286 | uint ; |
287 | uint is_nulls_extended; /* 1 if new null bytes */ |
288 | uint default_row_flag; /* 0 or ROW_FLAG_NULLS_EXTENDED */ |
289 | uint block_size; |
290 | /* Size of initial record buffer */ |
291 | uint default_rec_buff_size; |
292 | /* Extra number of bytes the row format require in the record buffer */ |
293 | uint ; |
294 | /* Tuning flags that can be ignored by older Maria versions */ |
295 | uint ; |
296 | /* default language, not really used but displayed by maria_chk */ |
297 | uint language; |
298 | |
299 | /* The following are from the header */ |
300 | uint key_parts, all_key_parts; |
301 | uchar uuid[MY_UUID_SIZE]; |
302 | /** |
303 | @brief If false, we disable logging, versioning, transaction etc. Observe |
304 | difference with MARIA_SHARE::now_transactional |
305 | */ |
306 | my_bool born_transactional; |
307 | } MARIA_BASE_INFO; |
308 | |
309 | |
310 | /* Structs used intern in database */ |
311 | |
312 | typedef struct st_maria_blob /* Info of record */ |
313 | { |
314 | ulong offset; /* Offset to blob in record */ |
315 | uint pack_length; /* Type of packed length */ |
316 | ulong length; /* Calc:ed for each record */ |
317 | } MARIA_BLOB; |
318 | |
319 | |
320 | typedef struct st_maria_pack |
321 | { |
322 | ulong ; |
323 | uint ref_length; |
324 | uchar version; |
325 | } MARIA_PACK; |
326 | |
327 | typedef struct st_maria_file_bitmap |
328 | { |
329 | struct st_maria_share *share; |
330 | uchar *map; |
331 | pgcache_page_no_t page; /* Page number for current bitmap */ |
332 | pgcache_page_no_t last_bitmap_page; /* Last possible bitmap page */ |
333 | my_bool changed; /* 1 if page needs to be written */ |
334 | my_bool changed_not_flushed; /* 1 if some bitmap is not flushed */ |
335 | my_bool return_first_match; /* Shortcut find_head() */ |
336 | uint used_size; /* Size of bitmap head that is not 0 */ |
337 | uint full_head_size; /* Where to start search for head */ |
338 | uint full_tail_size; /* Where to start search for tail */ |
339 | uint flush_all_requested; /**< If _ma_bitmap_flush_all waiting */ |
340 | uint waiting_for_flush_all_requested; /* If someone is waiting for above */ |
341 | uint non_flushable; /**< 0 if bitmap and log are in sync */ |
342 | uint waiting_for_non_flushable; /* If someone is waiting for above */ |
343 | PAGECACHE_FILE file; /* datafile where bitmap is stored */ |
344 | |
345 | mysql_mutex_t bitmap_lock; |
346 | mysql_cond_t bitmap_cond; /**< When bitmap becomes flushable */ |
347 | /* Constants, allocated when initiating bitmaps */ |
348 | uint sizes[8]; /* Size per bit combination */ |
349 | uint total_size; /* Total usable size of bitmap page */ |
350 | uint max_total_size; /* Max value for total_size */ |
351 | uint last_total_size; /* Size of bitmap on last_bitmap_page */ |
352 | uint block_size; /* Block size of file */ |
353 | ulong pages_covered; /* Pages covered by bitmap + 1 */ |
354 | DYNAMIC_ARRAY pinned_pages; /**< not-yet-flushable bitmap pages */ |
355 | } MARIA_FILE_BITMAP; |
356 | |
357 | #define MARIA_CHECKPOINT_LOOKS_AT_ME 1 |
358 | #define MARIA_CHECKPOINT_SHOULD_FREE_ME 2 |
359 | #define MARIA_CHECKPOINT_SEEN_IN_LOOP 4 |
360 | |
361 | typedef struct st_maria_crypt_data MARIA_CRYPT_DATA; |
362 | |
363 | typedef struct st_maria_share |
364 | { /* Shared between opens */ |
365 | MARIA_STATE_INFO state; |
366 | MARIA_STATE_INFO checkpoint_state; /* Copy of saved state by checkpoint */ |
367 | MARIA_BASE_INFO base; |
368 | MARIA_STATE_HISTORY *state_history; |
369 | MARIA_KEYDEF ft2_keyinfo; /* Second-level ft-key definition */ |
370 | MARIA_KEYDEF *keyinfo; /* Key definitions */ |
371 | MARIA_UNIQUEDEF *uniqueinfo; /* unique definitions */ |
372 | HA_KEYSEG *keyparts; /* key part info */ |
373 | MARIA_COLUMNDEF *columndef; /* Pointer to column information */ |
374 | MARIA_PACK pack; /* Data about packed records */ |
375 | MARIA_BLOB *blobs; /* Pointer to blobs */ |
376 | uint16 *column_nr; /* Original column order */ |
377 | LEX_STRING unique_file_name; /* realpath() of index file */ |
378 | LEX_STRING data_file_name; /* Resolved path names from symlinks */ |
379 | LEX_STRING index_file_name; |
380 | LEX_STRING open_file_name; /* parameter to open filename */ |
381 | uchar *file_map; /* mem-map of file if possible */ |
382 | LIST *open_list; /* Tables open with this share */ |
383 | PAGECACHE *pagecache; /* ref to the current key cache */ |
384 | MARIA_DECODE_TREE *decode_trees; |
385 | /* |
386 | Previous auto-increment value. Used to verify if we can restore the |
387 | auto-increment counter if we have to abort an insert (duplicate key). |
388 | */ |
389 | ulonglong last_auto_increment; |
390 | uint16 *decode_tables; |
391 | uint16 id; /**< 2-byte id by which log records refer to the table */ |
392 | /* Called the first time the table instance is opened */ |
393 | my_bool (*once_init)(struct st_maria_share *, File); |
394 | /* Called when the last instance of the table is closed */ |
395 | my_bool (*once_end)(struct st_maria_share *); |
396 | /* Is called for every open of the table */ |
397 | my_bool (*init)(MARIA_HA *); |
398 | /* Is called for every close of the table */ |
399 | void (*end)(MARIA_HA *); |
400 | /* Called when we want to read a record from a specific position */ |
401 | int (*read_record)(MARIA_HA *, uchar *, MARIA_RECORD_POS); |
402 | /* Initialize a scan */ |
403 | my_bool (*scan_init)(MARIA_HA *); |
404 | /* Read next record while scanning */ |
405 | int (*scan)(MARIA_HA *, uchar *, MARIA_RECORD_POS, my_bool); |
406 | /* End scan */ |
407 | void (*scan_end)(MARIA_HA *); |
408 | int (*scan_remember_pos)(MARIA_HA *, MARIA_RECORD_POS*); |
409 | int (*scan_restore_pos)(MARIA_HA *, MARIA_RECORD_POS); |
410 | /* Pre-write of row (some handlers may do the actual write here) */ |
411 | MARIA_RECORD_POS (*write_record_init)(MARIA_HA *, const uchar *); |
412 | /* Write record (or accept write_record_init) */ |
413 | my_bool (*write_record)(MARIA_HA *, const uchar *); |
414 | /* Called when write failed */ |
415 | my_bool (*write_record_abort)(MARIA_HA *); |
416 | my_bool (*update_record)(MARIA_HA *, MARIA_RECORD_POS, |
417 | const uchar *, const uchar *); |
418 | my_bool (*delete_record)(MARIA_HA *, const uchar *record); |
419 | my_bool (*compare_record)(MARIA_HA *, const uchar *); |
420 | /* calculate checksum for a row */ |
421 | ha_checksum(*calc_checksum)(MARIA_HA *, const uchar *); |
422 | /* |
423 | Calculate checksum for a row during write. May be 0 if we calculate |
424 | the checksum in write_record_init() |
425 | */ |
426 | ha_checksum(*calc_write_checksum)(MARIA_HA *, const uchar *); |
427 | /* calculate checksum for a row during check table */ |
428 | ha_checksum(*calc_check_checksum)(MARIA_HA *, const uchar *); |
429 | /* Compare a row in memory with a row on disk */ |
430 | my_bool (*compare_unique)(MARIA_HA *, MARIA_UNIQUEDEF *, |
431 | const uchar *record, MARIA_RECORD_POS pos); |
432 | my_off_t (*keypos_to_recpos)(struct st_maria_share *share, my_off_t pos); |
433 | my_off_t (*recpos_to_keypos)(struct st_maria_share *share, my_off_t pos); |
434 | my_bool (*row_is_visible)(MARIA_HA *); |
435 | |
436 | /* Mapings to read/write the data file */ |
437 | size_t (*file_read)(MARIA_HA *, uchar *, size_t, my_off_t, myf); |
438 | size_t (*file_write)(MARIA_HA *, const uchar *, size_t, my_off_t, myf); |
439 | /* query cache invalidator for merged tables */ |
440 | invalidator_by_filename invalidator; |
441 | /* query cache invalidator for changing state */ |
442 | invalidator_by_filename chst_invalidator; |
443 | my_off_t key_del_current; /* delete links for index pages */ |
444 | ulong this_process; /* processid */ |
445 | ulong last_process; /* For table-change-check */ |
446 | ulong last_version; /* Version on start */ |
447 | ulong options; /* Options used */ |
448 | ulong min_pack_length; /* These are used by packed data */ |
449 | ulong max_pack_length; |
450 | ulong state_diff_length; |
451 | uint rec_reflength; /* rec_reflength in use now */ |
452 | uint ; |
453 | uint32 ftkeys; /* Number of distinct full-text keys |
454 | + 1 */ |
455 | PAGECACHE_FILE kfile; /* Shared keyfile */ |
456 | File data_file; /* Shared data file */ |
457 | int mode; /* mode of file on open */ |
458 | uint reopen; /* How many times opened */ |
459 | uint in_trans; /* Number of references by trn */ |
460 | uint w_locks, r_locks, tot_locks; /* Number of read/write locks */ |
461 | uint block_size; /* block_size of keyfile & data file*/ |
462 | uint max_index_block_size; /* block_size - end_of_page_info */ |
463 | /* Fixed length part of a packed row in BLOCK_RECORD format */ |
464 | uint base_length; |
465 | myf write_flag; |
466 | enum data_file_type data_file_type; |
467 | enum pagecache_page_type page_type; /* value depending transactional */ |
468 | /** |
469 | if Checkpoint looking at table; protected by close_lock or THR_LOCK_maria |
470 | */ |
471 | uint8 in_checkpoint; |
472 | my_bool temporary; |
473 | /* Below flag is needed to make log tables work with concurrent insert */ |
474 | my_bool is_log_table; |
475 | my_bool has_null_fields; |
476 | my_bool has_varchar_fields; /* If table has varchar fields */ |
477 | /* |
478 | Set to 1 if open_count was wrong at open. Set to avoid asserts for |
479 | wrong open count on close. |
480 | */ |
481 | my_bool open_count_not_zero_on_open; |
482 | |
483 | my_bool changed, /* If changed since lock */ |
484 | global_changed, /* If changed since open */ |
485 | not_flushed; |
486 | my_bool internal_table; /* Internal tmp table */ |
487 | my_bool lock_key_trees; /* If we have to lock trees on read */ |
488 | my_bool non_transactional_concurrent_insert; |
489 | my_bool delay_key_write; |
490 | my_bool have_rtree; |
491 | /** |
492 | @brief if the table is transactional right now. It may have been created |
493 | transactional (base.born_transactional==TRUE) but with transactionality |
494 | (logging) temporarily disabled (now_transactional==FALSE). The opposite |
495 | (FALSE, TRUE) is impossible. |
496 | */ |
497 | my_bool now_transactional; |
498 | my_bool have_versioning; |
499 | my_bool key_del_used; /* != 0 if key_del is locked */ |
500 | my_bool deleting; /* we are going to delete this table */ |
501 | THR_LOCK lock; |
502 | void (*lock_restore_status)(void *); |
503 | /** |
504 | Protects kfile, dfile, most members of the state, state disk writes, |
505 | versioning information (like in_trans, state_history). |
506 | @todo find the exhaustive list. |
507 | */ |
508 | mysql_mutex_t intern_lock; |
509 | mysql_mutex_t key_del_lock; |
510 | mysql_cond_t key_del_cond; |
511 | /** |
512 | _Always_ held while closing table; prevents checkpoint from looking at |
513 | structures freed during closure (like bitmap). If you need close_lock and |
514 | intern_lock, lock them in this order. |
515 | */ |
516 | mysql_mutex_t close_lock; |
517 | my_off_t mmaped_length; |
518 | uint nonmmaped_inserts; /* counter of writing in |
519 | non-mmaped area */ |
520 | MARIA_FILE_BITMAP bitmap; |
521 | mysql_rwlock_t mmap_lock; |
522 | LSN lsn_of_file_id; /**< LSN of its last LOGREC_FILE_ID */ |
523 | |
524 | /** |
525 | Crypt data |
526 | */ |
527 | uint ; |
528 | MARIA_CRYPT_DATA *crypt_data; |
529 | |
530 | /** |
531 | Keep of track of last insert page, used to implement insert order |
532 | */ |
533 | uint last_insert_page; |
534 | pgcache_page_no_t last_insert_bitmap; |
535 | } MARIA_SHARE; |
536 | |
537 | |
538 | typedef uchar MARIA_BITMAP_BUFFER; |
539 | |
540 | typedef struct st_maria_bitmap_block |
541 | { |
542 | pgcache_page_no_t page; /* Page number */ |
543 | /* Number of continuous pages. TAIL_BIT is set if this is a tail page */ |
544 | uint page_count; |
545 | uint empty_space; /* Set for head and tail pages */ |
546 | /* |
547 | Number of BLOCKS for block-region (holds all non-blob-fields or one blob) |
548 | */ |
549 | uint sub_blocks; |
550 | /* set to <> 0 in write_record() if this block was actually used */ |
551 | uint8 used; |
552 | uint8 org_bitmap_value; |
553 | } MARIA_BITMAP_BLOCK; |
554 | |
555 | |
556 | typedef struct st_maria_bitmap_blocks |
557 | { |
558 | MARIA_BITMAP_BLOCK *block; |
559 | uint count; |
560 | my_bool tail_page_skipped; /* If some tail pages was not used */ |
561 | my_bool page_skipped; /* If some full pages was not used */ |
562 | } MARIA_BITMAP_BLOCKS; |
563 | |
564 | |
565 | /* Data about the currently read row */ |
566 | typedef struct st_maria_row |
567 | { |
568 | MARIA_BITMAP_BLOCKS insert_blocks; |
569 | MARIA_BITMAP_BUFFER *extents; |
570 | MARIA_RECORD_POS lastpos, nextpos; |
571 | MARIA_RECORD_POS *tail_positions; |
572 | ha_checksum checksum; |
573 | LSN orig_undo_lsn; /* Lsn at start of row insert */ |
574 | TrID trid; /* Transaction id for current row */ |
575 | uchar *empty_bits, *field_lengths; |
576 | uint *null_field_lengths; /* All null field lengths */ |
577 | ulong *blob_lengths; /* Length for each blob */ |
578 | ulong min_length, normal_length, char_length, varchar_length; |
579 | ulong blob_length, total_length; |
580 | size_t extents_buffer_length; /* Size of 'extents' buffer */ |
581 | uint head_length, ; |
582 | uint field_lengths_length; /* Length of data in field_lengths */ |
583 | uint extents_count; /* number of extents in 'extents' */ |
584 | uint full_page_count, tail_count; /* For maria_chk */ |
585 | uint space_on_head_page; |
586 | } MARIA_ROW; |
587 | |
588 | /* Data to scan row in blocked format */ |
589 | typedef struct st_maria_block_scan |
590 | { |
591 | uchar *bitmap_buff, *bitmap_pos, *bitmap_end, *page_buff; |
592 | uchar *dir, *dir_end; |
593 | pgcache_page_no_t bitmap_page, max_page; |
594 | ulonglong bits; |
595 | uint number_of_rows, bit_pos; |
596 | MARIA_RECORD_POS row_base_page; |
597 | ulonglong row_changes; |
598 | } MARIA_BLOCK_SCAN; |
599 | |
600 | |
601 | struct st_maria_handler |
602 | { |
603 | MARIA_SHARE *s; /* Shared between open:s */ |
604 | struct st_ma_transaction *trn; /* Pointer to active transaction */ |
605 | MARIA_STATUS_INFO *state, state_save; |
606 | MARIA_STATUS_INFO *state_start; /* State at start of transaction */ |
607 | MARIA_USED_TABLES *used_tables; |
608 | MARIA_ROW cur_row; /* The active row that we just read */ |
609 | MARIA_ROW new_row; /* Storage for a row during update */ |
610 | MARIA_KEY last_key; /* Last found key */ |
611 | MARIA_BLOCK_SCAN scan, *scan_save; |
612 | MARIA_BLOB *blobs; /* Pointer to blobs */ |
613 | MARIA_BIT_BUFF bit_buff; |
614 | DYNAMIC_ARRAY bitmap_blocks; |
615 | DYNAMIC_ARRAY pinned_pages; |
616 | /* accumulate indexfile changes between write's */ |
617 | TREE *bulk_insert; |
618 | LEX_CUSTRING *log_row_parts; /* For logging */ |
619 | DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */ |
620 | MEM_ROOT ft_memroot; /* used by the parser */ |
621 | MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */ |
622 | void *external_ref; /* For MariaDB TABLE */ |
623 | uchar *buff; /* page buffer */ |
624 | uchar *keyread_buff; /* Buffer for last key read */ |
625 | uchar *lastkey_buff; /* Last used search key */ |
626 | uchar *lastkey_buff2; |
627 | uchar *first_mbr_key; /* Searhed spatial key */ |
628 | uchar *rec_buff; /* Temp buffer for recordpack */ |
629 | uchar *blob_buff; /* Temp buffer for blobs */ |
630 | uchar *int_keypos; /* Save position for next/previous */ |
631 | uchar *int_maxpos; /* -""- */ |
632 | uint keypos_offset; /* Tmp storage for offset int_keypos */ |
633 | uint maxpos_offset; /* Tmp storage for offset int_maxpos */ |
634 | uchar *update_field_data; /* Used by update in rows-in-block */ |
635 | uint int_nod_flag; /* -""- */ |
636 | uint32 int_keytree_version; /* -""- */ |
637 | int (*read_record)(MARIA_HA *, uchar*, MARIA_RECORD_POS); |
638 | invalidator_by_filename invalidator; /* query cache invalidator */ |
639 | ulonglong last_auto_increment; /* auto value at start of statement */ |
640 | ulonglong row_changes; /* Incremented for each change */ |
641 | ulong this_unique; /* uniq filenumber or thread */ |
642 | ulong last_unique; /* last unique number */ |
643 | ulong this_loop; /* counter for this open */ |
644 | ulong last_loop; /* last used counter */ |
645 | MARIA_RECORD_POS save_lastpos; |
646 | MARIA_RECORD_POS dup_key_pos; |
647 | TrID dup_key_trid; |
648 | my_off_t pos; /* Intern variable */ |
649 | my_off_t last_keypage; /* Last key page read */ |
650 | my_off_t last_search_keypage; /* Last keypage when searching */ |
651 | |
652 | /* |
653 | QQ: the folloing two xxx_length fields should be removed, |
654 | as they are not compatible with parallel repair |
655 | */ |
656 | ulong packed_length, blob_length; /* Length of found, packed record */ |
657 | size_t rec_buff_size, blob_buff_size; |
658 | PAGECACHE_FILE dfile; /* The datafile */ |
659 | IO_CACHE rec_cache; /* When cacheing records */ |
660 | LIST open_list; |
661 | LIST share_list; |
662 | MY_BITMAP changed_fields; |
663 | ulong row_base_length; /* Length of row header */ |
664 | uint row_flag; /* Flag to store in row header */ |
665 | uint opt_flag; /* Optim. for space/speed */ |
666 | uint open_flags; /* Flags used in open() */ |
667 | uint update; /* If file changed since open */ |
668 | int lastinx; /* Last used index */ |
669 | uint last_rkey_length; /* Last length in maria_rkey() */ |
670 | uint *last_rtree_keypos; /* Last key positions for rtrees */ |
671 | uint bulk_insert_ref_length; /* Lenght of row ref during bi */ |
672 | uint non_flushable_state; |
673 | enum ha_rkey_function last_key_func; /* CONTAIN, OVERLAP, etc */ |
674 | uint save_lastkey_data_length; |
675 | uint save_lastkey_ref_length; |
676 | uint pack_key_length; /* For MARIA_MRG */ |
677 | myf lock_wait; /* is 0 or MY_SHORT_WAIT */ |
678 | int errkey; /* Got last error on this key */ |
679 | int lock_type; /* How database was locked */ |
680 | int tmp_lock_type; /* When locked by readinfo */ |
681 | uint data_changed; /* Somebody has changed data */ |
682 | uint save_update; /* When using KEY_READ */ |
683 | int save_lastinx; |
684 | uint preload_buff_size; /* When preloading indexes */ |
685 | uint16 last_used_keyseg; /* For MARIAMRG */ |
686 | uint8 key_del_used; /* != 0 if key_del is used */ |
687 | my_bool was_locked; /* Was locked in panic */ |
688 | my_bool append_insert_at_end; /* Set if concurrent insert */ |
689 | my_bool quick_mode; |
690 | my_bool in_check_table; /* We are running check tables */ |
691 | /* Marker if key_del_changed */ |
692 | /* If info->keyread_buff can't be used for rnext */ |
693 | my_bool page_changed; |
694 | /* If info->keyread_buff has to be re-read for rnext */ |
695 | my_bool keyread_buff_used; |
696 | my_bool once_flags; /* For MARIA_MRG */ |
697 | /* For bulk insert enable/disable transactions control */ |
698 | my_bool switched_transactional; |
699 | #ifdef _WIN32 |
700 | my_bool owned_by_merge; /* This Maria table is part of a merge union */ |
701 | #endif |
702 | THR_LOCK_DATA lock; |
703 | uchar *maria_rtree_recursion_state; /* For RTREE */ |
704 | uchar length_buff[5]; /* temp buff to store blob lengths */ |
705 | int maria_rtree_recursion_depth; |
706 | |
707 | my_bool create_unique_index_by_sort; |
708 | index_cond_func_t index_cond_func; /* Index condition function */ |
709 | void *index_cond_func_arg; /* parameter for the func */ |
710 | }; |
711 | |
712 | /* Some defines used by maria-functions */ |
713 | |
714 | #define USE_WHOLE_KEY 65535 /* Use whole key in _search() */ |
715 | #define -1 |
716 | |
717 | /* bits in opt_flag */ |
718 | #define MEMMAP_USED 32U |
719 | #define REMEMBER_OLD_POS 64U |
720 | |
721 | #define WRITEINFO_UPDATE_KEYFILE 1U |
722 | #define WRITEINFO_NO_UNLOCK 2U |
723 | |
724 | /* once_flags */ |
725 | #define USE_PACKED_KEYS 1U |
726 | #define RRND_PRESERVE_LASTINX 2U |
727 | |
728 | /* bits in state.changed */ |
729 | |
730 | #define STATE_CHANGED 1U |
731 | #define STATE_CRASHED 2U |
732 | #define STATE_CRASHED_ON_REPAIR 4U |
733 | #define STATE_NOT_ANALYZED 8U |
734 | #define STATE_NOT_OPTIMIZED_KEYS 16U |
735 | #define STATE_NOT_SORTED_PAGES 32U |
736 | #define STATE_NOT_OPTIMIZED_ROWS 64U |
737 | #define STATE_NOT_ZEROFILLED 128U |
738 | #define STATE_NOT_MOVABLE 256U |
739 | #define STATE_MOVED 512U /* set if base->uuid != maria_uuid */ |
740 | #define STATE_IN_REPAIR 1024U /* We are running repair on table */ |
741 | #define STATE_CRASHED_PRINTED 2048U |
742 | #define STATE_DATA_FILE_FULL 4096U |
743 | |
744 | #define STATE_CRASHED_FLAGS (STATE_CRASHED | STATE_CRASHED_ON_REPAIR | STATE_CRASHED_PRINTED) |
745 | |
746 | /* options to maria_read_cache */ |
747 | |
748 | #define READING_NEXT 1U |
749 | #define 2U |
750 | |
751 | /* Number of bytes on key pages to indicate used size */ |
752 | #define KEYPAGE_USED_SIZE 2U |
753 | #define KEYPAGE_KEYID_SIZE 1U |
754 | #define KEYPAGE_FLAG_SIZE 1U |
755 | #define KEYPAGE_KEY_VERSION_SIZE 4U /* encryption */ |
756 | #define KEYPAGE_CHECKSUM_SIZE 4U |
757 | #define (LSN_STORE_SIZE + KEYPAGE_USED_SIZE + \ |
758 | KEYPAGE_KEYID_SIZE + KEYPAGE_FLAG_SIZE + \ |
759 | TRANSID_SIZE + KEYPAGE_KEY_VERSION_SIZE) |
760 | #define KEYPAGE_FLAG_ISNOD 1U |
761 | #define KEYPAGE_FLAG_HAS_TRANSID 2U |
762 | |
763 | #define _ma_get_page_used(share,x) \ |
764 | ((uint) mi_uint2korr((x) + (share)->keypage_header - KEYPAGE_USED_SIZE)) |
765 | #define _ma_store_page_used(share,x,y) \ |
766 | mi_int2store((x) + (share)->keypage_header - KEYPAGE_USED_SIZE, (y)) |
767 | #define _ma_get_keypage_flag(share,x) x[(share)->keypage_header - KEYPAGE_USED_SIZE - KEYPAGE_FLAG_SIZE] |
768 | #define _ma_test_if_nod(share,x) \ |
769 | ((_ma_get_keypage_flag(share,x) & KEYPAGE_FLAG_ISNOD) ? (share)->base.key_reflength : 0) |
770 | |
771 | #define _ma_store_keynr(share, x, nr) x[(share)->keypage_header - KEYPAGE_KEYID_SIZE - KEYPAGE_FLAG_SIZE - KEYPAGE_USED_SIZE]= (nr) |
772 | #define _ma_get_keynr(share, x) ((uchar) x[(share)->keypage_header - KEYPAGE_KEYID_SIZE - KEYPAGE_FLAG_SIZE - KEYPAGE_USED_SIZE]) |
773 | #define _ma_store_transid(buff, transid) \ |
774 | transid_store((buff) + LSN_STORE_SIZE, (transid)) |
775 | #define _ma_korr_transid(buff) \ |
776 | transid_korr((buff) + LSN_STORE_SIZE) |
777 | #define _ma_store_keypage_flag(share,x,flag) x[(share)->keypage_header - KEYPAGE_USED_SIZE - KEYPAGE_FLAG_SIZE]= (flag) |
778 | #define _ma_mark_page_with_transid(share, page) \ |
779 | (page)->flag|= KEYPAGE_FLAG_HAS_TRANSID; \ |
780 | (page)->buff[(share)->keypage_header - KEYPAGE_USED_SIZE - KEYPAGE_FLAG_SIZE]= (page)->flag; |
781 | |
782 | #define KEYPAGE_KEY_VERSION(share, x) ((x) + \ |
783 | (share)->keypage_header - \ |
784 | (KEYPAGE_USED_SIZE + \ |
785 | KEYPAGE_FLAG_SIZE + \ |
786 | KEYPAGE_KEYID_SIZE + \ |
787 | KEYPAGE_KEY_VERSION_SIZE)) |
788 | |
789 | #define _ma_get_key_version(share,x) \ |
790 | ((uint) uint4korr(KEYPAGE_KEY_VERSION((share), (x)))) |
791 | |
792 | #define _ma_store_key_version(share,x,kv) \ |
793 | int4store(KEYPAGE_KEY_VERSION((share), (x)), (kv)) |
794 | |
795 | /* |
796 | TODO: write int4store_aligned as *((uint32 *) (T))= (uint32) (A) for |
797 | architectures where it is possible |
798 | */ |
799 | #define int4store_aligned(A,B) int4store((A),(B)) |
800 | |
801 | #define maria_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \ |
802 | DBUG_PRINT("error", ("Marked table crashed")); \ |
803 | }while(0) |
804 | #define maria_mark_crashed_share(x) \ |
805 | do{(x)->state.changed|= STATE_CRASHED; \ |
806 | DBUG_PRINT("error", ("Marked table crashed")); \ |
807 | }while(0) |
808 | #define maria_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \ |
809 | STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \ |
810 | (x)->update|= HA_STATE_CHANGED; \ |
811 | DBUG_PRINT("error", ("Marked table crashed on repair")); \ |
812 | }while(0) |
813 | #define maria_mark_in_repair(x) do{(x)->s->state.changed|= \ |
814 | STATE_CRASHED | STATE_IN_REPAIR; \ |
815 | (x)->update|= HA_STATE_CHANGED; \ |
816 | DBUG_PRINT("error", ("Marked table crashed for repair")); \ |
817 | }while(0) |
818 | #define maria_is_crashed(x) ((x)->s->state.changed & STATE_CRASHED) |
819 | #define maria_is_crashed_on_repair(x) ((x)->s->state.changed & STATE_CRASHED_ON_REPAIR) |
820 | #define maria_in_repair(x) ((x)->s->state.changed & STATE_IN_REPAIR) |
821 | |
822 | #ifdef EXTRA_DEBUG |
823 | /** |
824 | Brings additional information in certain debug builds and in standalone |
825 | (non-ha_maria) programs. To help debugging. Not in ha_maria, to not spam the |
826 | user (some messages can be produced many times per statement, or even |
827 | wrongly during some repair operations). |
828 | */ |
829 | #define maria_print_error(SHARE, ERRNO) \ |
830 | do{ if (!maria_in_ha_maria) \ |
831 | _ma_report_error((ERRNO), &(SHARE)->index_file_name); } \ |
832 | while(0) |
833 | #else |
834 | #define maria_print_error(SHARE, ERRNO) while (0) |
835 | #endif |
836 | #define DBUG_DUMP_KEY(name, key) DBUG_DUMP(name, (key)->data, (key)->data_length + (key)->ref_length) |
837 | |
838 | /* Functions to store length of space packed keys, VARCHAR or BLOB keys */ |
839 | |
840 | #define store_key_length(key,length) \ |
841 | { if ((length) < 255) \ |
842 | { *(key)=(length); } \ |
843 | else \ |
844 | { *(key)=255; mi_int2store((key)+1,(length)); } \ |
845 | } |
846 | |
847 | #define get_key_full_length(length,key) \ |
848 | { if (*(const uchar*) (key) != 255) \ |
849 | length= ((uint) *(const uchar*) ((key)++))+1; \ |
850 | else \ |
851 | { length=mi_uint2korr((key)+1)+3; (key)+=3; } \ |
852 | } |
853 | |
854 | #define get_key_full_length_rdonly(length,key) \ |
855 | { if (*(const uchar*) (key) != 255) \ |
856 | length= ((uint) *(const uchar*) ((key)))+1; \ |
857 | else \ |
858 | { length=mi_uint2korr((key)+1)+3; } \ |
859 | } |
860 | |
861 | #define _ma_max_key_length() ((maria_block_size - MAX_KEYPAGE_HEADER_SIZE)/3 - MARIA_INDEX_OVERHEAD_SIZE) |
862 | #define get_pack_length(length) ((length) >= 255 ? 3 : 1) |
863 | #define _ma_have_versioning(info) ((info)->row_flag & ROW_FLAG_TRANSID) |
864 | |
865 | /** |
866 | Sets table's trn and prints debug information |
867 | @param tbl MARIA_HA of table |
868 | @param newtrn what to put into tbl->trn |
869 | @note cast of newtrn is because %p of NULL gives warning (NULL is int) |
870 | */ |
871 | #define _ma_set_trn_for_table(tbl, newtrn) do { \ |
872 | DBUG_PRINT("info",("table: %p trn: %p -> %p", \ |
873 | (tbl), (tbl)->trn, (void *)(newtrn))); \ |
874 | (tbl)->trn= (newtrn); \ |
875 | } while (0) |
876 | |
877 | |
878 | #define MARIA_MIN_BLOCK_LENGTH 20 /* Because of delete-link */ |
879 | /* Don't use to small record-blocks */ |
880 | #define MARIA_EXTEND_BLOCK_LENGTH 20 |
881 | #define MARIA_SPLIT_LENGTH ((MARIA_EXTEND_BLOCK_LENGTH+4)*2) |
882 | /* Max prefix of record-block */ |
883 | #define 20 |
884 | #define 20 |
885 | #define 20 /* length of delete-block-header */ |
886 | #define MARIA_DYN_MAX_BLOCK_LENGTH ((1L << 24)-4L) |
887 | #define MARIA_DYN_MAX_ROW_LENGTH (MARIA_DYN_MAX_BLOCK_LENGTH - MARIA_SPLIT_LENGTH) |
888 | #define MARIA_DYN_ALIGN_SIZE 4 /* Align blocks on this */ |
889 | #define 13 /* max header uchar for dynamic rows */ |
890 | #define MARIA_MAX_BLOCK_LENGTH ((((ulong) 1 << 24)-1) & (~ (ulong) (MARIA_DYN_ALIGN_SIZE-1))) |
891 | #define MARIA_REC_BUFF_OFFSET ALIGN_SIZE(MARIA_DYN_DELETE_BLOCK_HEADER+sizeof(uint32)) |
892 | |
893 | #define 7 /* Write this as a suffix for file */ |
894 | |
895 | #define PACK_TYPE_SELECTED 1U /* Bits in field->pack_type */ |
896 | #define PACK_TYPE_SPACE_FIELDS 2U |
897 | #define PACK_TYPE_ZERO_FILL 4U |
898 | #define MARIA_FOUND_WRONG_KEY 32768U /* Impossible value from ha_key_cmp */ |
899 | |
900 | #define MARIA_BLOCK_SIZE(key_length,data_pointer,key_pointer,block_size) (((((key_length)+(data_pointer)+(key_pointer))*4+(key_pointer)+2)/(block_size)+1)*(block_size)) |
901 | #define MARIA_MAX_KEYPTR_SIZE 5 /* For calculating block lengths */ |
902 | |
903 | /* Marker for impossible delete link */ |
904 | #define IMPOSSIBLE_PAGE_NO 0xFFFFFFFFFFLL |
905 | |
906 | /* The UNIQUE check is done with a hashed long key */ |
907 | |
908 | #define MARIA_UNIQUE_HASH_TYPE HA_KEYTYPE_ULONG_INT |
909 | #define maria_unique_store(A,B) mi_int4store((A),(B)) |
910 | |
911 | extern mysql_mutex_t THR_LOCK_maria; |
912 | #ifdef DONT_USE_RW_LOCKS |
913 | #define mysql_rwlock_wrlock(A) {} |
914 | #define mysql_rwlock_rdlock(A) {} |
915 | #define mysql_rwlock_unlock(A) {} |
916 | #endif |
917 | |
918 | /* Some tuning parameters */ |
919 | #define MARIA_MIN_KEYBLOCK_LENGTH 50 /* When to split delete blocks */ |
920 | #define MARIA_MIN_SIZE_BULK_INSERT_TREE 16384U /* this is per key */ |
921 | #define MARIA_MIN_ROWS_TO_USE_BULK_INSERT 100 |
922 | #define MARIA_MIN_ROWS_TO_DISABLE_INDEXES 100 |
923 | #define MARIA_MIN_ROWS_TO_USE_WRITE_CACHE 10 |
924 | /* Keep a small buffer for tables only using small blobs */ |
925 | #define MARIA_SMALL_BLOB_BUFFER 1024U |
926 | #define MARIA_MAX_CONTROL_FILE_LOCK_RETRY 30 /* Retry this many times */ |
927 | |
928 | /* Some extern variables */ |
929 | extern LIST *maria_open_list; |
930 | extern uchar maria_file_magic[], maria_pack_file_magic[]; |
931 | extern uchar maria_uuid[MY_UUID_SIZE]; |
932 | extern uint32 maria_read_vec[], maria_readnext_vec[]; |
933 | extern uint maria_quick_table_bits; |
934 | extern char *maria_data_root; |
935 | extern uchar maria_zero_string[]; |
936 | extern my_bool maria_inited, maria_in_ha_maria, maria_recovery_changed_data; |
937 | extern my_bool maria_recovery_verbose, maria_checkpoint_disabled; |
938 | extern my_bool maria_assert_if_crashed_table; |
939 | extern ulong maria_checkpoint_min_log_activity; |
940 | extern HASH maria_stored_state; |
941 | extern int (*maria_create_trn_hook)(MARIA_HA *); |
942 | extern my_bool (*ma_killed)(MARIA_HA *); |
943 | |
944 | #ifdef HAVE_PSI_INTERFACE |
945 | extern PSI_mutex_key key_SHARE_BITMAP_lock, key_SORT_INFO_mutex, |
946 | key_THR_LOCK_maria, key_TRANSLOG_BUFFER_mutex, |
947 | key_LOCK_soft_sync, |
948 | key_TRANSLOG_DESCRIPTOR_dirty_buffer_mask_lock, |
949 | key_TRANSLOG_DESCRIPTOR_sent_to_disk_lock, |
950 | key_TRANSLOG_DESCRIPTOR_log_flush_lock, |
951 | , |
952 | key_TRANSLOG_DESCRIPTOR_unfinished_files_lock, |
953 | key_TRANSLOG_DESCRIPTOR_purger_lock, |
954 | key_SHARE_intern_lock, key_SHARE_key_del_lock, |
955 | key_SHARE_close_lock, |
956 | key_SERVICE_THREAD_CONTROL_lock, |
957 | key_PAGECACHE_cache_lock; |
958 | |
959 | extern PSI_mutex_key key_CRYPT_DATA_lock; |
960 | |
961 | extern PSI_cond_key key_SHARE_key_del_cond, key_SERVICE_THREAD_CONTROL_cond, |
962 | key_SORT_INFO_cond, key_SHARE_BITMAP_cond, |
963 | key_COND_soft_sync, key_TRANSLOG_BUFFER_waiting_filling_buffer, |
964 | key_TRANSLOG_BUFFER_prev_sent_to_disk_cond, |
965 | key_TRANSLOG_DESCRIPTOR_log_flush_cond, |
966 | key_TRANSLOG_DESCRIPTOR_new_goal_cond; |
967 | |
968 | extern PSI_rwlock_key key_KEYINFO_root_lock, key_SHARE_mmap_lock, |
969 | key_TRANSLOG_DESCRIPTOR_open_files_lock; |
970 | |
971 | extern PSI_thread_key key_thread_checkpoint, key_thread_find_all_keys, |
972 | key_thread_soft_sync; |
973 | |
974 | extern PSI_file_key key_file_translog, key_file_kfile, key_file_dfile, |
975 | key_file_control, key_file_tmp; |
976 | |
977 | #endif |
978 | |
979 | /* Note that PSI_stage_info globals must always be declared. */ |
980 | extern PSI_stage_info stage_waiting_for_a_resource; |
981 | |
982 | /* This is used by _ma_calc_xxx_key_length och _ma_store_key */ |
983 | typedef struct st_maria_s_param |
984 | { |
985 | const uchar *key; |
986 | uchar *prev_key, *next_key_pos; |
987 | uchar *key_pos; /* For balance page */ |
988 | uint ref_length, key_length, n_ref_length; |
989 | uint n_length, totlength, part_of_prev_key, prev_length, pack_marker; |
990 | uint changed_length; |
991 | int move_length; /* For balance_page */ |
992 | my_bool store_not_null; |
993 | } MARIA_KEY_PARAM; |
994 | |
995 | |
996 | /* Used to store reference to pinned page */ |
997 | typedef struct st_pinned_page |
998 | { |
999 | PAGECACHE_BLOCK_LINK *link; |
1000 | enum pagecache_page_lock unlock, write_lock; |
1001 | my_bool changed; |
1002 | } MARIA_PINNED_PAGE; |
1003 | |
1004 | |
1005 | /* Keeps all information about a page and related to a page */ |
1006 | typedef struct st_maria_page |
1007 | { |
1008 | MARIA_HA *info; |
1009 | const MARIA_KEYDEF *keyinfo; |
1010 | uchar *buff; /* Data for page */ |
1011 | my_off_t pos; /* Disk address to page */ |
1012 | uint size; /* Size of data on page */ |
1013 | uint org_size; /* Size of page at read or after log */ |
1014 | uint node; /* 0 or share->base.key_reflength */ |
1015 | uint flag; /* Page flag */ |
1016 | uint link_offset; |
1017 | } MARIA_PAGE; |
1018 | |
1019 | |
1020 | /* Prototypes for intern functions */ |
1021 | extern int _ma_read_dynamic_record(MARIA_HA *, uchar *, MARIA_RECORD_POS); |
1022 | extern int _ma_read_rnd_dynamic_record(MARIA_HA *, uchar *, MARIA_RECORD_POS, |
1023 | my_bool); |
1024 | extern my_bool _ma_write_dynamic_record(MARIA_HA *, const uchar *); |
1025 | extern my_bool _ma_update_dynamic_record(MARIA_HA *, MARIA_RECORD_POS, |
1026 | const uchar *, const uchar *); |
1027 | extern my_bool _ma_delete_dynamic_record(MARIA_HA *info, const uchar *record); |
1028 | extern my_bool _ma_cmp_dynamic_record(MARIA_HA *info, const uchar *record); |
1029 | extern my_bool _ma_write_blob_record(MARIA_HA *, const uchar *); |
1030 | extern my_bool _ma_update_blob_record(MARIA_HA *, MARIA_RECORD_POS, |
1031 | const uchar *, const uchar *); |
1032 | extern int _ma_read_static_record(MARIA_HA *info, uchar *, MARIA_RECORD_POS); |
1033 | extern int _ma_read_rnd_static_record(MARIA_HA *, uchar *, MARIA_RECORD_POS, |
1034 | my_bool); |
1035 | extern my_bool _ma_write_static_record(MARIA_HA *, const uchar *); |
1036 | extern my_bool _ma_update_static_record(MARIA_HA *, MARIA_RECORD_POS, |
1037 | const uchar *, const uchar *); |
1038 | extern my_bool _ma_delete_static_record(MARIA_HA *info, const uchar *record); |
1039 | extern my_bool _ma_cmp_static_record(MARIA_HA *info, const uchar *record); |
1040 | |
1041 | extern my_bool _ma_write_no_record(MARIA_HA *info, const uchar *record); |
1042 | extern my_bool _ma_update_no_record(MARIA_HA *info, MARIA_RECORD_POS pos, |
1043 | const uchar *oldrec, const uchar *record); |
1044 | extern my_bool _ma_delete_no_record(MARIA_HA *info, const uchar *record); |
1045 | extern int _ma_read_no_record(MARIA_HA *info, uchar *record, |
1046 | MARIA_RECORD_POS pos); |
1047 | extern int _ma_read_rnd_no_record(MARIA_HA *info, uchar *buf, |
1048 | MARIA_RECORD_POS filepos, |
1049 | my_bool skip_deleted_blocks); |
1050 | my_off_t _ma_no_keypos_to_recpos(MARIA_SHARE *share, my_off_t pos); |
1051 | |
1052 | extern my_bool _ma_ck_write(MARIA_HA *info, MARIA_KEY *key); |
1053 | extern my_bool _ma_enlarge_root(MARIA_HA *info, MARIA_KEY *key, |
1054 | MARIA_RECORD_POS *root); |
1055 | int _ma_insert(MARIA_HA *info, MARIA_KEY *key, |
1056 | MARIA_PAGE *anc_page, uchar *key_pos, uchar *key_buff, |
1057 | MARIA_PAGE *father_page, uchar *father_key_pos, |
1058 | my_bool insert_last); |
1059 | extern my_bool _ma_ck_real_write_btree(MARIA_HA *info, MARIA_KEY *key, |
1060 | MARIA_RECORD_POS *root, uint32 comp_flag); |
1061 | extern int _ma_split_page(MARIA_HA *info, MARIA_KEY *key, |
1062 | MARIA_PAGE *split_page, |
1063 | uint org_split_length, |
1064 | uchar *inserted_key_pos, uint changed_length, |
1065 | int move_length, |
1066 | uchar *key_buff, my_bool insert_last_key); |
1067 | extern uchar *_ma_find_half_pos(MARIA_KEY *key, MARIA_PAGE *page, |
1068 | uchar ** after_key); |
1069 | extern int _ma_calc_static_key_length(const MARIA_KEY *key, uint nod_flag, |
1070 | uchar *key_pos, uchar *org_key, |
1071 | uchar *key_buff, |
1072 | MARIA_KEY_PARAM *s_temp); |
1073 | extern int _ma_calc_var_key_length(const MARIA_KEY *key, uint nod_flag, |
1074 | uchar *key_pos, uchar *org_key, |
1075 | uchar *key_buff, |
1076 | MARIA_KEY_PARAM *s_temp); |
1077 | extern int _ma_calc_var_pack_key_length(const MARIA_KEY *key, |
1078 | uint nod_flag, uchar *next_key, |
1079 | uchar *org_key, uchar *prev_key, |
1080 | MARIA_KEY_PARAM *s_temp); |
1081 | extern int _ma_calc_bin_pack_key_length(const MARIA_KEY *key, |
1082 | uint nod_flag, uchar *next_key, |
1083 | uchar *org_key, uchar *prev_key, |
1084 | MARIA_KEY_PARAM *s_temp); |
1085 | extern void _ma_store_static_key(MARIA_KEYDEF *keyinfo, uchar *key_pos, |
1086 | MARIA_KEY_PARAM *s_temp); |
1087 | extern void _ma_store_var_pack_key(MARIA_KEYDEF *keyinfo, uchar *key_pos, |
1088 | MARIA_KEY_PARAM *s_temp); |
1089 | #ifdef NOT_USED |
1090 | extern void _ma_store_pack_key(MARIA_KEYDEF *keyinfo, uchar *key_pos, |
1091 | MARIA_KEY_PARAM *s_temp); |
1092 | #endif |
1093 | extern void _ma_store_bin_pack_key(MARIA_KEYDEF *keyinfo, uchar *key_pos, |
1094 | MARIA_KEY_PARAM *s_temp); |
1095 | |
1096 | extern my_bool _ma_ck_delete(MARIA_HA *info, MARIA_KEY *key); |
1097 | extern my_bool _ma_ck_real_delete(MARIA_HA *info, MARIA_KEY *key, |
1098 | my_off_t *root); |
1099 | extern int _ma_readinfo(MARIA_HA *info, int lock_flag, int check_keybuffer); |
1100 | extern int _ma_writeinfo(MARIA_HA *info, uint options); |
1101 | extern int _ma_test_if_changed(MARIA_HA *info); |
1102 | extern int _ma_mark_file_changed(MARIA_SHARE *info); |
1103 | extern int _ma_mark_file_changed_now(MARIA_SHARE *info); |
1104 | extern void _ma_mark_file_crashed(MARIA_SHARE *share); |
1105 | void _ma_set_fatal_error(MARIA_SHARE *share, int error); |
1106 | extern my_bool _ma_set_uuid(MARIA_SHARE *info, my_bool reset_uuid); |
1107 | extern my_bool _ma_check_if_zero(uchar *pos, size_t size); |
1108 | extern int _ma_decrement_open_count(MARIA_HA *info, my_bool lock_table); |
1109 | extern int _ma_check_index(MARIA_HA *info, int inx); |
1110 | extern int _ma_search(MARIA_HA *info, MARIA_KEY *key, uint32 nextflag, |
1111 | my_off_t pos); |
1112 | extern int _ma_bin_search(const MARIA_KEY *key, const MARIA_PAGE *page, |
1113 | uint32 comp_flag, uchar **ret_pos, uchar *buff, |
1114 | my_bool *was_last_key); |
1115 | extern int _ma_seq_search(const MARIA_KEY *key, const MARIA_PAGE *page, |
1116 | uint comp_flag, uchar ** ret_pos, uchar *buff, |
1117 | my_bool *was_last_key); |
1118 | extern int _ma_prefix_search(const MARIA_KEY *key, const MARIA_PAGE *page, |
1119 | uint32 comp_flag, uchar ** ret_pos, uchar *buff, |
1120 | my_bool *was_last_key); |
1121 | extern my_off_t _ma_kpos(uint nod_flag, const uchar *after_key); |
1122 | extern void _ma_kpointer(MARIA_HA *info, uchar *buff, my_off_t pos); |
1123 | MARIA_RECORD_POS _ma_row_pos_from_key(const MARIA_KEY *key); |
1124 | TrID _ma_trid_from_key(const MARIA_KEY *key); |
1125 | extern MARIA_RECORD_POS _ma_rec_pos(MARIA_SHARE *share, uchar *ptr); |
1126 | extern void _ma_dpointer(MARIA_SHARE *share, uchar *buff, |
1127 | MARIA_RECORD_POS pos); |
1128 | extern uint _ma_get_static_key(MARIA_KEY *key, uint page_flag, uint nod_flag, |
1129 | uchar **page); |
1130 | extern uchar *_ma_skip_static_key(MARIA_KEY *key, uint page_flag, |
1131 | uint nod_flag, uchar *page); |
1132 | extern uint _ma_get_pack_key(MARIA_KEY *key, uint page_flag, uint nod_flag, |
1133 | uchar **page); |
1134 | extern uchar *_ma_skip_pack_key(MARIA_KEY *key, uint page_flag, |
1135 | uint nod_flag, uchar *page); |
1136 | extern uint _ma_get_binary_pack_key(MARIA_KEY *key, uint page_flag, |
1137 | uint nod_flag, uchar **page_pos); |
1138 | uchar *_ma_skip_binary_pack_key(MARIA_KEY *key, uint page_flag, |
1139 | uint nod_flag, uchar *page); |
1140 | extern uchar *_ma_get_last_key(MARIA_KEY *key, MARIA_PAGE *page, |
1141 | uchar *endpos); |
1142 | extern uchar *_ma_get_key(MARIA_KEY *key, MARIA_PAGE *page, uchar *keypos); |
1143 | extern uint _ma_keylength(MARIA_KEYDEF *keyinfo, const uchar *key); |
1144 | extern uint _ma_keylength_part(MARIA_KEYDEF *keyinfo, const uchar *key, |
1145 | HA_KEYSEG *end); |
1146 | extern int _ma_search_next(MARIA_HA *info, MARIA_KEY *key, |
1147 | uint32 nextflag, my_off_t pos); |
1148 | extern int _ma_search_first(MARIA_HA *info, MARIA_KEYDEF *keyinfo, |
1149 | my_off_t pos); |
1150 | extern int _ma_search_last(MARIA_HA *info, MARIA_KEYDEF *keyinfo, |
1151 | my_off_t pos); |
1152 | extern my_off_t _ma_static_keypos_to_recpos(MARIA_SHARE *share, my_off_t pos); |
1153 | extern my_off_t _ma_static_recpos_to_keypos(MARIA_SHARE *share, my_off_t pos); |
1154 | extern my_off_t _ma_transparent_recpos(MARIA_SHARE *share, my_off_t pos); |
1155 | extern my_off_t _ma_transaction_keypos_to_recpos(MARIA_SHARE *, my_off_t pos); |
1156 | extern my_off_t _ma_transaction_recpos_to_keypos(MARIA_SHARE *, my_off_t pos); |
1157 | |
1158 | extern void _ma_page_setup(MARIA_PAGE *page, MARIA_HA *info, |
1159 | const MARIA_KEYDEF *keyinfo, my_off_t pos, |
1160 | uchar *buff); |
1161 | extern my_bool _ma_fetch_keypage(MARIA_PAGE *page, MARIA_HA *info, |
1162 | const MARIA_KEYDEF *keyinfo, |
1163 | my_off_t pos, enum pagecache_page_lock lock, |
1164 | int level, uchar *buff, |
1165 | my_bool return_buffer); |
1166 | extern my_bool _ma_write_keypage(MARIA_PAGE *page, |
1167 | enum pagecache_page_lock lock, int level); |
1168 | extern int _ma_dispose(MARIA_HA *info, my_off_t pos, my_bool page_not_read); |
1169 | extern my_off_t _ma_new(MARIA_HA *info, int level, |
1170 | MARIA_PINNED_PAGE **page_link); |
1171 | extern my_bool _ma_compact_keypage(MARIA_PAGE *page, TrID min_read_from); |
1172 | extern uint transid_store_packed(MARIA_HA *info, uchar *to, ulonglong trid); |
1173 | extern ulonglong transid_get_packed(MARIA_SHARE *share, const uchar *from); |
1174 | #define transid_packed_length(data) \ |
1175 | ((data)[0] < MARIA_MIN_TRANSID_PACK_OFFSET ? 1 : \ |
1176 | (uint) ((uchar) (data)[0]) - (MARIA_TRANSID_PACK_OFFSET - 1)) |
1177 | #define key_has_transid(key) (*(key) & 1) |
1178 | |
1179 | #define page_mark_changed(info, page) \ |
1180 | dynamic_element(&(info)->pinned_pages, (page)->link_offset, \ |
1181 | MARIA_PINNED_PAGE*)->changed= 1; |
1182 | #define page_store_size(share, page) \ |
1183 | _ma_store_page_used((share), (page)->buff, (page)->size); |
1184 | #define page_store_info(share, page) \ |
1185 | _ma_store_keypage_flag((share), (page)->buff, (page)->flag); \ |
1186 | _ma_store_page_used((share), (page)->buff, (page)->size); |
1187 | #ifdef IDENTICAL_PAGES_AFTER_RECOVERY |
1188 | void page_cleanup(MARIA_SHARE *share, MARIA_PAGE *page) |
1189 | #else |
1190 | #define page_cleanup(A,B) do { } while (0) |
1191 | #endif |
1192 | |
1193 | extern MARIA_KEY *_ma_make_key(MARIA_HA *info, MARIA_KEY *int_key, uint keynr, |
1194 | uchar *key, const uchar *record, |
1195 | MARIA_RECORD_POS filepos, ulonglong trid); |
1196 | extern MARIA_KEY *_ma_pack_key(MARIA_HA *info, MARIA_KEY *int_key, |
1197 | uint keynr, uchar *key, |
1198 | const uchar *old, key_part_map keypart_map, |
1199 | HA_KEYSEG ** last_used_keyseg); |
1200 | extern void _ma_copy_key(MARIA_KEY *to, const MARIA_KEY *from); |
1201 | extern int _ma_read_key_record(MARIA_HA *info, uchar *buf, MARIA_RECORD_POS); |
1202 | extern my_bool _ma_read_cache(MARIA_HA *, IO_CACHE *info, uchar *buff, |
1203 | MARIA_RECORD_POS pos, size_t length, |
1204 | uint re_read_if_possibly); |
1205 | extern ulonglong ma_retrieve_auto_increment(const uchar *key, uint8 key_type); |
1206 | extern my_bool _ma_alloc_buffer(uchar **old_addr, size_t *old_size, |
1207 | size_t new_size); |
1208 | extern size_t _ma_rec_unpack(MARIA_HA *info, uchar *to, uchar *from, |
1209 | size_t reclength); |
1210 | extern my_bool _ma_rec_check(MARIA_HA *info, const uchar *record, |
1211 | uchar *packpos, ulong packed_length, |
1212 | my_bool with_checkum, ha_checksum checksum); |
1213 | extern int _ma_write_part_record(MARIA_HA *info, my_off_t filepos, |
1214 | ulong length, my_off_t next_filepos, |
1215 | uchar ** record, ulong *reclength, |
1216 | int *flag); |
1217 | extern void _ma_print_key(FILE *stream, MARIA_KEY *key); |
1218 | extern void _ma_print_keydata(FILE *stream, HA_KEYSEG *keyseg, |
1219 | const uchar *key, uint length); |
1220 | extern my_bool _ma_once_init_pack_row(MARIA_SHARE *share, File dfile); |
1221 | extern my_bool _ma_once_end_pack_row(MARIA_SHARE *share); |
1222 | extern int _ma_read_pack_record(MARIA_HA *info, uchar *buf, |
1223 | MARIA_RECORD_POS filepos); |
1224 | extern int _ma_read_rnd_pack_record(MARIA_HA *, uchar *, MARIA_RECORD_POS, |
1225 | my_bool); |
1226 | extern int _ma_pack_rec_unpack(MARIA_HA *info, MARIA_BIT_BUFF *bit_buff, |
1227 | uchar *to, uchar *from, ulong reclength); |
1228 | extern ulonglong _ma_safe_mul(ulonglong a, ulonglong b); |
1229 | extern int _ma_ft_update(MARIA_HA *info, uint keynr, uchar *keybuf, |
1230 | const uchar *oldrec, const uchar *newrec, |
1231 | my_off_t pos); |
1232 | |
1233 | /* |
1234 | Parameter to _ma_get_block_info |
1235 | The dynamic row header is read into this struct. For an explanation of |
1236 | the fields, look at the function _ma_get_block_info(). |
1237 | */ |
1238 | |
1239 | typedef struct st_maria_block_info |
1240 | { |
1241 | uchar [MARIA_BLOCK_INFO_HEADER_LENGTH]; |
1242 | ulong rec_len; |
1243 | ulong data_len; |
1244 | ulong block_len; |
1245 | ulong blob_len; |
1246 | MARIA_RECORD_POS filepos; |
1247 | MARIA_RECORD_POS next_filepos; |
1248 | MARIA_RECORD_POS prev_filepos; |
1249 | uint second_read; |
1250 | uint offset; |
1251 | } MARIA_BLOCK_INFO; |
1252 | |
1253 | |
1254 | /* bits in return from _ma_get_block_info */ |
1255 | |
1256 | #define BLOCK_FIRST 1U |
1257 | #define BLOCK_LAST 2U |
1258 | #define BLOCK_DELETED 4U |
1259 | #define BLOCK_ERROR 8U /* Wrong data */ |
1260 | #define BLOCK_SYNC_ERROR 16U /* Right data at wrong place */ |
1261 | #define BLOCK_FATAL_ERROR 32U /* hardware-error */ |
1262 | |
1263 | #define NEED_MEM ((uint) 10*4*(IO_SIZE+32)+32) /* Nead for recursion */ |
1264 | #define MAXERR 20 |
1265 | #define BUFFERS_WHEN_SORTING 16 /* Alloc for sort-key-tree */ |
1266 | #define WRITE_COUNT MY_HOW_OFTEN_TO_WRITE |
1267 | #define INDEX_TMP_EXT ".TMM" |
1268 | #define DATA_TMP_EXT ".TMD" |
1269 | |
1270 | #define UPDATE_TIME 1U |
1271 | #define UPDATE_STAT 2U |
1272 | #define UPDATE_SORT 4U |
1273 | #define UPDATE_AUTO_INC 8U |
1274 | #define UPDATE_OPEN_COUNT 16U |
1275 | |
1276 | /* We use MY_ALIGN_DOWN here mainly to ensure that we get stable values for mysqld --help ) */ |
1277 | #define PAGE_BUFFER_INIT MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 8192) |
1278 | #define READ_BUFFER_INIT MY_ALIGN_DOWN(1024L*256L-MALLOC_OVERHEAD, 1024) |
1279 | #define SORT_BUFFER_INIT MY_ALIGN_DOWN(1024L*1024L*256L-MALLOC_OVERHEAD, 1024) |
1280 | #define MIN_SORT_BUFFER 4096U |
1281 | |
1282 | #define fast_ma_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _ma_writeinfo((INFO),0) |
1283 | #define fast_ma_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _ma_readinfo((INFO),F_RDLCK,1) |
1284 | |
1285 | extern uint _ma_get_block_info(MARIA_HA *, MARIA_BLOCK_INFO *, File, my_off_t); |
1286 | extern uint _ma_rec_pack(MARIA_HA *info, uchar *to, const uchar *from); |
1287 | extern uint _ma_pack_get_block_info(MARIA_HA *maria, MARIA_BIT_BUFF *bit_buff, |
1288 | MARIA_BLOCK_INFO *info, uchar **rec_buff_p, |
1289 | size_t *rec_buff_size, |
1290 | File file, my_off_t filepos); |
1291 | extern void _ma_store_blob_length(uchar *pos, uint pack_length, uint length); |
1292 | extern void _ma_report_error(int errcode, const LEX_STRING *file_name); |
1293 | extern my_bool _ma_memmap_file(MARIA_HA *info); |
1294 | extern void _ma_unmap_file(MARIA_HA *info); |
1295 | extern uint _ma_save_pack_length(uint version, uchar * block_buff, |
1296 | ulong length); |
1297 | extern uint _ma_calc_pack_length(uint version, ulong length); |
1298 | extern ulong _ma_calc_blob_length(uint length, const uchar *pos); |
1299 | extern size_t _ma_mmap_pread(MARIA_HA *info, uchar *Buffer, |
1300 | size_t Count, my_off_t offset, myf MyFlags); |
1301 | extern size_t _ma_mmap_pwrite(MARIA_HA *info, const uchar *Buffer, |
1302 | size_t Count, my_off_t offset, myf MyFlags); |
1303 | extern size_t _ma_nommap_pread(MARIA_HA *info, uchar *Buffer, |
1304 | size_t Count, my_off_t offset, myf MyFlags); |
1305 | extern size_t _ma_nommap_pwrite(MARIA_HA *info, const uchar *Buffer, |
1306 | size_t Count, my_off_t offset, myf MyFlags); |
1307 | |
1308 | /* my_pwrite instead of my_write used */ |
1309 | #define MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET 1 |
1310 | /* info should be written */ |
1311 | #define MA_STATE_INFO_WRITE_FULL_INFO 2 |
1312 | /* intern_lock taking is needed */ |
1313 | #define MA_STATE_INFO_WRITE_LOCK 4 |
1314 | uint _ma_state_info_write(MARIA_SHARE *share, uint pWrite); |
1315 | uint _ma_state_info_write_sub(File file, MARIA_STATE_INFO *state, uint pWrite); |
1316 | uint _ma_state_info_read_dsk(File file, MARIA_STATE_INFO *state); |
1317 | uint _ma_base_info_write(File file, MARIA_BASE_INFO *base); |
1318 | my_bool _ma_keyseg_write(File file, const HA_KEYSEG *keyseg); |
1319 | uchar *_ma_keyseg_read(uchar *ptr, HA_KEYSEG *keyseg); |
1320 | my_bool _ma_keydef_write(File file, MARIA_KEYDEF *keydef); |
1321 | uchar *_ma_keydef_read(uchar *ptr, MARIA_KEYDEF *keydef); |
1322 | my_bool _ma_uniquedef_write(File file, MARIA_UNIQUEDEF *keydef); |
1323 | uchar *_ma_uniquedef_read(uchar *ptr, MARIA_UNIQUEDEF *keydef); |
1324 | my_bool _ma_columndef_write(File file, MARIA_COLUMNDEF *columndef); |
1325 | uchar *_ma_columndef_read(uchar *ptr, MARIA_COLUMNDEF *columndef); |
1326 | my_bool _ma_column_nr_write(File file, uint16 *offsets, uint columns); |
1327 | uchar *_ma_column_nr_read(uchar *ptr, uint16 *offsets, uint columns); |
1328 | ulong _ma_calc_total_blob_length(MARIA_HA *info, const uchar *record); |
1329 | ha_checksum _ma_checksum(MARIA_HA *info, const uchar *buf); |
1330 | ha_checksum _ma_static_checksum(MARIA_HA *info, const uchar *buf); |
1331 | my_bool _ma_check_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def, |
1332 | const uchar *record, ha_checksum unique_hash, |
1333 | MARIA_RECORD_POS pos); |
1334 | ha_checksum _ma_unique_hash(MARIA_UNIQUEDEF *def, const uchar *buf); |
1335 | my_bool _ma_cmp_static_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def, |
1336 | const uchar *record, MARIA_RECORD_POS pos); |
1337 | my_bool _ma_cmp_dynamic_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def, |
1338 | const uchar *record, MARIA_RECORD_POS pos); |
1339 | my_bool _ma_unique_comp(MARIA_UNIQUEDEF *def, const uchar *a, const uchar *b, |
1340 | my_bool null_are_equal); |
1341 | void _ma_get_status(void *param, my_bool concurrent_insert); |
1342 | void _ma_update_status(void *param); |
1343 | void _ma_restore_status(void *param); |
1344 | void _ma_copy_status(void *to, void *from); |
1345 | my_bool _ma_check_status(void *param); |
1346 | void _ma_restore_status(void *param); |
1347 | void _ma_reset_status(MARIA_HA *maria); |
1348 | int _ma_def_scan_remember_pos(MARIA_HA *info, MARIA_RECORD_POS *lastpos); |
1349 | int _ma_def_scan_restore_pos(MARIA_HA *info, MARIA_RECORD_POS lastpos); |
1350 | |
1351 | #include "ma_commit.h" |
1352 | |
1353 | extern MARIA_HA *_ma_test_if_reopen(const char *filename); |
1354 | my_bool _ma_check_table_is_closed(const char *name, const char *where); |
1355 | int _ma_open_datafile(MARIA_HA *info, MARIA_SHARE *share); |
1356 | int _ma_open_keyfile(MARIA_SHARE *share); |
1357 | void _ma_setup_functions(MARIA_SHARE *share); |
1358 | my_bool _ma_dynmap_file(MARIA_HA *info, my_off_t size); |
1359 | void _ma_remap_file(MARIA_HA *info, my_off_t size); |
1360 | |
1361 | MARIA_RECORD_POS _ma_write_init_default(MARIA_HA *info, const uchar *record); |
1362 | my_bool _ma_write_abort_default(MARIA_HA *info); |
1363 | int maria_delete_table_files(const char *name, my_bool temporary, |
1364 | myf sync_dir); |
1365 | |
1366 | /* |
1367 | This cannot be in my_base.h as it clashes with HA_SPATIAL. |
1368 | But it was introduced for Aria engine, and is only used there. |
1369 | So it can safely stay here, only visible to Aria |
1370 | */ |
1371 | #define HA_RTREE_INDEX 16384 /* For RTREE search */ |
1372 | |
1373 | C_MODE_START |
1374 | #define MARIA_FLUSH_DATA 1 |
1375 | #define MARIA_FLUSH_INDEX 2 |
1376 | int _ma_flush_table_files(MARIA_HA *info, uint flush_data_or_index, |
1377 | enum flush_type flush_type_for_data, |
1378 | enum flush_type flush_type_for_index); |
1379 | /* |
1380 | Functions needed by _ma_check (are overridden in MySQL/ha_maria.cc). |
1381 | See ma_check_standalone.h . |
1382 | */ |
1383 | int _ma_killed_ptr(HA_CHECK *param); |
1384 | void _ma_report_progress(HA_CHECK *param, ulonglong progress, |
1385 | ulonglong max_progress); |
1386 | void _ma_check_print_error(HA_CHECK *param, const char *fmt, ...) |
1387 | ATTRIBUTE_FORMAT(printf, 2, 3); |
1388 | void _ma_check_print_warning(HA_CHECK *param, const char *fmt, ...) |
1389 | ATTRIBUTE_FORMAT(printf, 2, 3); |
1390 | void _ma_check_print_info(HA_CHECK *param, const char *fmt, ...) |
1391 | ATTRIBUTE_FORMAT(printf, 2, 3); |
1392 | my_bool write_log_record_for_repair(const HA_CHECK *param, MARIA_HA *info); |
1393 | C_MODE_END |
1394 | |
1395 | int _ma_flush_pending_blocks(MARIA_SORT_PARAM *param); |
1396 | int _ma_sort_ft_buf_flush(MARIA_SORT_PARAM *sort_param); |
1397 | int _ma_thr_write_keys(MARIA_SORT_PARAM *sort_param); |
1398 | pthread_handler_t _ma_thr_find_all_keys(void *arg); |
1399 | |
1400 | int _ma_sort_write_record(MARIA_SORT_PARAM *sort_param); |
1401 | int _ma_create_index_by_sort(MARIA_SORT_PARAM *info, my_bool no_messages, |
1402 | size_t); |
1403 | int _ma_sync_table_files(const MARIA_HA *info); |
1404 | int _ma_initialize_data_file(MARIA_SHARE *share, File dfile); |
1405 | int _ma_update_state_lsns(MARIA_SHARE *share, |
1406 | LSN lsn, TrID create_trid, my_bool do_sync, |
1407 | my_bool update_create_rename_lsn); |
1408 | int _ma_update_state_lsns_sub(MARIA_SHARE *share, LSN lsn, |
1409 | TrID create_trid, my_bool do_sync, |
1410 | my_bool update_create_rename_lsn); |
1411 | void _ma_set_data_pagecache_callbacks(PAGECACHE_FILE *file, |
1412 | MARIA_SHARE *share); |
1413 | void _ma_set_index_pagecache_callbacks(PAGECACHE_FILE *file, |
1414 | MARIA_SHARE *share); |
1415 | void _ma_tmp_disable_logging_for_table(MARIA_HA *info, |
1416 | my_bool log_incomplete); |
1417 | my_bool _ma_reenable_logging_for_table(MARIA_HA *info, my_bool flush_pages); |
1418 | my_bool write_log_record_for_bulk_insert(MARIA_HA *info); |
1419 | void _ma_unpin_all_pages(MARIA_HA *info, LSN undo_lsn); |
1420 | |
1421 | #define MARIA_NO_CRC_NORMAL_PAGE 0xffffffff |
1422 | #define MARIA_NO_CRC_BITMAP_PAGE 0xfffffffe |
1423 | extern my_bool maria_page_crc_set_index(PAGECACHE_IO_HOOK_ARGS *args); |
1424 | extern my_bool maria_page_crc_set_normal(PAGECACHE_IO_HOOK_ARGS *args); |
1425 | extern my_bool maria_page_crc_check_bitmap(int, PAGECACHE_IO_HOOK_ARGS *args); |
1426 | extern my_bool maria_page_crc_check_data(int, PAGECACHE_IO_HOOK_ARGS *args); |
1427 | extern my_bool maria_page_crc_check_index(int, PAGECACHE_IO_HOOK_ARGS *args); |
1428 | extern my_bool maria_page_crc_check_none(int, PAGECACHE_IO_HOOK_ARGS *args); |
1429 | extern my_bool maria_page_filler_set_bitmap(PAGECACHE_IO_HOOK_ARGS *args); |
1430 | extern my_bool maria_page_filler_set_normal(PAGECACHE_IO_HOOK_ARGS *args); |
1431 | extern my_bool maria_page_filler_set_none(PAGECACHE_IO_HOOK_ARGS *args); |
1432 | extern void maria_page_write_failure(int error, PAGECACHE_IO_HOOK_ARGS *args); |
1433 | extern my_bool maria_flush_log_for_page(PAGECACHE_IO_HOOK_ARGS *args); |
1434 | extern my_bool maria_flush_log_for_page_none(PAGECACHE_IO_HOOK_ARGS *args); |
1435 | |
1436 | extern PAGECACHE *maria_log_pagecache; |
1437 | extern void ma_set_index_cond_func(MARIA_HA *info, index_cond_func_t func, |
1438 | void *func_arg); |
1439 | ICP_RESULT ma_check_index_cond(MARIA_HA *info, uint keynr, uchar *record); |
1440 | |
1441 | extern my_bool ma_yield_and_check_if_killed(MARIA_HA *info, int inx); |
1442 | extern my_bool ma_killed_standalone(MARIA_HA *); |
1443 | |
1444 | extern uint _ma_file_callback_to_id(void *callback_data); |
1445 | |