| 2110 | */ |
| 2111 | |
| 2112 | static int |
| 2113 | binlog_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 | /* |
no test coverage detected