From b531d60e803a70e0ec7aee0156198051ac2d7b61 Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Wed, 19 Dec 2007 13:22:39 +0000 Subject: [PATCH] Backported fix for CORE-1657: AV with long inactive read-only read-commited transaction --- src/jrd/tpc.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/jrd/tpc.cpp b/src/jrd/tpc.cpp index 897a0dc1b8..5d55d9da26 100644 --- a/src/jrd/tpc.cpp +++ b/src/jrd/tpc.cpp @@ -391,16 +391,16 @@ static ULONG cache_transactions(thread_db* tdbb, TxPageCache** tip_cache_ptr, #ifdef SUPERSERVER_V2 const ULONG top = dbb->dbb_next_transaction; - oldest = MAX(oldest, dbb->dbb_oldest_transaction); + const ULONG hdr_oldest = dbb->dbb_oldest_transaction; #else WIN window(HEADER_PAGE); const Ods::header_page* header = (Ods::header_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_header); const ULONG top = header->hdr_next_transaction; const ULONG hdr_oldest = (ULONG) header->hdr_oldest_transaction; - oldest = MAX(oldest, hdr_oldest); CCH_RELEASE(tdbb, &window); #endif + oldest = MAX(oldest, hdr_oldest); /* allocate TxPageCache blocks to hold all transaction states -- assign one TxPageCache block per page to simplify cache maintenance */ @@ -421,11 +421,23 @@ static ULONG cache_transactions(thread_db* tdbb, TxPageCache** tip_cache_ptr, TRA_get_inventory(tdbb, NULL, oldest, top); -#ifdef SUPERSERVER_V2 - return dbb->dbb_oldest_transaction; -#else + // hvlad: cache_transactions returns number of oldest transaction + // just refreshed from header page. No need to cache TIP pages below it + // Moreover out tip cache can now contain an gap between last + // cached tip page and new pages if our process was idle for long time + + for (TxPageCache* tip_cache = dbb->dbb_tip_cache; + tip_cache && (tip_cache->tpc_base + trans_per_tip < hdr_oldest); + tip_cache = dbb->dbb_tip_cache) + { + dbb->dbb_tip_cache = tip_cache->tpc_next; + + // hvlad: commented out in 2.0 release branch, enabled and required + // additional testing in 2.1 + // delete tip_cache; + } + return hdr_oldest; -#endif } @@ -461,23 +473,6 @@ static int extend_cache(thread_db* tdbb, SLONG number) const ULONG oldest = cache_transactions(tdbb, tip_cache_ptr, tip_cache->tpc_base + trans_per_tip); - - // hvlad: cache_transactions returns number of oldest transaction - // just refreshed from header page. No need to cache TIP pages below it - // Moreover out tip cache can now contain an gap between last - // cached tip page and new pages if our process was idle for long time - - for (tip_cache = dbb->dbb_tip_cache; - tip_cache && (tip_cache->tpc_base + trans_per_tip < oldest); - tip_cache = dbb->dbb_tip_cache) - { - dbb->dbb_tip_cache = tip_cache->tpc_next; - - // hvlad: commented out in 2.0 release branch, enabled and required - // additional testing in 2.1 - // delete tip_cache; - } - if (number < oldest) return tra_committed;