MCPcopy Create free account
hub / github.com/MariaDB/server / binlog_flush_cache

Function binlog_flush_cache

sql/log.cc:2112–2239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2110 */
2111
2112static int
2113binlog_flush_cache(THD *thd, binlog_cache_mngr *cache_mngr,
2114 Log_event *end_ev, bool all, bool using_stmt,
2115 bool using_trx, bool is_ro_1pc= false)
2116{
2117 int error= 0;
2118 DBUG_ENTER("binlog_flush_cache");
2119 DBUG_PRINT("enter", ("end_ev: %p", end_ev));
2120
2121 bool doing_stmt= using_stmt && !cache_mngr->stmt_cache.empty();
2122 bool doing_trx= using_trx && !cache_mngr->trx_cache.empty();
2123 if (doing_stmt || doing_trx || thd->transaction->xid_state.is_explicit_XA())
2124 {
2125 /*
2126 thd->binlog_flush_pending_rows_event() ensures that the pending row event
2127 is flushed into the respective IO cache. We also need to make sure that
2128 the IO cache is consistent where its data is stored, i.e. it should
2129 either be entirely in-memory or backed by a temporary file. So if
2130 necessary (i.e if the cache data exceeds its binlog_cache_size), flush
2131 the IO cache to its tmp file on disk.
2132
2133 Technically, this reconciliation would happen automatically when writing
2134 the cache data to the actual binlog file. We pre-empt it though because:
2135 1) we write the GTID event separately to the binlog directly before
2136 moving the cache data, and if the reconciliation fails (e.g. if the
2137 directory storing the tmp file is full), the binlog would get
2138 corrupted with a standalone GTID event
2139 2) that happens during group commit with locks held, and other
2140 ready-to-commit (concurrent) transactions could be stalled
2141 */
2142 if (using_stmt && !thd->binlog_flush_pending_rows_event(TRUE, FALSE) &&
2143 flush_write_buffer_if_file_backed(
2144 cache_mngr->get_binlog_cache_log(FALSE)))
2145 DBUG_RETURN(1);
2146
2147 /*
2148 See statment cache comment above.
2149 */
2150 if (using_trx && !thd->binlog_flush_pending_rows_event(TRUE, TRUE) &&
2151 flush_write_buffer_if_file_backed(
2152 cache_mngr->get_binlog_cache_log(TRUE)))
2153 DBUG_RETURN(1);
2154
2155#ifdef WITH_WSREP
2156 /* Wsrep transaction was BF aborted but it must replay because certification
2157 succeeded. The transaction must not be written into binlog yet, it will
2158 be done during commit after the replay. */
2159 if (WSREP(thd) && wsrep_must_replay(thd))
2160 {
2161 DBUG_RETURN(0);
2162 }
2163#endif /* WITH_WSREP */
2164
2165 if (opt_binlog_engine_hton &&
2166 likely(!(thd->lex->sql_command == SQLCOM_XA_COMMIT &&
2167 thd->lex->xa_opt != XA_ONE_PHASE)))
2168 {
2169 /*

Calls 10

my_b_flush_io_cacheFunction · 0.85
is_explicit_XAMethod · 0.80
get_binlog_cache_logMethod · 0.80
wsrep_must_replayFunction · 0.70
emptyMethod · 0.45
write_eventMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected