10bet网址
MySQL 8.0 Reference Manual
Related Documentation Download this Manual Excerpts from this Manual

17.5.1.21 Replication and MEMORY Tables

When a replication source server shuts down and restarts, itsMEMORYtables become empty. To replicate this effect to replicas, the first time that the source uses a givenMEMORYtable after startup, it logs an event that notifies replicas that the table must be emptied by writing aDELETEor (from MySQL 8.0.22)TRUNCATE TABLEstatement for that table to the binary log. This generated event is identifiable by a comment in the binary log, and if GTIDs are in use on the server, it has a GTID assigned. The statement is always logged in statement format, even if the binary logging format is set toROW, and it is written even ifread_onlyorsuper_read_onlymode is set on the server. Note that the replica still has outdated data in aMEMORYtable during the interval between the source's restart and its first use of the table. To avoid this interval when a direct query to the replica could return stale data, you can set theinit_filesystem variable to name a file containing statements that populate theMEMORYtable on the source at startup.

When a replica server shuts down and restarts, itsMEMORYtables become empty. This causes the replica to be out of synchrony with the source and may lead to other failures or cause the replica to stop:

  • Row-format updates and deletes received from the source may fail withCan't find record in 'memory_table'.

  • 年代tatements such asINSERT INTO ... SELECT FROMmemory_tablemay insert a different set of rows on the source and replica.

The replica also writes aDELETEor (from MySQL 8.0.22)TRUNCATE TABLEstatement to its own binary log, which is passed on to any downstream replicas, causing them to empty their ownMEMORYtables.

The safe way to restart a replica that is replicatingMEMORYtables is to first drop or delete all rows from theMEMORYtables on the source and wait until those changes have replicated to the replica. Then it is safe to restart the replica.

An alternative restart method may apply in some cases. Whenbinlog_format=ROW, you can prevent the replica from stopping if you setreplica_exec_mode=IDEMPOTENT(from MySQL 8.0.26) orslave_exec_mode=IDEMPOTENT(before MySQL 8.0.26) before you start the replica again. This allows the replica to continue to replicate, but itsMEMORYtables still differ from those on the source. This is acceptable if the application logic is such that the contents ofMEMORYtables can be safely lost (for example, if theMEMORYtables are used for caching).replica_exec_mode=IDEMPOTENTorslave_exec_mode=IDEMPOTENTapplies globally to all tables, so it may hide other replication errors in non-MEMORYtables.

(The method just described is not applicable in NDB Cluster, wherereplica_exec_modeorslave_exec_modeis alwaysIDEMPOTENT, and cannot be changed.)

的大小MEMORYtables is limited by the value of themax_heap_table_sizesystem variable, which is not replicated (see年代ection 17.5.1.39, “Replication and Variables”). A change inmax_heap_table_sizetakes effect forMEMORYtables that are created or updated usingALTER TABLE ... ENGINE = MEMORYorTRUNCATE TABLEfollowing the change, or for allMEMORYtables following a server restart. If you increase the value of this variable on the source without doing so on the replica, it becomes possible for a table on the source to grow larger than its counterpart on the replica, leading to inserts that succeed on the source but fail on the replica withTable is fullerrors. This is a known issue (Bug #48666). In such cases, you must set the global value ofmax_heap_table_sizeon the replica as well as on the source, then restart replication. It is also recommended that you restart both the source and replica MySQL servers, to ensure that the new value takes complete (global) effect on each of them.

年代ee年代ection 16.3, “The MEMORY Storage Engine”, for more information aboutMEMORYtables.