| 2018 | |
| 2019 | |
| 2020 | void CCH_release(thread_db* tdbb, WIN* window, const bool release_tail) |
| 2021 | { |
| 2022 | /************************************** |
| 2023 | * |
| 2024 | * C C H _ r e l e a s e |
| 2025 | * |
| 2026 | ************************************** |
| 2027 | * |
| 2028 | * Functional description |
| 2029 | * Release a window. If the release_tail |
| 2030 | * flag is true then make the buffer |
| 2031 | * least-recently-used. |
| 2032 | * |
| 2033 | **************************************/ |
| 2034 | SET_TDBB(tdbb); |
| 2035 | |
| 2036 | BufferDesc* const bdb = window->win_bdb; |
| 2037 | BLKCHK(bdb, type_bdb); |
| 2038 | |
| 2039 | BufferControl* bcb = bdb->bdb_bcb; |
| 2040 | |
| 2041 | CCH_TRACE(("RELEASE %d:%06d", window->win_page.getPageSpaceID(), window->win_page.getPageNum())); |
| 2042 | |
| 2043 | // A large sequential scan has requested that the garbage |
| 2044 | // collector garbage collect. Mark the buffer so that the |
| 2045 | // page isn't released to the LRU tail before the garbage |
| 2046 | // collector can process the page. |
| 2047 | |
| 2048 | if (window->win_flags & WIN_large_scan && window->win_flags & WIN_garbage_collect) |
| 2049 | { |
| 2050 | bdb->bdb_flags |= BDB_garbage_collect; |
| 2051 | window->win_flags &= ~WIN_garbage_collect; |
| 2052 | } |
| 2053 | |
| 2054 | const bool mustWrite = (bdb->bdb_flags & BDB_must_write) || |
| 2055 | bcb->bcb_database->dbb_backup_manager->databaseFlushInProgress(); |
| 2056 | |
| 2057 | if (bdb->bdb_writers == 1 || bdb->bdb_use_count == 1 || |
| 2058 | (bdb->bdb_writers == 0 && mustWrite)) |
| 2059 | { |
| 2060 | const bool marked = bdb->bdb_flags & BDB_marked; |
| 2061 | bdb->bdb_flags &= ~(BDB_writer | BDB_marked | BDB_faked); |
| 2062 | |
| 2063 | if (marked) |
| 2064 | bdb->unLockIO(tdbb); |
| 2065 | |
| 2066 | if (mustWrite) |
| 2067 | { |
| 2068 | // Downgrade exclusive latch to shared to allow concurrent share access |
| 2069 | // to page during I/O. |
| 2070 | |
| 2071 | bdb->downgrade(SYNC_SHARED); |
| 2072 | |
| 2073 | if (!write_buffer(tdbb, bdb, bdb->bdb_page, false, tdbb->tdbb_status_vector, true)) |
| 2074 | { |
| 2075 | insertDirty(bcb, bdb); |
| 2076 | CCH_unwind(tdbb, true); |
| 2077 | } |
no test coverage detected