When we run the same query twice, we get the same result, regardless other session modifications on that table. What does a gap lock mean? A gap lock is a lock on a gap between index records, or a lock on the gap before the first or after the last index record. We want to read the records that are not touched by the second session. | parent | RECORD | S | supremum pseudo-record | GRANTED | | id | parent_name | child_id | child_name | Mysql> select * from parent where id1 for share Session one locks two rows in the parent table, one of which is a gap lock. | parent | RECORD | X,GAP | 2, 2 | GRANTED | | parent | RECORD | X,REC_NOT_GAP | 1 | GRANTED | | child | RECORD | X,REC_NOT_GAP | 1 | GRANTED | | parent | RECORD | X,REC_NOT_GAP | 1 | WAITING | | object_name | lock_type | lock_mode | lock_data | lock_status | Mysql> SELECT object_name, lock_type, lock_mode, lock_data, lock_status FROM performance_schema.data_locks Mysql> update parent set parent_name='parent2' where id=1 We’re gonna add a column to the parent table. Please check this article in order to prepare your setup. So now that we found a valid case for using triggers, let’s see what we need to be careful when using them. And in the same time we don’t want to work on the monolith to add more code which would support this migration, so the obvious choice would be to use database triggers. Of course in order to do this we need to synchronise the data. We want to keep the monolith working but in the same time prepare the new services so that we can do a canary release at some point. So, we’re not going with a bing bang approach but with incremental changes. One case for this would be refactoring your monolith to microservices and part of that is this database migration. Or you could break one table in multiple tables, in order to separate domain concepts. Let’s say that part of the migration you create new separate schema which you plan to use it for the new version. But if you plan to do a database migration you may find them handy. Who uses triggers you may wonder? That’s a valid question.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |