struct TABLE; /** Prepend the history list with an undo log. Removetheundologsegmentfromthersegslotifitistoobigforreuse. @param[in]trxtransaction @param[in,out]undoundolog @param[in,out]mtrmini-transaction
@param[in] end transaction serialisation number */ void
trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr,
trx_id_t end);
/** Runapurgebatch. @paramtrxdummytransactionassociatedwiththepurgecoordinator @paramn_tasksnumberofpurgetaskstosubmittothequeue @paramhistory_sizetrx_sys.history_size()
@return number of undo log pages handled in the batch */
ulint trx_purge(trx_t *trx, ulint n_tasks, ulint history_size) noexcept;
/** The control structure used in the purge operation */ class purge_sys_t
{ /** Min-heap based priority queue of (trx_no, trx_sys.rseg_array index) pairs,orderedontrx_no.Thehighest64-TRX_NO_SHIFTbitsofeachelementis
trx_no, the lowest 8 bits is rseg's index in trx_sys.rseg_array. */ class purge_queue
{ public: typedef std::vector<uint64_t, ut_allocator<uint64_t>> container_type; /** Number of bits reserved to shift trx_no in purge queue element */ static constexpr unsigned TRX_NO_SHIFT= 8;
public: /** latch protecting view, m_enabled */
alignas(CPU_LEVEL1_DCACHE_LINESIZE) mutable IF_DBUG(srw_lock_debug,srw_spin_lock) latch; private: /** Read view at the start of a purge batch. Any encountered index records
that are older than view will be removed. */
ReadViewBase view; /** whether the subsystem has been initialized */ bool m_initialized{false}; /** whether purge is enabled; protected by latch and std::atomic */
std::atomic<bool> m_enabled{false}; /** The primary candidate for iterator::free_history() is rseg=trx_sys.rseg_array[skipped_rseg].Thisfieldmaybechanged afterinvokingrseg.set_skip_allocation()andrseg.clear_skip_allocation() andwhileholdingtheexclusiverseg.latch.
Thismayonlybe0ifinnodb_undo_tablespaces=0,becauserollbacksegment 0alwaysresidesinthesystemtablespaceandwouldneverbeusedwhen
dedicated undo tablespaces are in use. */
Atomic_relaxed<uint8_t> skipped_rseg; public: /** whether purge is active (may hold table handles) */
std::atomic<bool> m_active{false}; private: /** number of pending stop() calls without resume() */
Atomic_counter<uint32_t> m_paused; /** PAUSED_SYS * number of stop_SYS() calls without resume_SYS() +
number of stop_FTS() calls without resume_FTS() */
Atomic_relaxed<uint32_t> m_FTS_paused; /** The stop_SYS() multiplier in m_FTS_paused */ static constexpr const uint32_t PAUSED_SYS= 1U << 16;
/** latch protecting end_view */
alignas(CPU_LEVEL1_DCACHE_LINESIZE) srw_spin_lock_low end_latch; /** Read view at the end of a purge batch (copied from view). Any undo pages
containing records older than end_view may be freed. */
ReadViewBase end_view;
using unordered_map =
std::unordered_map<const page_id_t, buf_block_t*, hasher, #ifdefined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ >= 8
std::equal_to<page_id_t> /* GCC 4.8.5 would fail to find a matching allocator */ #else
std::equal_to<page_id_t>,
ut_allocator<std::pair<const page_id_t, buf_block_t*>> #endif
>; /** map of buffer-fixed undo log pages processed during a purge batch */
unordered_map pages; public: /** @return the number of processed undo pages */
size_t n_pages_handled() const { return pages.size(); }
/** Look up an undo log page. @paramidundopageidentifier @paramtrxtransactionattachedtocurrent_thd @returnundopage
@retval nullptr in case the page is corrupted */
buf_block_t *get_page(page_id_t id, trx_t *trx);
que_t* query; /*!< The query graph which will do the
parallelized purge operation */
/** Iterator to the undo log records of committed transactions */ struct iterator
{ booloperator<=(const iterator& other) const
{ if (trx_no < other.trx_no) returntrue; if (trx_no > other.trx_no) returnfalse; return undo_no <= other.undo_no;
}
/** Remove unnecessary history data from a rollback segment. @paramrsegrollbacksegment
@return error code */ inline dberr_t free_history_rseg(trx_rseg_t &rseg) const;
/** Free the undo pages up to this. */
dberr_t free_history() const;
/** trx_t::no of the committed transaction */
trx_id_t trx_no; /** The record number within the committed transaction's undo
log, increasing, purged from from 0 onwards */
undo_no_t undo_no;
};
/** The tail of the purge queue; the last parsed undo log of a
committed transaction. */
iterator tail; /** The head of the purge queue; any older undo logs of committed transactionsmaybediscarded(historylisttruncation).
Protected by latch. */
iterator head; /*-----------------------------*/ bool next_stored; /*!< whether rseg holds the next record
to purge */
trx_rseg_t* rseg; /*!< Rollback segment for the next undo
record to purge */ private: /** Coordinator thread's THD during batch processing. Setbythecoordinatoratthestartoftrx_purge()andcleared attheend.Thisservestwopurposes: 1.Identifiesthecoordinatorthreadinreset_worker_thd() whichskipsTHDresetforthecoordinatorsinceitmanages cleanupcentrallyintrx_purge()afterallworkerscomplete.
2.UsedtosetTABLE::in_usewhenopeningtablesforpurge operationswithvirtualcolumns,ensuringpropertable
ownership tracking during the purge batch. */
THD *coordinator_thd= nullptr;
uint32_t page_no; /*!< Page number for the next undo recordtopurge,pagenumberofthe
log header, if dummy record */
uint32_t hdr_page_no; /*!< Header page of the undo log where
the next record to purge belongs */
uint16_t offset; /*!< Page offset for the next undo recordtopurge,0ifthedummy
record */
uint16_t hdr_offset; /*!< Header byte offset on the page */
/** Binary min-heap of (trx_no, trx_sys.rseg_array index) pairs, ordered on
trx_no. It is protected by the pq_mutex */
purge_queue purge_queue;
/** innodb_undo_log_truncate=ON state;
only modified by purge_coordinator_callback() */ struct { /** The undo tablespace that is currently being truncated */
Atomic_relaxed<fil_space_t*> current; /** The number of the undo tablespace that was last truncated,
relative from srv_undo_space_id_start */
uint32_t last;
} truncate_undo_space;
/** Create the instance */ void create();
/** Close the purge system on shutdown */ void close();
/** @return whether purge is enabled */ bool enabled() { return m_enabled.load(std::memory_order_relaxed); } /** @return whether the purge coordinator is paused */ bool paused()
{ return m_paused != 0; }
/** @return whether the purge tasks are active */ staticbool running();
/** Stop purge during FLUSH TABLES FOR EXPORT. */ void stop(); /** Resume purge at UNLOCK TABLES after FLUSH TABLES FOR EXPORT */ void resume();
/** Close and reopen all tables in case of a MDL conflict with DDL @paramidtableidentifierthattriggeredreopen @paramptlastpurge_tableentryprocessed @paramthdcoordinatorthread
@return purge_table for the reopened table, or empty on error */
purge_table close_and_reopen(table_id_t id, purge_table pt,
THD *thd) noexcept;
private: /** Suspend purge during a DDL operation on FULLTEXT INDEX tables */ void wait_FTS(bool also_sys); public: /** Suspend purge in data dictionary tables */ void stop_SYS()
{
ut_d(constauto p=) m_FTS_paused.fetch_add(PAUSED_SYS);
ut_ad(p < p + PAUSED_SYS);
} /** Resume purge in data dictionary tables */ staticvoid resume_SYS(void *);
/** Pause purge during a DDL operation that could drop FTS_ tables. */ void stop_FTS(); /** Resume purge after stop_FTS(). */ void resume_FTS()
{ ut_d(constauto p=) m_FTS_paused.fetch_sub(1); ut_ad(p & ~PAUSED_SYS); } /** @return whether stop_SYS() is in effect */ bool must_wait_FTS() const { return m_FTS_paused & ~PAUSED_SYS; } /** Reset coordinator thread back to table->in_use */ inlinevoid reset_in_use(TABLE *table) const noexcept;
private: /** Getthenextrecordtopurgeandupdatetheinfointhepurgesystem. @paramtrxtransactionattachedtocurrent_thd @paramroll_ptrundologpointertotherecord @returnbuffer-fixedreferencetoundologrecord @retval{nullptr,1}ifthewholeundologcanskippedinpurge
@retval {nullptr,0} if nothing is left, or on corruption */ inline trx_purge_rec_t get_next_rec(trx_t *trx, roll_ptr_t roll_ptr)
noexcept;
/** Choose the next undo log to purge. @paramtrxtransactionattachedtocurrent_thd
@return whether anything is to be purged */ bool choose_next_log(trx_t *trx) noexcept;
/** Update the last not yet purged history log info in rseg when wehavepurgedawholeundolog.Advancesalsopurge_trx_no pastthepurgedlog. @paramtrxtransactionattachedtocurrent_thd
@return whether anything is to be purged */ bool rseg_get_next_history_log(trx_t *trx) noexcept;
public: /** Fetchthenextundologrecordfromthehistorylisttopurge. @paramtrxtransactionattachedtocurrent_thd @returnbuffer-fixedreferencetoundologrecord @retval{nullptr,1}ifthewholeundologcanskippedinpurge
@retval {nullptr,0} if nothing is left, or on corruption */ inline trx_purge_rec_t fetch_next_rec(trx_t *trx) noexcept;
/** Determine if the history of a transaction is purgeable. @paramtrx_idtransactionidentifier
@return whether the history is purgeable */ bool is_purgeable(trx_id_t trx_id) const noexcept;
/** A wrapper around ReadView::low_limit_no(). */
trx_id_t low_limit_no() const
{ /* This function may only be called by purge_coordinator_callback().
Anyotherthreadsthataccesspurge_sys.viewmustholdpurge_sys.latch,
typically via purge_sys_t::view_guard. */ return view.low_limit_no();
} /** A wrapper around ReadView::sees(). */
trx_id_t sees(trx_id_t id) const
{ /* This function may only be called by purge_coordinator_callback().
Anyotherthreadsthataccesspurge_sys.viewmustholdpurge_sys.latch,
typically via purge_sys_t::view_guard. */ return view.sees(id);
}
private: /** Enable the use of a rollback segment and advance skipped_rseg, afteriterator::free_history_rseg()hadinvoked
rseg.set_skip_allocation(). */ inlinevoid rseg_enable(trx_rseg_t &rseg);
/** Try to start truncating a tablespace. @paramidundotablespaceidentifier @paramsizethemaximumdesiredundotablespacesize,inpages @returnundotablespacewhosetruncationwasstarted
@retval nullptr if truncation is not currently possible */ inline fil_space_t *undo_truncate_try(uint32_t id, uint32_t size); public: /** Check if innodb_undo_log_truncate=ON needs to be handled. Thisisonlytobecalledbypurge_coordinator_callback(). @returnundotablespacechosenbyinnodb_undo_log_truncate=ON
@retval nullptr if truncation is not currently possible */
fil_space_t *truncating_tablespace();
if (!also_end_view)
wait_FTS(true);
latch.wr_lock(SRW_LOCK_CALL);
trx_sys.clone_oldest_view(&view); if (also_end_view)
(end_view= view).
clamp_low_limit_id(head.trx_no ? head.trx_no : tail.trx_no);
latch.wr_unlock();
}
/** Wake up the purge threads if there is work to do. */ void wake_if_not_active();
/** Release undo pages and update end_view at the end of a purge batch. @retvalfalsewhennothingistobepurged
@retval true when purge_sys.rseg->latch was locked */ inlinevoid batch_cleanup(const iterator &head);
/** Stop the purge thread and check n_ref_count of all auxiliary andcommontableassociatedwiththeftstable. @paramtableparentFTStable @paramalready_stoppedTrueindicatespurgethreadswere
already stopped */ void stop_FTS(const dict_table_t &table, bool already_stopped=false);
/** Cleanse purge queue to remove the rseg that reside in undo-tablespace markedfortruncate.
@param space undo tablespace being truncated */ void cleanse_purge_queue(const fil_space_t &space);
/** Reset the state of a purge_worker_task at the end of a batch */ inlinevoid reset_worker_thd(THD *thd) const noexcept;
/** The global data structure coordinating a purge */ extern purge_sys_t purge_sys;
purge_sys_t::view_guard::view_guard(purge_sys_t::view_guard::guard latch) :
latch(latch)
{ switch (latch) { case VIEW:
purge_sys.latch.rd_lock(SRW_LOCK_CALL); break; case END_VIEW:
purge_sys.end_latch.rd_lock(); break; case PURGE: /* the access is within a purge batch; purge_coordinator_task
will wait for all workers to complete before updating the views */ break;
}
}
purge_sys_t::view_guard::~view_guard()
{ switch (latch) { case VIEW:
purge_sys.latch.rd_unlock(); break; case END_VIEW:
purge_sys.end_latch.rd_unlock(); break; case PURGE: break;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.