1
1
/*****************************************************************************
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
18
/*****************************************************************************
20
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
4
21
Copyright (c) 2009, Google Inc.
6
23
Portions of this file contain modifications contributed and copyrighted by
82
99
/* Global log system variable */
83
100
UNIV_INTERN log_t* log_sys = NULL;
85
#ifdef UNIV_PFS_RWLOCK
86
UNIV_INTERN mysql_pfs_key_t checkpoint_lock_key;
87
# ifdef UNIV_LOG_ARCHIVE
88
UNIV_INTERN mysql_pfs_key_t archive_lock_key;
90
#endif /* UNIV_PFS_RWLOCK */
93
UNIV_INTERN mysql_pfs_key_t log_sys_mutex_key;
94
UNIV_INTERN mysql_pfs_key_t log_flush_order_mutex_key;
95
#endif /* UNIV_PFS_MUTEX */
98
103
UNIV_INTERN ibool log_do_write = TRUE;
99
104
#endif /* UNIV_DEBUG */
769
774
log_sys = mem_alloc(sizeof(log_t));
771
mutex_create(log_sys_mutex_key, &log_sys->mutex, SYNC_LOG);
773
mutex_create(log_flush_order_mutex_key,
774
&log_sys->log_flush_order_mutex,
775
SYNC_LOG_FLUSH_ORDER);
776
mutex_create(&log_sys->mutex, SYNC_LOG);
777
778
mutex_enter(&(log_sys->mutex));
828
829
log_sys->last_checkpoint_lsn = log_sys->lsn;
829
830
log_sys->n_pending_checkpoint_writes = 0;
831
rw_lock_create(checkpoint_lock_key, &log_sys->checkpoint_lock,
832
SYNC_NO_ORDER_CHECK);
832
rw_lock_create(&log_sys->checkpoint_lock, SYNC_NO_ORDER_CHECK);
834
834
log_sys->checkpoint_buf_ptr = mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE);
835
835
log_sys->checkpoint_buf = ut_align(log_sys->checkpoint_buf_ptr,
846
846
log_sys->n_pending_archive_ios = 0;
848
rw_lock_create(archive_lock_key, &log_sys->archive_lock,
849
SYNC_NO_ORDER_CHECK);
848
rw_lock_create(&log_sys->archive_lock, SYNC_NO_ORDER_CHECK);
851
850
log_sys->archive_buf = NULL;
1166
1165
buf = *(group->file_header_bufs + nth_file);
1168
1167
mach_write_to_4(buf + LOG_GROUP_ID, group->id);
1169
mach_write_to_8(buf + LOG_FILE_START_LSN, start_lsn);
1168
mach_write_ull(buf + LOG_FILE_START_LSN, start_lsn);
1171
1170
/* Wipe over possible label of ibbackup --restore */
1172
1171
memcpy(buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, " ", 4);
1655
1654
recv_apply_hashed_log_recs(TRUE);
1658
n_pages = buf_flush_list(ULINT_MAX, new_oldest);
1657
n_pages = buf_flush_batch(BUF_FLUSH_LIST, ULINT_MAX, new_oldest);
1661
buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
1660
buf_flush_wait_batch_end(BUF_FLUSH_LIST);
1664
1663
if (n_pages == ULINT_UNDEFINED) {
1770
1769
buf = group->checkpoint_buf;
1772
mach_write_to_8(buf + LOG_CHECKPOINT_NO, log_sys->next_checkpoint_no);
1773
mach_write_to_8(buf + LOG_CHECKPOINT_LSN, log_sys->next_checkpoint_lsn);
1771
mach_write_ull(buf + LOG_CHECKPOINT_NO, log_sys->next_checkpoint_no);
1772
mach_write_ull(buf + LOG_CHECKPOINT_LSN, log_sys->next_checkpoint_lsn);
1775
1774
mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET,
1776
1775
log_group_calc_lsn_offset(
1793
mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn);
1792
mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn);
1794
1793
#else /* UNIV_LOG_ARCHIVE */
1795
mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1794
mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1796
1795
#endif /* UNIV_LOG_ARCHIVE */
1798
1797
for (i = 0; i < LOG_MAX_N_GROUPS; i++) {
1884
1883
ib_uint64_t lsn;
1886
1885
mach_write_to_4(hdr_buf + LOG_GROUP_ID, 0);
1887
mach_write_to_8(hdr_buf + LOG_FILE_START_LSN, start);
1886
mach_write_ull(hdr_buf + LOG_FILE_START_LSN, start);
1889
1888
lsn = start + LOG_BLOCK_HDR_SIZE;
1896
1895
+ (sizeof "ibbackup ") - 1));
1897
1896
buf = hdr_buf + LOG_CHECKPOINT_1;
1899
mach_write_to_8(buf + LOG_CHECKPOINT_NO, 0);
1900
mach_write_to_8(buf + LOG_CHECKPOINT_LSN, lsn);
1898
mach_write_ull(buf + LOG_CHECKPOINT_NO, 0);
1899
mach_write_ull(buf + LOG_CHECKPOINT_LSN, lsn);
1902
1901
mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET,
1903
1902
LOG_FILE_HDR_SIZE + LOG_BLOCK_HDR_SIZE);
1905
1904
mach_write_to_4(buf + LOG_CHECKPOINT_LOG_BUF_SIZE, 2 * 1024 * 1024);
1907
mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1906
mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1909
1908
fold = ut_fold_binary(buf, LOG_CHECKPOINT_CHECKSUM_1);
1910
1909
mach_write_to_4(buf + LOG_CHECKPOINT_CHECKSUM_1, fold);
2272
2271
buf = *(group->archive_file_header_bufs + nth_file);
2274
2273
mach_write_to_4(buf + LOG_GROUP_ID, group->id);
2275
mach_write_to_8(buf + LOG_FILE_START_LSN, start_lsn);
2274
mach_write_ull(buf + LOG_FILE_START_LSN, start_lsn);
2276
2275
mach_write_to_4(buf + LOG_FILE_NO, file_no);
2278
2277
mach_write_to_4(buf + LOG_FILE_ARCH_COMPLETED, FALSE);
2308
2307
buf = *(group->archive_file_header_bufs + nth_file);
2310
2309
mach_write_to_4(buf + LOG_FILE_ARCH_COMPLETED, TRUE);
2311
mach_write_to_8(buf + LOG_FILE_END_LSN, end_lsn);
2310
mach_write_ull(buf + LOG_FILE_END_LSN, end_lsn);
2313
2312
dest_offset = nth_file * group->file_size + LOG_FILE_ARCH_COMPLETED;
2372
2371
log_archived_file_name_gen(name, group->id,
2373
2372
group->archived_file_no + n_files);
2375
file_handle = os_file_create(innodb_file_log_key,
2374
file_handle = os_file_create(name, open_mode, OS_FILE_AIO,
2378
2375
OS_DATA_FILE, &ret);
2380
2377
if (!ret && (open_mode == OS_FILE_CREATE)) {
2381
2378
file_handle = os_file_create(
2382
innodb_file_log_key, name, OS_FILE_OPEN,
2383
OS_FILE_AIO, OS_DATA_FILE, &ret);
2379
name, OS_FILE_OPEN, OS_FILE_AIO,
2380
OS_DATA_FILE, &ret);
3099
3096
if (srv_fast_shutdown < 2
3100
3097
&& (srv_error_monitor_active
3101
|| srv_lock_timeout_active || srv_monitor_active)) {
3098
|| srv_lock_timeout_and_monitor_active)) {
3103
3100
mutex_exit(&kernel_mutex);
3131
3128
return; /* We SKIP ALL THE REST !! */
3131
/* Check that the master thread is suspended */
3133
if (srv_n_threads_active[SRV_MASTER] != 0) {
3135
mutex_exit(&kernel_mutex);
3134
3140
mutex_exit(&kernel_mutex);
3136
/* Check that the background threads are suspended */
3138
if (srv_is_any_background_thread_active()) {
3142
3142
mutex_enter(&(log_sys->mutex));
3144
3144
if (log_sys->n_pending_checkpoint_writes
3197
3197
mutex_exit(&(log_sys->mutex));
3199
/* Check that the background threads stay suspended */
3200
if (srv_is_any_background_thread_active()) {
3199
mutex_enter(&kernel_mutex);
3200
/* Check that the master thread has stayed suspended */
3201
if (srv_n_threads_active[SRV_MASTER] != 0) {
3201
3202
fprintf(stderr,
3202
"InnoDB: Warning: some background thread woke up"
3203
"InnoDB: Warning: the master thread woke up"
3203
3204
" during shutdown\n");
3206
mutex_exit(&kernel_mutex);
3210
mutex_exit(&kernel_mutex);
3208
3212
fil_flush_file_spaces(FIL_TABLESPACE);
3209
3213
fil_flush_file_spaces(FIL_LOG);
3221
3225
srv_shutdown_state = SRV_SHUTDOWN_LAST_PHASE;
3223
3227
/* Make some checks that the server really is quiet */
3224
ut_a(!srv_is_any_background_thread_active());
3228
ut_a(srv_n_threads_active[SRV_MASTER] == 0);
3226
3229
ut_a(buf_all_freed());
3227
3230
ut_a(lsn == log_sys->lsn);
3286
3288
ut_memcpy(scan_buf, start, end - start);
3288
recv_scan_log_recs((buf_pool_get_n_pages()
3289
- (recv_n_pool_free_frames * srv_buf_pool_instances))
3290
* UNIV_PAGE_SIZE, FALSE, scan_buf, end - start,
3290
recv_scan_log_recs((buf_pool->curr_size
3291
- recv_n_pool_free_frames) * UNIV_PAGE_SIZE,
3292
FALSE, scan_buf, end - start,
3291
3293
ut_uint64_align_down(buf_start_lsn,
3292
3294
OS_FILE_LOG_BLOCK_SIZE),
3293
3295
&contiguous_lsn, &scanned_lsn);