~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/buf/buf0flu.cc

  • Committer: Barry.Leslie at PrimeBase
  • Date: 2011-01-22 03:22:44 UTC
  • mfrom: (2101 staging)
  • mto: (2228.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2230.
  • Revision ID: barry.leslie@primebase.com-20110122032244-ukbe3mlj7fs8xph6
Merged with lp:drizzle.

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.
 
3
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
131
131
/*============================*/
132
132
        buf_page_t*     bpage)  /*!< in: bpage to be removed. */
133
133
{
 
134
#ifdef UNIV_DEBUG
134
135
        ibool           ret = FALSE;
 
136
#endif /* UNIV_DEBUG */
135
137
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
136
138
 
137
139
        ut_ad(buf_flush_list_mutex_own(buf_pool));
138
140
 
139
 
        ret = rbt_delete(buf_pool->flush_rbt, &bpage);
 
141
#ifdef UNIV_DEBUG
 
142
        ret =
 
143
#endif /* UNIV_DEBUG */
 
144
        rbt_delete(buf_pool->flush_rbt, &bpage);
140
145
        ut_ad(ret);
141
146
}
142
147
 
324
329
 
325
330
        buf_flush_list_mutex_enter(buf_pool);
326
331
 
327
 
        /* The field in_LRU_list is protected by buf_pool_mutex, which
 
332
        /* The field in_LRU_list is protected by buf_pool->mutex, which
328
333
        we are not holding.  However, while a block is in the flush
329
334
        list, it is dirty and cannot be discarded, not from the
330
335
        page_hash or from the LRU list.  At most, the uncompressed
987
992
        ut_ad(page);
988
993
 
989
994
        if (page_zip_) {
990
 
                page_zip_des_t* page_zip = page_zip_;
 
995
                page_zip_des_t* page_zip = static_cast<page_zip_des_t *>(page_zip_);
991
996
                ulint           zip_size = page_zip_get_size(page_zip);
992
997
                ut_ad(zip_size);
993
998
                ut_ad(ut_is_2pow(zip_size));
1076
1081
 
1077
1082
        ut_ad(buf_page_in_file(bpage));
1078
1083
 
1079
 
        /* We are not holding buf_pool_mutex or block_mutex here.
 
1084
        /* We are not holding buf_pool->mutex or block_mutex here.
1080
1085
        Nevertheless, it is safe to access bpage, because it is
1081
1086
        io_fixed and oldest_modification != 0.  Thus, it cannot be
1082
1087
        relocated in the buffer pool or removed from flush_list or
1147
1152
        }
1148
1153
}
1149
1154
 
 
1155
# if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
 
1156
/********************************************************************//**
 
1157
Writes a flushable page asynchronously from the buffer pool to a file.
 
1158
NOTE: buf_pool->mutex and block->mutex must be held upon entering this
 
1159
function, and they will be released by this function after flushing.
 
1160
This is loosely based on buf_flush_batch() and buf_flush_page().
 
1161
@return TRUE if the page was flushed and the mutexes released */
 
1162
UNIV_INTERN
 
1163
ibool
 
1164
buf_flush_page_try(
 
1165
/*===============*/
 
1166
        buf_pool_t*     buf_pool,       /*!< in/out: buffer pool instance */
 
1167
        buf_block_t*    block)          /*!< in/out: buffer control block */
 
1168
{
 
1169
        ut_ad(buf_pool_mutex_own(buf_pool));
 
1170
        ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
 
1171
        ut_ad(mutex_own(&block->mutex));
 
1172
 
 
1173
        if (!buf_flush_ready_for_flush(&block->page, BUF_FLUSH_LRU)) {
 
1174
                return(FALSE);
 
1175
        }
 
1176
 
 
1177
        if (buf_pool->n_flush[BUF_FLUSH_LRU] > 0
 
1178
            || buf_pool->init_flush[BUF_FLUSH_LRU]) {
 
1179
                /* There is already a flush batch of the same type running */
 
1180
                return(FALSE);
 
1181
        }
 
1182
 
 
1183
        buf_pool->init_flush[BUF_FLUSH_LRU] = TRUE;
 
1184
 
 
1185
        buf_page_set_io_fix(&block->page, BUF_IO_WRITE);
 
1186
 
 
1187
        buf_page_set_flush_type(&block->page, BUF_FLUSH_LRU);
 
1188
 
 
1189
        if (buf_pool->n_flush[BUF_FLUSH_LRU]++ == 0) {
 
1190
 
 
1191
                os_event_reset(buf_pool->no_flush[BUF_FLUSH_LRU]);
 
1192
        }
 
1193
 
 
1194
        /* VERY IMPORTANT:
 
1195
        Because any thread may call the LRU flush, even when owning
 
1196
        locks on pages, to avoid deadlocks, we must make sure that the
 
1197
        s-lock is acquired on the page without waiting: this is
 
1198
        accomplished because buf_flush_ready_for_flush() must hold,
 
1199
        and that requires the page not to be bufferfixed. */
 
1200
 
 
1201
        rw_lock_s_lock_gen(&block->lock, BUF_IO_WRITE);
 
1202
 
 
1203
        /* Note that the s-latch is acquired before releasing the
 
1204
        buf_pool mutex: this ensures that the latch is acquired
 
1205
        immediately. */
 
1206
 
 
1207
        mutex_exit(&block->mutex);
 
1208
        buf_pool_mutex_exit(buf_pool);
 
1209
 
 
1210
        /* Even though block is not protected by any mutex at this
 
1211
        point, it is safe to access block, because it is io_fixed and
 
1212
        oldest_modification != 0.  Thus, it cannot be relocated in the
 
1213
        buffer pool or removed from flush_list or LRU_list. */
 
1214
 
 
1215
        buf_flush_write_block_low(&block->page);
 
1216
 
 
1217
        buf_pool_mutex_enter(buf_pool);
 
1218
        buf_pool->init_flush[BUF_FLUSH_LRU] = FALSE;
 
1219
 
 
1220
        if (buf_pool->n_flush[BUF_FLUSH_LRU] == 0) {
 
1221
                /* The running flush batch has ended */
 
1222
                os_event_set(buf_pool->no_flush[BUF_FLUSH_LRU]);
 
1223
        }
 
1224
 
 
1225
        buf_pool_mutex_exit(buf_pool);
 
1226
        buf_flush_buffered_writes();
 
1227
 
 
1228
        return(TRUE);
 
1229
}
 
1230
# endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
 
1231
 
1150
1232
/********************************************************************//**
1151
1233
Writes a flushable page asynchronously from the buffer pool to a file.
1152
1234
NOTE: in simulated aio we must call
1763
1845
                ulint   i;
1764
1846
 
1765
1847
                for (i = 0; i < srv_buf_pool_instances; ++i) {
1766
 
                        buf_pool_t*     buf_pool;
1767
 
 
1768
 
                        buf_pool = buf_pool_from_array(i);
1769
 
 
1770
 
                        os_event_wait(buf_pool->no_flush[type]);
 
1848
                        buf_pool_t*     i_buf_pool = buf_pool_from_array(i);
 
1849
 
 
1850
                        os_event_wait(i_buf_pool->no_flush[type]);
1771
1851
                }
1772
1852
        } else {
1773
1853
                os_event_wait(buf_pool->no_flush[type]);
2127
2207
 
2128
2208
                ut_ad(bpage->in_flush_list);
2129
2209
 
2130
 
                /* A page in flush_list can be in BUF_BLOCK_REMOVE_HASH
2131
 
                state. This happens when a page is in the middle of
2132
 
                being relocated. In that case the original descriptor
2133
 
                can have this state and still be in the flush list
2134
 
                waiting to acquire the flush_list_mutex to complete
2135
 
                the relocation. */
 
2210
                /* A page in buf_pool->flush_list can be in
 
2211
                BUF_BLOCK_REMOVE_HASH state. This happens when a page
 
2212
                is in the middle of being relocated. In that case the
 
2213
                original descriptor can have this state and still be
 
2214
                in the flush list waiting to acquire the
 
2215
                buf_pool->flush_list_mutex to complete the relocation. */
2136
2216
                ut_a(buf_page_in_file(bpage)
2137
2217
                     || buf_page_get_state(bpage) == BUF_BLOCK_REMOVE_HASH);
2138
2218
                ut_a(om > 0);