Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql - do locks propagate over replication?

I have a Mysql master-slave(s) replication with MyISAM tables. All updates are done on the master and selects are done on either the master or slaves.

It appears that we might need to manually lock a few tables when we do certain updates. While this write lock is on the tables, no selects can happen on the locked table. But what about on the slaves? Does the lock propagate out?

Say I have table_A and table_B. I initiate a lock on table_A and table_B on the master and start performing the update. At this time no other connection can read table_A and table_B off the master? But what if at this time another connection tries to read the tables off of a slave, can they do so?

like image 867
adamSpline Avatar asked Jun 01 '12 23:06

adamSpline


People also ask

How do locks work in MySQL?

A MySQL Locks is nothing but a flag that can be assigned to a table to alter its properties. MySQL allows a table lock that can be assigned by a client-server to prevent other sessions from being able to access the same table during a specific time frame.

What causes MySQL locks?

The most common reason implicit locks are created is an INSERT operation: successfully inserted rows are not visible to other transactions until the inserting transaction commits, and it is a common situation that a single transaction inserts many rows, so it is cheaper to not create explicit locks for newly inserted ...

Does MySQL transaction lock row?

InnoDB implements standard row-level locking where there are two types of locks, shared ( S ) locks and exclusive ( X ) locks. A shared ( S ) lock permits the transaction that holds the lock to read a row. An exclusive ( X ) lock permits the transaction that holds the lock to update or delete a row.

Is MySQL replication single threaded?

The replication replay process executes in a single thread on the replicas, and thus has no hope of keeping up with even a moderately busy write load on the primary, where many updates are occurring concurrently.


1 Answers

Everything that MySQL replicates can be found in the binary logs.

You can run the following command to see the details.

show global variables like 'log_bin%';

log_bin_basename will tell you the path to your binary logs with base file name.

and run

show binary logs

to find the binary files that are currently present on your server.

You can check the actual commands that are written to the file by using mysqlbinlog command together with the file name or by running show binlog events ... from the MySQL CLI.

Also, check what binlog_format are you using.

Basically - the lock of the tables is not directly propagated to slaves, but at the time, whey will execute the performed updates they will perform a lock of the updated table if needed.

like image 101
Tata Avatar answered Oct 21 '22 15:10

Tata