当前位置:网站首页>mysql加写锁不生效
mysql加写锁不生效
2022-07-21 15:23:00 【聂炳玉】
1. 背景
需要验证:程序查询mylsq失败后执行流程是否符合预期。
待测试的程序:1.定时从mysql中读取数据;2.程序已经配置读写超时。
验证过程:
程序启动之后,添加写锁,下一次查询mysql应该失败,会执行失败流程。发现添加写锁之后,还能正确读取数据。
2. 加锁/解锁
加锁:
- locak table ‘table’ [read|write]
解锁:
- unlock tables
3. 失效原因
加锁之后的表现:
- 程序中定时读取数据正常
- 当前窗口终端,能查询到数据
- 新开启的终端,查询数据阻塞
从表现看 1和2 在加锁前都有从db中读取过数据,3是在加锁之后开始读数据。推测和缓存有关。
查询发现有开启缓存:
MariaDB> show variables like "%query_cache%";
+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 33554432 |
| query_cache_strip_comments | OFF |
| query_cache_type | ON |
| query_cache_wlock_invalidate | OFF |
+------------------------------+----------+
缓存会在数据更新之后失效,更新一下表数据,程序定时查询失败,符合预期。
4. 总结
在需要对表加锁进行验证,如果加锁之后还能读到数据,失效的原因可能和开启缓存有关。解决办法,执行update或insert更新一下表。
边栏推荐
猜你喜欢
Jupyter使用TIPS
Matlab GUI编程技巧(八):uitoolbar在图窗中创建工具栏
Matlab GUI编程技巧(七):matlablistbox操作-列表框(ListBox)和uilistbox常用操作
ArcGIS像元大小从0.00025变为米
B tree and b+ tree hash index
Matlab GUI编程技巧(九):详解 uitable 函数显示表格及相关操作(创建表用户界面)
Matlab GUI programming skills (x): UI figure function to create a visual window
The difference between abstract class and interface interface in C #
观察者模式与发布/订阅模式
EMQ映云科技荣登《中国企业家》2022年度“新锐100”榜单
随机推荐
Vim Ctags
【一个简单干净的log4j.properties完整配置】
ZBar项目简介及安装配置 | [email protected]
Recursive implementation of Hanoi Tower problem
接口与抽象类
英特尔计划出售基带芯片业务,但苹果已放弃?
ECCV 2022 | fix the performance damage of large targets caused by FPN: you should look at all objects
数组实现可扩展的循环队列
链表结构的栈实现
The properties of variables and functions beginning with static specifiers in C language
How to add a map to a page
实现逐行输出文本文件的内容
FileNotFoundError: [Errno 2] No such file or directory: ‘cmake‘
资金紧张,长电科技1.2亿美元出售星科金朋部分资产!
VLOOKUP函数
B tree and b+ tree hash index
Airtest stepped on the pit -- start flash back
side effect of intrinsics
Jmeter安装与设置(一)
索引