~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/log/log0log.c

  • Committer: Brian Aker
  • Date: 2010-12-26 00:07:57 UTC
  • Revision ID: brian@tangent.org-20101226000757-ysntnltqywxoe1em
MErge in the include changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (c) 2009, Google Inc.
 
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
 
4
Copyright (C) 2009 Google Inc.
5
5
 
6
6
Portions of this file contain modifications contributed and copyrighted by
7
7
Google, Inc. Those modifications are gratefully acknowledged and are described
82
82
/* Global log system variable */
83
83
UNIV_INTERN log_t*      log_sys = NULL;
84
84
 
 
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;
 
89
# endif
 
90
#endif /* UNIV_PFS_RWLOCK */
 
91
 
 
92
#ifdef UNIV_PFS_MUTEX
 
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 */
 
96
 
85
97
#ifdef UNIV_DEBUG
86
98
UNIV_INTERN ibool       log_do_write = TRUE;
87
99
#endif /* UNIV_DEBUG */
756
768
{
757
769
        log_sys = mem_alloc(sizeof(log_t));
758
770
 
759
 
        mutex_create(&log_sys->mutex, SYNC_LOG);
 
771
        mutex_create(log_sys_mutex_key, &log_sys->mutex, SYNC_LOG);
 
772
 
 
773
        mutex_create(log_flush_order_mutex_key,
 
774
                     &log_sys->log_flush_order_mutex,
 
775
                     SYNC_LOG_FLUSH_ORDER);
760
776
 
761
777
        mutex_enter(&(log_sys->mutex));
762
778
 
812
828
        log_sys->last_checkpoint_lsn = log_sys->lsn;
813
829
        log_sys->n_pending_checkpoint_writes = 0;
814
830
 
815
 
        rw_lock_create(&log_sys->checkpoint_lock, SYNC_NO_ORDER_CHECK);
 
831
        rw_lock_create(checkpoint_lock_key, &log_sys->checkpoint_lock,
 
832
                       SYNC_NO_ORDER_CHECK);
816
833
 
817
834
        log_sys->checkpoint_buf_ptr = mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE);
818
835
        log_sys->checkpoint_buf = ut_align(log_sys->checkpoint_buf_ptr,
828
845
 
829
846
        log_sys->n_pending_archive_ios = 0;
830
847
 
831
 
        rw_lock_create(&log_sys->archive_lock, SYNC_NO_ORDER_CHECK);
 
848
        rw_lock_create(archive_lock_key, &log_sys->archive_lock,
 
849
                       SYNC_NO_ORDER_CHECK);
832
850
 
833
851
        log_sys->archive_buf = NULL;
834
852
 
1148
1166
        buf = *(group->file_header_bufs + nth_file);
1149
1167
 
1150
1168
        mach_write_to_4(buf + LOG_GROUP_ID, group->id);
1151
 
        mach_write_ull(buf + LOG_FILE_START_LSN, start_lsn);
 
1169
        mach_write_to_8(buf + LOG_FILE_START_LSN, start_lsn);
1152
1170
 
1153
1171
        /* Wipe over possible label of ibbackup --restore */
1154
1172
        memcpy(buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, "    ", 4);
1637
1655
                recv_apply_hashed_log_recs(TRUE);
1638
1656
        }
1639
1657
 
1640
 
        n_pages = buf_flush_batch(BUF_FLUSH_LIST, ULINT_MAX, new_oldest);
 
1658
        n_pages = buf_flush_list(ULINT_MAX, new_oldest);
1641
1659
 
1642
1660
        if (sync) {
1643
 
                buf_flush_wait_batch_end(BUF_FLUSH_LIST);
 
1661
                buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
1644
1662
        }
1645
1663
 
1646
1664
        if (n_pages == ULINT_UNDEFINED) {
1751
1769
 
1752
1770
        buf = group->checkpoint_buf;
1753
1771
 
1754
 
        mach_write_ull(buf + LOG_CHECKPOINT_NO, log_sys->next_checkpoint_no);
1755
 
        mach_write_ull(buf + LOG_CHECKPOINT_LSN, log_sys->next_checkpoint_lsn);
 
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);
1756
1774
 
1757
1775
        mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET,
1758
1776
                        log_group_calc_lsn_offset(
1772
1790
                }
1773
1791
        }
1774
1792
 
1775
 
        mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn);
 
1793
        mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn);
1776
1794
#else /* UNIV_LOG_ARCHIVE */
1777
 
        mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
 
1795
        mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1778
1796
#endif /* UNIV_LOG_ARCHIVE */
1779
1797
 
1780
1798
        for (i = 0; i < LOG_MAX_N_GROUPS; i++) {
1866
1884
        ib_uint64_t     lsn;
1867
1885
 
1868
1886
        mach_write_to_4(hdr_buf + LOG_GROUP_ID, 0);
1869
 
        mach_write_ull(hdr_buf + LOG_FILE_START_LSN, start);
 
1887
        mach_write_to_8(hdr_buf + LOG_FILE_START_LSN, start);
1870
1888
 
1871
1889
        lsn = start + LOG_BLOCK_HDR_SIZE;
1872
1890
 
1878
1896
                                + (sizeof "ibbackup ") - 1));
1879
1897
        buf = hdr_buf + LOG_CHECKPOINT_1;
1880
1898
 
1881
 
        mach_write_ull(buf + LOG_CHECKPOINT_NO, 0);
1882
 
        mach_write_ull(buf + LOG_CHECKPOINT_LSN, lsn);
 
1899
        mach_write_to_8(buf + LOG_CHECKPOINT_NO, 0);
 
1900
        mach_write_to_8(buf + LOG_CHECKPOINT_LSN, lsn);
1883
1901
 
1884
1902
        mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET,
1885
1903
                        LOG_FILE_HDR_SIZE + LOG_BLOCK_HDR_SIZE);
1886
1904
 
1887
1905
        mach_write_to_4(buf + LOG_CHECKPOINT_LOG_BUF_SIZE, 2 * 1024 * 1024);
1888
1906
 
1889
 
        mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
 
1907
        mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1890
1908
 
1891
1909
        fold = ut_fold_binary(buf, LOG_CHECKPOINT_CHECKSUM_1);
1892
1910
        mach_write_to_4(buf + LOG_CHECKPOINT_CHECKSUM_1, fold);
2254
2272
        buf = *(group->archive_file_header_bufs + nth_file);
2255
2273
 
2256
2274
        mach_write_to_4(buf + LOG_GROUP_ID, group->id);
2257
 
        mach_write_ull(buf + LOG_FILE_START_LSN, start_lsn);
 
2275
        mach_write_to_8(buf + LOG_FILE_START_LSN, start_lsn);
2258
2276
        mach_write_to_4(buf + LOG_FILE_NO, file_no);
2259
2277
 
2260
2278
        mach_write_to_4(buf + LOG_FILE_ARCH_COMPLETED, FALSE);
2290
2308
        buf = *(group->archive_file_header_bufs + nth_file);
2291
2309
 
2292
2310
        mach_write_to_4(buf + LOG_FILE_ARCH_COMPLETED, TRUE);
2293
 
        mach_write_ull(buf + LOG_FILE_END_LSN, end_lsn);
 
2311
        mach_write_to_8(buf + LOG_FILE_END_LSN, end_lsn);
2294
2312
 
2295
2313
        dest_offset = nth_file * group->file_size + LOG_FILE_ARCH_COMPLETED;
2296
2314
 
2354
2372
                log_archived_file_name_gen(name, group->id,
2355
2373
                                           group->archived_file_no + n_files);
2356
2374
 
2357
 
                file_handle = os_file_create(name, open_mode, OS_FILE_AIO,
 
2375
                file_handle = os_file_create(innodb_file_log_key,
 
2376
                                             name, open_mode,
 
2377
                                             OS_FILE_AIO,
2358
2378
                                             OS_DATA_FILE, &ret);
2359
2379
 
2360
2380
                if (!ret && (open_mode == OS_FILE_CREATE)) {
2361
2381
                        file_handle = os_file_create(
2362
 
                                name, OS_FILE_OPEN, OS_FILE_AIO,
2363
 
                                OS_DATA_FILE, &ret);
 
2382
                                innodb_file_log_key, name, OS_FILE_OPEN,
 
2383
                                OS_FILE_AIO, OS_DATA_FILE, &ret);
2364
2384
                }
2365
2385
 
2366
2386
                if (!ret) {
3078
3098
 
3079
3099
        if (srv_fast_shutdown < 2
3080
3100
           && (srv_error_monitor_active
3081
 
              || srv_lock_timeout_active || srv_monitor_active)) {
 
3101
              || srv_lock_timeout_active
 
3102
              || srv_monitor_active)) {
3082
3103
 
3083
3104
                mutex_exit(&kernel_mutex);
3084
3105
 
 
3106
                os_event_set(srv_error_event);
 
3107
                os_event_set(srv_monitor_event);
 
3108
                os_event_set(srv_timeout_event);
 
3109
 
3085
3110
                goto loop;
3086
3111
        }
3087
3112
 
3108
3133
 
3109
3134
                log_buffer_flush_to_disk();
3110
3135
 
 
3136
                mutex_exit(&kernel_mutex);
 
3137
 
3111
3138
                return; /* We SKIP ALL THE REST !! */
3112
3139
        }
3113
3140
 
3114
 
        /* Check that the master thread is suspended */
3115
 
 
3116
 
        if (srv_n_threads_active[SRV_MASTER] != 0) {
3117
 
 
3118
 
                mutex_exit(&kernel_mutex);
3119
 
 
 
3141
        mutex_exit(&kernel_mutex);
 
3142
 
 
3143
        /* Check that the background threads are suspended */
 
3144
 
 
3145
        if (srv_is_any_background_thread_active()) {
3120
3146
                goto loop;
3121
3147
        }
3122
3148
 
3123
 
        mutex_exit(&kernel_mutex);
3124
 
 
3125
3149
        mutex_enter(&(log_sys->mutex));
3126
3150
 
3127
3151
        if (log_sys->n_pending_checkpoint_writes
3179
3203
 
3180
3204
        mutex_exit(&(log_sys->mutex));
3181
3205
 
3182
 
        mutex_enter(&kernel_mutex);
3183
 
        /* Check that the master thread has stayed suspended */
3184
 
        if (srv_n_threads_active[SRV_MASTER] != 0) {
 
3206
        /* Check that the background threads stay suspended */
 
3207
        if (srv_is_any_background_thread_active()) {
3185
3208
                fprintf(stderr,
3186
 
                        "InnoDB: Warning: the master thread woke up"
 
3209
                        "InnoDB: Warning: some background thread woke up"
3187
3210
                        " during shutdown\n");
3188
3211
 
3189
 
                mutex_exit(&kernel_mutex);
3190
 
 
3191
3212
                goto loop;
3192
3213
        }
3193
 
        mutex_exit(&kernel_mutex);
3194
3214
 
3195
3215
        fil_flush_file_spaces(FIL_TABLESPACE);
3196
3216
        fil_flush_file_spaces(FIL_LOG);
3208
3228
        srv_shutdown_state = SRV_SHUTDOWN_LAST_PHASE;
3209
3229
 
3210
3230
        /* Make some checks that the server really is quiet */
3211
 
        ut_a(srv_n_threads_active[SRV_MASTER] == 0);
 
3231
        ut_a(!srv_is_any_background_thread_active());
 
3232
 
3212
3233
        ut_a(buf_all_freed());
3213
3234
        ut_a(lsn == log_sys->lsn);
3214
3235
 
3229
3250
        fil_close_all_files();
3230
3251
 
3231
3252
        /* Make some checks that the server really is quiet */
3232
 
        ut_a(srv_n_threads_active[SRV_MASTER] == 0);
 
3253
        ut_a(!srv_is_any_background_thread_active());
 
3254
 
3233
3255
        ut_a(buf_all_freed());
3234
3256
        ut_a(lsn == log_sys->lsn);
3235
3257
}
3270
3292
 
3271
3293
        ut_memcpy(scan_buf, start, end - start);
3272
3294
 
3273
 
        recv_scan_log_recs((buf_pool->curr_size
3274
 
                            - recv_n_pool_free_frames) * UNIV_PAGE_SIZE,
3275
 
                           FALSE, scan_buf, end - start,
 
3295
        recv_scan_log_recs((buf_pool_get_n_pages()
 
3296
                           - (recv_n_pool_free_frames * srv_buf_pool_instances))
 
3297
                           * UNIV_PAGE_SIZE, FALSE, scan_buf, end - start,
3276
3298
                           ut_uint64_align_down(buf_start_lsn,
3277
3299
                                                OS_FILE_LOG_BLOCK_SIZE),
3278
3300
                           &contiguous_lsn, &scanned_lsn);