~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to storage/innobase/buf/buf0flu.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
723
723
        return(0);
724
724
}
725
725
 
 
726
# if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
 
727
/**********************************************************************
 
728
Writes a flushable page asynchronously from the buffer pool to a file.
 
729
NOTE: buf_pool_mutex and block->mutex must be held upon entering this
 
730
function, and they will be released by this function after flushing.
 
731
This is loosely based on buf_flush_batch() and buf_flush_try_page(). */
 
732
 
 
733
ibool
 
734
buf_flush_page_try(
 
735
/*===============*/
 
736
                                        /* out: TRUE if flushed and
 
737
                                        mutexes released */
 
738
        buf_block_t*    block)          /*!< in/out: buffer control block */
 
739
{
 
740
        ut_ad(mutex_own(&buf_pool->mutex));
 
741
        ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
 
742
        ut_ad(mutex_own(&block->mutex));
 
743
 
 
744
        if (!buf_flush_ready_for_flush(block, BUF_FLUSH_LRU)) {
 
745
                return(FALSE);
 
746
        }
 
747
 
 
748
        if (buf_pool->n_flush[BUF_FLUSH_LRU] > 0
 
749
            || buf_pool->init_flush[BUF_FLUSH_LRU]) {
 
750
                /* There is already a flush batch of the same type running */
 
751
                return(FALSE);
 
752
        }
 
753
 
 
754
        buf_pool->init_flush[BUF_FLUSH_LRU] = TRUE;
 
755
 
 
756
        block->io_fix = BUF_IO_WRITE;
 
757
        block->flush_type = BUF_FLUSH_LRU;
 
758
 
 
759
        if (buf_pool->n_flush[BUF_FLUSH_LRU]++ == 0) {
 
760
 
 
761
                os_event_reset(buf_pool->no_flush[BUF_FLUSH_LRU]);
 
762
        }
 
763
 
 
764
        /* VERY IMPORTANT:
 
765
        Because any thread may call the LRU flush, even when owning
 
766
        locks on pages, to avoid deadlocks, we must make sure that the
 
767
        s-lock is acquired on the page without waiting: this is
 
768
        accomplished because buf_flush_ready_for_flush() must hold,
 
769
        and that requires the page not to be bufferfixed. */
 
770
 
 
771
        rw_lock_s_lock_gen(&block->lock, BUF_IO_WRITE);
 
772
 
 
773
        /* Note that the s-latch is acquired before releasing the
 
774
        buf_pool mutex: this ensures that the latch is acquired
 
775
        immediately. */
 
776
 
 
777
        mutex_exit(&block->mutex);
 
778
        mutex_exit(&buf_pool->mutex);
 
779
 
 
780
        /* Even though block is not protected by any mutex at this
 
781
        point, it is safe to access block, because it is io_fixed and
 
782
        oldest_modification != 0.  Thus, it cannot be relocated in the
 
783
        buffer pool or removed from flush_list or LRU_list. */
 
784
 
 
785
        buf_flush_write_block_low(block);
 
786
 
 
787
        mutex_enter(&buf_pool->mutex);
 
788
        buf_pool->init_flush[BUF_FLUSH_LRU] = FALSE;
 
789
 
 
790
        if (buf_pool->n_flush[BUF_FLUSH_LRU] == 0) {
 
791
                /* The running flush batch has ended */
 
792
                os_event_set(buf_pool->no_flush[BUF_FLUSH_LRU]);
 
793
        }
 
794
 
 
795
        mutex_exit(&buf_pool->mutex);
 
796
        buf_flush_buffered_writes();
 
797
 
 
798
        return(TRUE);
 
799
}
 
800
#endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
 
801
 
726
802
/***************************************************************
727
803
Flushes to disk all flushable pages within the flush area. */
728
804
static
841
917
{
842
918
        buf_block_t*    block;
843
919
        ulint           page_count      = 0;
844
 
        ulint           old_page_count;
845
920
        ulint           space;
846
921
        ulint           offset;
847
922
        ibool           found;
913
988
                                mutex_exit(&block->mutex);
914
989
                                mutex_exit(&(buf_pool->mutex));
915
990
 
916
 
                                old_page_count = page_count;
917
 
 
918
991
                                /* Try to flush also all the neighbors */
919
992
                                page_count += buf_flush_try_neighbors(
920
993
                                        space, offset, flush_type);
921
 
                                /* fprintf(stderr,
922
 
                                "Flush type %lu, page no %lu, neighb %lu\n",
923
 
                                flush_type, offset,
924
 
                                page_count - old_page_count); */
925
994
 
926
995
                                mutex_enter(&(buf_pool->mutex));
927
996