~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Stewart Smith
  • Date: 2010-11-07 04:22:31 UTC
  • mto: (1911.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: stewart@flamingspork.com-20101107042231-ola4sl7j0qvg58tz
fix ARCHIVE storage engine calling exit (lintian warning). Was because we were linking in libinternal into libazio, which links into archive plugin. Just link libinternal into the command line utilities.

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, 2009, Innobase Oy. All Rights Reserved.
 
4
 
 
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.
 
8
 
 
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.
 
12
 
 
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
 
16
 
 
17
*****************************************************************************/
 
18
/*****************************************************************************
 
19
 
 
20
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
21
Copyright (c) 2009, Google Inc.
5
22
 
6
23
Portions of this file contain modifications contributed and copyrighted by
7
24
Google, Inc. Those modifications are gratefully acknowledged and are described
49
66
#include "trx0sys.h"
50
67
#include "trx0trx.h"
51
68
 
52
 
#include <drizzled/errmsg_print.h>
53
 
 
54
69
/*
55
70
General philosophy of InnoDB redo-logs:
56
71
 
84
99
/* Global log system variable */
85
100
UNIV_INTERN log_t*      log_sys = NULL;
86
101
 
87
 
#ifdef UNIV_PFS_RWLOCK
88
 
UNIV_INTERN mysql_pfs_key_t     checkpoint_lock_key;
89
 
# ifdef UNIV_LOG_ARCHIVE
90
 
UNIV_INTERN mysql_pfs_key_t     archive_lock_key;
91
 
# endif
92
 
#endif /* UNIV_PFS_RWLOCK */
93
 
 
94
 
#ifdef UNIV_PFS_MUTEX
95
 
UNIV_INTERN mysql_pfs_key_t     log_sys_mutex_key;
96
 
UNIV_INTERN mysql_pfs_key_t     log_flush_order_mutex_key;
97
 
#endif /* UNIV_PFS_MUTEX */
98
 
 
99
102
#ifdef UNIV_DEBUG
100
103
UNIV_INTERN ibool       log_do_write = TRUE;
101
104
#endif /* UNIV_DEBUG */
330
333
        str_len -= len;
331
334
        str = str + len;
332
335
 
333
 
        log_block = static_cast<unsigned char *>(ut_align_down(log->buf + log->buf_free,
334
 
                                OS_FILE_LOG_BLOCK_SIZE));
 
336
        log_block = ut_align_down(log->buf + log->buf_free,
 
337
                                  OS_FILE_LOG_BLOCK_SIZE);
335
338
        log_block_set_data_len(log_block, data_len);
336
339
 
337
340
        if (data_len == OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE) {
380
383
 
381
384
        lsn = log->lsn;
382
385
 
383
 
        log_block = static_cast<unsigned char *>(ut_align_down(log->buf + log->buf_free,
384
 
                                OS_FILE_LOG_BLOCK_SIZE));
 
386
        log_block = ut_align_down(log->buf + log->buf_free,
 
387
                                  OS_FILE_LOG_BLOCK_SIZE);
385
388
        first_rec_group = log_block_get_first_rec_group(log_block);
386
389
 
387
390
        if (first_rec_group == 0) {
768
771
log_init(void)
769
772
/*==========*/
770
773
{
771
 
        log_sys = static_cast<log_t *>(mem_alloc(sizeof(log_t)));
772
 
 
773
 
        mutex_create(log_sys_mutex_key, &log_sys->mutex, SYNC_LOG);
774
 
 
775
 
        mutex_create(log_flush_order_mutex_key,
776
 
                     &log_sys->log_flush_order_mutex,
777
 
                     SYNC_LOG_FLUSH_ORDER);
 
774
        log_sys = mem_alloc(sizeof(log_t));
 
775
 
 
776
        mutex_create(&log_sys->mutex, SYNC_LOG);
778
777
 
779
778
        mutex_enter(&(log_sys->mutex));
780
779
 
786
785
        ut_a(LOG_BUFFER_SIZE >= 16 * OS_FILE_LOG_BLOCK_SIZE);
787
786
        ut_a(LOG_BUFFER_SIZE >= 4 * UNIV_PAGE_SIZE);
788
787
 
789
 
        log_sys->buf_ptr = static_cast<unsigned char *>(mem_alloc(LOG_BUFFER_SIZE + OS_FILE_LOG_BLOCK_SIZE));
790
 
        log_sys->buf = static_cast<unsigned char *>(ut_align(log_sys->buf_ptr, OS_FILE_LOG_BLOCK_SIZE));
 
788
        log_sys->buf_ptr = mem_alloc(LOG_BUFFER_SIZE + OS_FILE_LOG_BLOCK_SIZE);
 
789
        log_sys->buf = ut_align(log_sys->buf_ptr, OS_FILE_LOG_BLOCK_SIZE);
791
790
 
792
791
        log_sys->buf_size = LOG_BUFFER_SIZE;
793
792
 
830
829
        log_sys->last_checkpoint_lsn = log_sys->lsn;
831
830
        log_sys->n_pending_checkpoint_writes = 0;
832
831
 
833
 
        rw_lock_create(checkpoint_lock_key, &log_sys->checkpoint_lock,
834
 
                       SYNC_NO_ORDER_CHECK);
 
832
        rw_lock_create(&log_sys->checkpoint_lock, SYNC_NO_ORDER_CHECK);
835
833
 
836
 
        log_sys->checkpoint_buf_ptr = static_cast<unsigned char *>(mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE));
837
 
        log_sys->checkpoint_buf = static_cast<unsigned char *>(ut_align(log_sys->checkpoint_buf_ptr,
838
 
                                OS_FILE_LOG_BLOCK_SIZE));
 
834
        log_sys->checkpoint_buf_ptr = mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE);
 
835
        log_sys->checkpoint_buf = ut_align(log_sys->checkpoint_buf_ptr,
 
836
                                           OS_FILE_LOG_BLOCK_SIZE);
839
837
        memset(log_sys->checkpoint_buf, '\0', OS_FILE_LOG_BLOCK_SIZE);
840
838
        /*----------------------------*/
841
839
 
847
845
 
848
846
        log_sys->n_pending_archive_ios = 0;
849
847
 
850
 
        rw_lock_create(archive_lock_key, &log_sys->archive_lock,
851
 
                       SYNC_NO_ORDER_CHECK);
 
848
        rw_lock_create(&log_sys->archive_lock, SYNC_NO_ORDER_CHECK);
852
849
 
853
850
        log_sys->archive_buf = NULL;
854
851
 
897
894
        ulint   space_id,               /*!< in: space id of the file space
898
895
                                        which contains the log files of this
899
896
                                        group */
900
 
        ulint   /*archive_space_id __attribute__((unused))*/)
 
897
        ulint   archive_space_id __attribute__((unused)))
901
898
                                        /*!< in: space id of the file space
902
899
                                        which contains some archived log
903
900
                                        files for this group; currently, only
908
905
 
909
906
        log_group_t*    group;
910
907
 
911
 
        group = static_cast<log_group_t *>(mem_alloc(sizeof(log_group_t)));
 
908
        group = mem_alloc(sizeof(log_group_t));
912
909
 
913
910
        group->id = id;
914
911
        group->n_files = n_files;
919
916
        group->lsn_offset = LOG_FILE_HDR_SIZE;
920
917
        group->n_pending_writes = 0;
921
918
 
922
 
        group->file_header_bufs_ptr = static_cast<unsigned char **>(mem_alloc(sizeof(byte*) * n_files));
923
 
        group->file_header_bufs = static_cast<unsigned char **>(mem_alloc(sizeof(byte*) * n_files));
 
919
        group->file_header_bufs_ptr = mem_alloc(sizeof(byte*) * n_files);
 
920
        group->file_header_bufs = mem_alloc(sizeof(byte*) * n_files);
924
921
#ifdef UNIV_LOG_ARCHIVE
925
922
        group->archive_file_header_bufs_ptr = mem_alloc(
926
923
                sizeof(byte*) * n_files);
928
925
#endif /* UNIV_LOG_ARCHIVE */
929
926
 
930
927
        for (i = 0; i < n_files; i++) {
931
 
                group->file_header_bufs_ptr[i] = static_cast<unsigned char *>(mem_alloc(
932
 
                        LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE));
 
928
                group->file_header_bufs_ptr[i] = mem_alloc(
 
929
                        LOG_FILE_HDR_SIZE + OS_FILE_LOG_BLOCK_SIZE);
933
930
 
934
 
                group->file_header_bufs[i] = static_cast<unsigned char *>(ut_align(
 
931
                group->file_header_bufs[i] = ut_align(
935
932
                        group->file_header_bufs_ptr[i],
936
 
                        OS_FILE_LOG_BLOCK_SIZE));
 
933
                        OS_FILE_LOG_BLOCK_SIZE);
937
934
 
938
935
                memset(*(group->file_header_bufs + i), '\0',
939
936
                       LOG_FILE_HDR_SIZE);
958
955
        group->archived_offset = 0;
959
956
#endif /* UNIV_LOG_ARCHIVE */
960
957
 
961
 
        group->checkpoint_buf_ptr = static_cast<unsigned char *>(mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE));
962
 
        group->checkpoint_buf = static_cast<unsigned char*>(ut_align(group->checkpoint_buf_ptr,
963
 
                                         OS_FILE_LOG_BLOCK_SIZE));
 
958
        group->checkpoint_buf_ptr = mem_alloc(2 * OS_FILE_LOG_BLOCK_SIZE);
 
959
        group->checkpoint_buf = ut_align(group->checkpoint_buf_ptr,
 
960
                                         OS_FILE_LOG_BLOCK_SIZE);
964
961
 
965
962
        memset(group->checkpoint_buf, '\0', OS_FILE_LOG_BLOCK_SIZE);
966
963
 
1168
1165
        buf = *(group->file_header_bufs + nth_file);
1169
1166
 
1170
1167
        mach_write_to_4(buf + LOG_GROUP_ID, group->id);
1171
 
        mach_write_to_8(buf + LOG_FILE_START_LSN, start_lsn);
 
1168
        mach_write_ull(buf + LOG_FILE_START_LSN, start_lsn);
1172
1169
 
1173
1170
        /* Wipe over possible label of ibbackup --restore */
1174
1171
        memcpy(buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, "    ", 4);
1657
1654
                recv_apply_hashed_log_recs(TRUE);
1658
1655
        }
1659
1656
 
1660
 
        n_pages = buf_flush_list(ULINT_MAX, new_oldest);
 
1657
        n_pages = buf_flush_batch(BUF_FLUSH_LIST, ULINT_MAX, new_oldest);
1661
1658
 
1662
1659
        if (sync) {
1663
 
                buf_flush_wait_batch_end(NULL, BUF_FLUSH_LIST);
 
1660
                buf_flush_wait_batch_end(BUF_FLUSH_LIST);
1664
1661
        }
1665
1662
 
1666
1663
        if (n_pages == ULINT_UNDEFINED) {
1771
1768
 
1772
1769
        buf = group->checkpoint_buf;
1773
1770
 
1774
 
        mach_write_to_8(buf + LOG_CHECKPOINT_NO, log_sys->next_checkpoint_no);
1775
 
        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);
1776
1773
 
1777
1774
        mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET,
1778
1775
                        log_group_calc_lsn_offset(
1792
1789
                }
1793
1790
        }
1794
1791
 
1795
 
        mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn);
 
1792
        mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, archived_lsn);
1796
1793
#else /* UNIV_LOG_ARCHIVE */
1797
 
        mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
 
1794
        mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1798
1795
#endif /* UNIV_LOG_ARCHIVE */
1799
1796
 
1800
1797
        for (i = 0; i < LOG_MAX_N_GROUPS; i++) {
1886
1883
        ib_uint64_t     lsn;
1887
1884
 
1888
1885
        mach_write_to_4(hdr_buf + LOG_GROUP_ID, 0);
1889
 
        mach_write_to_8(hdr_buf + LOG_FILE_START_LSN, start);
 
1886
        mach_write_ull(hdr_buf + LOG_FILE_START_LSN, start);
1890
1887
 
1891
1888
        lsn = start + LOG_BLOCK_HDR_SIZE;
1892
1889
 
1898
1895
                                + (sizeof "ibbackup ") - 1));
1899
1896
        buf = hdr_buf + LOG_CHECKPOINT_1;
1900
1897
 
1901
 
        mach_write_to_8(buf + LOG_CHECKPOINT_NO, 0);
1902
 
        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);
1903
1900
 
1904
1901
        mach_write_to_4(buf + LOG_CHECKPOINT_OFFSET,
1905
1902
                        LOG_FILE_HDR_SIZE + LOG_BLOCK_HDR_SIZE);
1906
1903
 
1907
1904
        mach_write_to_4(buf + LOG_CHECKPOINT_LOG_BUF_SIZE, 2 * 1024 * 1024);
1908
1905
 
1909
 
        mach_write_to_8(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
 
1906
        mach_write_ull(buf + LOG_CHECKPOINT_ARCHIVED_LSN, IB_ULONGLONG_MAX);
1910
1907
 
1911
1908
        fold = ut_fold_binary(buf, LOG_CHECKPOINT_CHECKSUM_1);
1912
1909
        mach_write_to_4(buf + LOG_CHECKPOINT_CHECKSUM_1, fold);
2016
2013
                return(TRUE);
2017
2014
        }
2018
2015
 
2019
 
        ut_ad(log_sys->flushed_to_disk_lsn >= oldest_lsn);
 
2016
        ut_ad(log_sys->written_to_all_lsn >= oldest_lsn);
2020
2017
 
2021
2018
        if (log_sys->n_pending_checkpoint_writes > 0) {
2022
2019
                /* A checkpoint write is running */
2074
2071
{
2075
2072
        /* Preflush pages synchronously */
2076
2073
 
2077
 
        while (!log_preflush_pool_modified_pages(lsn, TRUE)) {}
 
2074
        while (!log_preflush_pool_modified_pages(lsn, TRUE));
2078
2075
 
2079
 
        while (!log_checkpoint(TRUE, write_always)) {}
 
2076
        while (!log_checkpoint(TRUE, write_always));
2080
2077
}
2081
2078
 
2082
2079
/****************************************************************//**
2243
2240
log_archived_file_name_gen(
2244
2241
/*=======================*/
2245
2242
        char*   buf,    /*!< in: buffer where to write */
2246
 
        ulint   /*id __attribute__((unused))*/,
 
2243
        ulint   id __attribute__((unused)),
2247
2244
                        /*!< in: group id;
2248
2245
                        currently we only archive the first group */
2249
2246
        ulint   file_no)/*!< in: file number */
2274
2271
        buf = *(group->archive_file_header_bufs + nth_file);
2275
2272
 
2276
2273
        mach_write_to_4(buf + LOG_GROUP_ID, group->id);
2277
 
        mach_write_to_8(buf + LOG_FILE_START_LSN, start_lsn);
 
2274
        mach_write_ull(buf + LOG_FILE_START_LSN, start_lsn);
2278
2275
        mach_write_to_4(buf + LOG_FILE_NO, file_no);
2279
2276
 
2280
2277
        mach_write_to_4(buf + LOG_FILE_ARCH_COMPLETED, FALSE);
2310
2307
        buf = *(group->archive_file_header_bufs + nth_file);
2311
2308
 
2312
2309
        mach_write_to_4(buf + LOG_FILE_ARCH_COMPLETED, TRUE);
2313
 
        mach_write_to_8(buf + LOG_FILE_END_LSN, end_lsn);
 
2310
        mach_write_ull(buf + LOG_FILE_END_LSN, end_lsn);
2314
2311
 
2315
2312
        dest_offset = nth_file * group->file_size + LOG_FILE_ARCH_COMPLETED;
2316
2313
 
2374
2371
                log_archived_file_name_gen(name, group->id,
2375
2372
                                           group->archived_file_no + n_files);
2376
2373
 
2377
 
                file_handle = os_file_create(innodb_file_log_key,
2378
 
                                             name, open_mode,
2379
 
                                             OS_FILE_AIO,
 
2374
                file_handle = os_file_create(name, open_mode, OS_FILE_AIO,
2380
2375
                                             OS_DATA_FILE, &ret);
2381
2376
 
2382
2377
                if (!ret && (open_mode == OS_FILE_CREATE)) {
2383
2378
                        file_handle = os_file_create(
2384
 
                                innodb_file_log_key, name, OS_FILE_OPEN,
2385
 
                                OS_FILE_AIO, OS_DATA_FILE, &ret);
 
2379
                                name, OS_FILE_OPEN, OS_FILE_AIO,
 
2380
                                OS_DATA_FILE, &ret);
2386
2381
                }
2387
2382
 
2388
2383
                if (!ret) {
3100
3095
 
3101
3096
        if (srv_fast_shutdown < 2
3102
3097
           && (srv_error_monitor_active
3103
 
              || srv_lock_timeout_active
3104
 
              || srv_monitor_active)) {
 
3098
              || srv_lock_timeout_and_monitor_active)) {
3105
3099
 
3106
3100
                mutex_exit(&kernel_mutex);
3107
3101
 
3108
 
                os_event_set(srv_error_event);
3109
 
                os_event_set(srv_monitor_event);
3110
 
                os_event_set(srv_timeout_event);
3111
 
 
3112
3102
                goto loop;
3113
3103
        }
3114
3104
 
3135
3125
 
3136
3126
                log_buffer_flush_to_disk();
3137
3127
 
3138
 
                mutex_exit(&kernel_mutex);
3139
 
 
3140
3128
                return; /* We SKIP ALL THE REST !! */
3141
3129
        }
3142
3130
 
 
3131
        /* Check that the master thread is suspended */
 
3132
 
 
3133
        if (srv_n_threads_active[SRV_MASTER] != 0) {
 
3134
 
 
3135
                mutex_exit(&kernel_mutex);
 
3136
 
 
3137
                goto loop;
 
3138
        }
 
3139
 
3143
3140
        mutex_exit(&kernel_mutex);
3144
3141
 
3145
 
        /* Check that the background threads are suspended */
3146
 
 
3147
 
        if (srv_is_any_background_thread_active()) {
3148
 
                goto loop;
3149
 
        }
3150
 
 
3151
3142
        mutex_enter(&(log_sys->mutex));
3152
3143
 
3153
3144
        if (log_sys->n_pending_checkpoint_writes
3205
3196
 
3206
3197
        mutex_exit(&(log_sys->mutex));
3207
3198
 
3208
 
        /* Check that the background threads stay suspended */
3209
 
        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) {
3210
3202
                fprintf(stderr,
3211
 
                        "InnoDB: Warning: some background thread woke up"
 
3203
                        "InnoDB: Warning: the master thread woke up"
3212
3204
                        " during shutdown\n");
3213
3205
 
 
3206
                mutex_exit(&kernel_mutex);
 
3207
 
3214
3208
                goto loop;
3215
3209
        }
 
3210
        mutex_exit(&kernel_mutex);
3216
3211
 
3217
3212
        fil_flush_file_spaces(FIL_TABLESPACE);
3218
3213
        fil_flush_file_spaces(FIL_LOG);
3230
3225
        srv_shutdown_state = SRV_SHUTDOWN_LAST_PHASE;
3231
3226
 
3232
3227
        /* Make some checks that the server really is quiet */
3233
 
        ut_a(!srv_is_any_background_thread_active());
3234
 
 
 
3228
        ut_a(srv_n_threads_active[SRV_MASTER] == 0);
3235
3229
        ut_a(buf_all_freed());
3236
3230
        ut_a(lsn == log_sys->lsn);
3237
3231
 
3238
3232
        if (lsn < srv_start_lsn) {
3239
 
          drizzled::errmsg_printf(drizzled::error::ERROR,
3240
 
                                  "InnoDB: Error: log sequence number at shutdown %"PRIu64" is lower than at startup %"PRIu64"!",
3241
 
                                  lsn, srv_start_lsn);
 
3233
                fprintf(stderr,
 
3234
                        "InnoDB: Error: log sequence number"
 
3235
                        " at shutdown %"PRIu64"\n"
 
3236
                        "InnoDB: is lower than at startup %"PRIu64"!\n",
 
3237
                        lsn, srv_start_lsn);
3242
3238
        }
3243
3239
 
3244
3240
        srv_shutdown_lsn = lsn;
3250
3246
        fil_close_all_files();
3251
3247
 
3252
3248
        /* Make some checks that the server really is quiet */
3253
 
        ut_a(!srv_is_any_background_thread_active());
3254
 
 
 
3249
        ut_a(srv_n_threads_active[SRV_MASTER] == 0);
3255
3250
        ut_a(buf_all_freed());
3256
3251
        ut_a(lsn == log_sys->lsn);
3257
3252
}
3292
3287
 
3293
3288
        ut_memcpy(scan_buf, start, end - start);
3294
3289
 
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,
 
3290
        recv_scan_log_recs((buf_pool->curr_size
 
3291
                            - recv_n_pool_free_frames) * UNIV_PAGE_SIZE,
 
3292
                           FALSE, scan_buf, end - start,
3298
3293
                           ut_uint64_align_down(buf_start_lsn,
3299
3294
                                                OS_FILE_LOG_BLOCK_SIZE),
3300
3295
                           &contiguous_lsn, &scanned_lsn);