diff options
Diffstat (limited to 'storage/innobase/include/buf0dblwr.h')
-rw-r--r-- | storage/innobase/include/buf0dblwr.h | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/storage/innobase/include/buf0dblwr.h b/storage/innobase/include/buf0dblwr.h index fb9df55504c..d9c9239c0b4 100644 --- a/storage/innobase/include/buf0dblwr.h +++ b/storage/innobase/include/buf0dblwr.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2020, MariaDB Corporation. +Copyright (c) 2017, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -54,9 +54,9 @@ class buf_dblwr_t }; /** the page number of the first doublewrite block (block_size() pages) */ - page_id_t block1= page_id_t(0, 0); + page_id_t block1{0, 0}; /** the page number of the second doublewrite block (block_size() pages) */ - page_id_t block2= page_id_t(0, 0); + page_id_t block2{0, 0}; /** mutex protecting the data members below */ mysql_mutex_t mutex; @@ -72,11 +72,15 @@ class buf_dblwr_t ulint writes_completed; /** number of pages written by flush_buffered_writes_completed() */ ulint pages_written; + /** condition variable for !writes_pending */ + pthread_cond_t write_cond; + /** number of pending page writes */ + size_t writes_pending; slot slots[2]; - slot *active_slot= &slots[0]; + slot *active_slot; - /** Initialize the doublewrite buffer data structure. + /** Initialise the persistent storage of the doublewrite buffer. @param header doublewrite page header in the TRX_SYS page */ inline void init(const byte *header); @@ -84,6 +88,8 @@ class buf_dblwr_t bool flush_buffered_writes(const ulint size); public: + /** Initialise the doublewrite buffer data structures. */ + void init(); /** Create or restore the doublewrite buffer in the TRX_SYS page. @return whether the operation succeeded */ bool create(); @@ -118,7 +124,7 @@ public: void recover(); /** Update the doublewrite buffer on data page write completion. */ - void write_completed(); + void write_completed(bool with_doublewrite); /** Flush possible buffered writes to persistent storage. It is very important to call this function after a batch of writes has been posted, and also when we may have to wait for a page latch! @@ -137,14 +143,14 @@ public: @param size payload size in bytes */ void add_to_batch(const IORequest &request, size_t size); - /** Determine whether the doublewrite buffer is initialized */ - bool is_initialised() const + /** Determine whether the doublewrite buffer has been created */ + bool is_created() const { return UNIV_LIKELY(block1 != page_id_t(0, 0)); } /** @return whether a page identifier is part of the doublewrite buffer */ bool is_inside(const page_id_t id) const { - if (!is_initialised()) + if (!is_created()) return false; ut_ad(block1 < block2); if (id < block1) @@ -156,13 +162,44 @@ public: /** Wait for flush_buffered_writes() to be fully completed */ void wait_flush_buffered_writes() { - if (is_initialised()) - { - mysql_mutex_lock(&mutex); - while (batch_running) - my_cond_wait(&cond, &mutex.m_mutex); - mysql_mutex_unlock(&mutex); - } + mysql_mutex_lock(&mutex); + while (batch_running) + my_cond_wait(&cond, &mutex.m_mutex); + mysql_mutex_unlock(&mutex); + } + + /** Register an unbuffered page write */ + void add_unbuffered() + { + mysql_mutex_lock(&mutex); + writes_pending++; + mysql_mutex_unlock(&mutex); + } + + size_t pending_writes() + { + mysql_mutex_lock(&mutex); + const size_t pending{writes_pending}; + mysql_mutex_unlock(&mutex); + return pending; + } + + /** Wait for writes_pending to reach 0 */ + void wait_for_page_writes() + { + mysql_mutex_lock(&mutex); + while (writes_pending) + my_cond_wait(&write_cond, &mutex.m_mutex); + mysql_mutex_unlock(&mutex); + } + + /** Wait for writes_pending to reach 0 */ + void wait_for_page_writes(const timespec &abstime) + { + mysql_mutex_lock(&mutex); + while (writes_pending) + my_cond_timedwait(&write_cond, &mutex.m_mutex, &abstime); + mysql_mutex_unlock(&mutex); } }; |