@@ -94,7 +94,7 @@ typedef Firebird::GenericMap<Firebird::Pair<Firebird::NonPooled<USHORT, UCHAR> >
9494#ifdef SUPERSERVER_V2
9595static SLONG bump_transaction_id (thread_db*, WIN *);
9696#else
97- static header_page* bump_transaction_id (thread_db*, WIN *);
97+ static header_page* bump_transaction_id (thread_db*, WIN *, bool );
9898#endif
9999static Lock* create_transaction_lock (thread_db* tdbb, void * object);
100100static void retain_context (thread_db*, jrd_tra*, bool , SSHORT);
@@ -1571,16 +1571,28 @@ void TRA_set_state(thread_db* tdbb, jrd_tra* transaction, SLONG number, SSHORT s
15711571 WIN window (DB_PAGE_SPACE, -1 );
15721572 tx_inv_page* tip = fetch_inventory_page (tdbb, &window, (SLONG) sequence, LCK_write);
15731573
1574- #ifdef SUPERSERVER_V2
1575- CCH_MARK (tdbb, &window);
1574+ UCHAR* address = tip->tip_transactions + byte;
1575+ const int old_state = ((*address) >> shift) & TRA_MASK;
1576+
1577+ #if defined(SUPERSERVER_V2)
15761578 const ULONG generation = tip->pag_generation ;
1577- #else
1578- CCH_MARK_MUST_WRITE (tdbb, &window);
1579+ const bool mustWrite = false ;
1580+ #elif defined(SUPERSERVER)
1581+ const bool mustWrite =
1582+ (!transaction ||
1583+ (transaction->tra_flags & TRA_write) ||
1584+ old_state != tra_active || state != tra_committed);
1585+ #else // not SUPERSERVER
1586+ const bool mustWrite = true ;
15791587#endif
15801588
1589+ if (mustWrite)
1590+ CCH_MARK_MUST_WRITE (tdbb, &window);
1591+ else
1592+ CCH_MARK (tdbb, &window);
1593+
15811594 // set the state on the TIP page
15821595
1583- UCHAR* address = tip->tip_transactions + byte;
15841596 *address &= ~(TRA_MASK << shift);
15851597 *address |= state << shift;
15861598
@@ -2085,7 +2097,7 @@ static SLONG bump_transaction_id(thread_db* tdbb, WIN* window)
20852097#else
20862098
20872099
2088- static header_page* bump_transaction_id (thread_db* tdbb, WIN* window)
2100+ static header_page* bump_transaction_id (thread_db* tdbb, WIN* window, bool mustWrite )
20892101{
20902102/* *************************************
20912103 *
@@ -2133,7 +2145,11 @@ static header_page* bump_transaction_id(thread_db* tdbb, WIN* window)
21332145
21342146 // Extend, if necessary, has apparently succeeded. Next, update header page
21352147
2136- CCH_MARK_MUST_WRITE (tdbb, window);
2148+ if (mustWrite || new_tip)
2149+ CCH_MARK_MUST_WRITE (tdbb, window);
2150+ else
2151+ CCH_MARK (tdbb, window);
2152+
21372153 header->hdr_next_transaction = number;
21382154
21392155 if (dbb->dbb_oldest_active > header->hdr_oldest_active )
@@ -2674,7 +2690,13 @@ static void retain_context(thread_db* tdbb, jrd_tra* transaction, bool commit, S
26742690 new_number = dbb->dbb_next_transaction + dbb->generateTransactionId (tdbb);
26752691 else
26762692 {
2677- const header_page* header = bump_transaction_id (tdbb, &window);
2693+ const bool mustWrite =
2694+ #ifdef SUPERSERVER
2695+ !(transaction->tra_flags & TRA_readonly);
2696+ #else
2697+ true ;
2698+ #endif
2699+ const header_page* header = bump_transaction_id (tdbb, &window, mustWrite);
26782700 new_number = header->hdr_next_transaction ;
26792701 }
26802702#endif
@@ -3398,7 +3420,13 @@ static jrd_tra* transaction_start(thread_db* tdbb, jrd_tra* temp)
33983420 }
33993421 else
34003422 {
3401- const header_page* header = bump_transaction_id (tdbb, &window);
3423+ const bool mustWrite =
3424+ #ifdef SUPERSERVER
3425+ !(trans->tra_flags & TRA_readonly);
3426+ #else
3427+ true ;
3428+ #endif
3429+ const header_page* header = bump_transaction_id (tdbb, &window, mustWrite);
34023430 number = header->hdr_next_transaction ;
34033431 oldest = header->hdr_oldest_transaction ;
34043432 oldest_active = header->hdr_oldest_active ;
0 commit comments