当前位置: 首页 > wzjs >正文

网站建设性能分析网站托管目的是什么

网站建设性能分析,网站托管目的是什么,数字展厅网站建设,做网站被骗了怎么办XactLockTableWait函数、transactionid锁的一些原理和分析 结论 更新行时,会根据xmax拿transactionid锁,等对应的事务结束。 如果结束是回滚,则heap_update继续更新。如果结束时提交,则heap_update要返回上层ExecUpdate调用EvalP…

XactLockTableWait函数、transactionid锁的一些原理和分析

结论

  • 更新行时,会根据xmax拿transactionid锁,等对应的事务结束。
    • 如果结束是回滚,则heap_update继续更新。
    • 如果结束时提交,则heap_update要返回上层ExecUpdate调用EvalPlanQual重新拿到数据再更新(也有可能更新后不符合谓词就看不到了)。

场景

先执行事务1更新3为30,不提交。

再执行事务2更新所有小于10的数。

drop table t81;
create table t81(i int);
insert into t81 select t.i from generate_series(1,5) t(i);-- 事务745
begin;
update t81 set i = 30 where i = 3;-- 事务746
begin;
update t81 set i = 100 where i < 10;

事务二的update会卡住等待事务1。

postgres=# select * from pg_locks where pid <> pg_backend_pid() order by pid,locktype;locktype    | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction |  pid  |       mode       | granted | fastpath |waitstart
---------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+------------------+---------+----------+-------------------------------relation      |        5 |    16389 |      |       |            |               |         |       |          | 3/446              | 29044 | RowExclusiveLock | t       | t        |transactionid |          |          |      |       |            |           745 |         |       |          | 3/446              | 29044 | ExclusiveLock    | t       | f        |virtualxid    |          |          |      |       | 3/446      |               |         |       |          | 3/446              | 29044 | ExclusiveLock    | t       | t        |relation      |        5 |    16389 |      |       |            |               |         |       |          | 4/22               | 29246 | RowExclusiveLock | t       | t        |transactionid |          |          |      |       |            |           746 |         |       |          | 4/22               | 29246 | ExclusiveLock    | t       | f        |transactionid |          |          |      |       |            |           745 |         |       |          | 4/22               | 29246 | ShareLock        | f       | f        | xxxx-xx-xx 16:53:14.828479+08tuple         |        5 |    16389 |    0 |     3 |            |               |         |       |          | 4/22               | 29246 | ExclusiveLock    | t       | f        |virtualxid    |          |          |      |       | 4/22       |               |         |       |          | 4/22               | 29246 | ExclusiveLock    | t       | t        |
(8 rows)

分析

事务746的等锁堆栈

...#5  0x00000000009a4c23 in WaitOnLock (locallock=0x1f8d120, owner=0x1f9dbc0) at lock.c:1818
#6  0x00000000009a3961 in LockAcquireExtended (locktag=0x7ffd197ae4f0, lockmode=5, sessionLock=false, dontWait=false, reportMemoryError=true, locallockp=0x0) at lock.c:1082
#7  0x00000000009a2f3f in LockAcquire (locktag=0x7ffd197ae4f0, lockmode=5, sessionLock=false, dontWait=false) at lock.c:740
#8  0x00000000009a181c in XactLockTableWait (xid=740, rel=0x7f29222b20d8, ctid=0x7ffd197ae594, oper=XLTW_Update) at lmgr.c:702
#9  0x00000000004f1453 in heap_update (relation=0x7f29222b20d8, otid=0x7ffd197ae8aa, newtup=0x205baf8, cid=0, crosscheck=0x0, wait=true, tmfd=0x7ffd197ae8d8, lockmode=0x7ffd197ae82c, update_indexes=0x7ffd197ae828) at heapam.c:3316
#10 0x00000000004fdfa3 in heapam_tuple_update (relation=0x7f29222b20d8, otid=0x7ffd197ae8aa, slot=0x205b518, cid=0, snapshot=0x1f98370, crosscheck=0x0, wait=true, tmfd=0x7ffd197ae8d8, lockmode=0x7ffd197ae82c, update_indexes=0x7ffd197ae828) at heapam_handler.c:327
#11 0x000000000077f5a0 in table_tuple_update (rel=0x7f29222b20d8, otid=0x7ffd197ae8aa, slot=0x205b518, cid=0, snapshot=0x1f98370, crosscheck=0x0, wait=true, tmfd=0x7ffd197ae8d8, lockmode=0x7ffd197ae82c, update_indexes=0x7ffd197ae828) at ../../../src/include/access/tableam.h:1535
#12 0x000000000078278f in ExecUpdateAct (context=0x7ffd197ae8b0, resultRelInfo=0x205a4a8, tupleid=0x7ffd197ae8aa, oldtuple=0x0, slot=0x205b518, canSetTag=true, updateCxt=0x7ffd197ae824) at nodeModifyTable.c:2101
#13 0x0000000000782cbb in ExecUpdate (context=0x7ffd197ae8b0, resultRelInfo=0x205a4a8, tupleid=0x7ffd197ae8aa, oldtuple=0x0, slot=0x205b518, canSetTag=true) at nodeModifyTable.c:2322
#14 0x000000000078533d in ExecModifyTable (pstate=0x205a298) at nodeModifyTable.c:3824
#15 0x0000000000746fa6 in ExecProcNodeFirst (node=0x205a298) at execProcnode.c:464
#16 0x000000000073ad27 in ExecProcNode (node=0x205a298) at ../../../src/include/executor/executor.h:273...

可以看到事务746在等待事务745的transactionid锁。

事务746流程分析

heap_update拿到目标元组的otid和拼好的新元组后

heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, ...)

先把buffer锁上,因为另一个事务已经更新完了,所以buffer锁当前可以拿到。

LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);

然后拿到被修改元组的xmax,万一被别人改了呢?例如这里xwait=745,且745还没提交。

xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);

注意这里要先放buffer,因为有可能别的事务会修改,后面需要重新锁上拿数据

LockBuffer(buffer, BUFFER_LOCK_UNLOCK);

先把行锁拿到,避免别人正在更新

heap_acquire_tuplock(relation, &(oldtup.t_self), LockTupleNoKeyExclusive, LockWaitBlock, &have_tuple_lock);

在去拿xmax=745的事务锁,确保修改那个事务已经没了

XactLockTableWait(xwait, relation, &oldtup.t_self, XLTW_Update);

这里会加transactionid的ShareLock模式。

  • 746事务自己拿了一个transactionid ExclusiveLock因为自己也更新了数据。

  • 745事务有写入数据,所以745已经拿到transactionid的ExclusiveLock。

  • 746事务去获取745的transactionid ShareLock,开始等锁。

这里等锁就发生了,保证了RC级别的隔离性。

postgres=# select * from pg_locks where pid <> pg_backend_pid() order by pid,locktype;locktype    | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction |  pid  |       mode       | granted | fastpath |waitstart
---------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+------------------+---------+----------+-------------------------------transactionid |          |          |      |       |            |           745 |         |       |          | 3/446              | 29044 | ExclusiveLock    | t       | f        |transactionid |          |          |      |       |            |           746 |         |       |          | 4/22               | 29246 | ExclusiveLock    | t       | f        |transactionid |          |          |      |       |            |           745 |         |       |          | 4/22               | 29246 | ShareLock        | f       | f        | xxxx-xx-xx 16:53:14.828479+08
  • 如果事务745发生了提交
    • 那么事务2就不应该更新3这条数据了。代码继续运行会检查oldtup.t_data,确认xmax到底有没有回滚。这里heap_update不会继续进行更新动作了,直接返回TM_Updated。外层函数ExecUpdate收到TM_Updated后,会调用EvalPlanQual重新读取这一行数据,如果还能看到就返回epqslot新元组下面重新更新;如果现在已经看不到这一行了,就返回NULL,这次的更新就结束了。
  • 如果事务745发生了回滚
    • 那么事务2就还能看到3这条数据。代码继续运行检查发现xmax已经回滚了,可以继续更新,所以在heap_update中完成了本次更新,返回TM_Ok。
http://www.dtcms.com/wzjs/806253.html

相关文章:

  • 建网站 需要签署协议建设银行官方网站个人系统板块修改
  • 电子商务网站建设与管理课后在线直播
  • 惠安网站建设网站开发预算多少
  • 计算机应用技术与php网站开发美团网站建设总体需求与目标
  • 网站建设龙头股出口退税在哪个网站做
  • 做网站为什么先交定金国内排名前五的电商
  • 所有网站名称大全wordpress简单工作室博客
  • 聊城集团网站建设营销型企业网站的类型
  • 网站是怎么做的吗江苏省工程建设信息官方网
  • 门户网站开发视频教学wordpress注册默认密码忘记
  • 奉贤网站开发公司网站怎么做才高大上
  • 网站做的最好的兰州网站建设
  • 前端个人网站模板电子科技产品东莞网站建设
  • 衡水做企业网站的价格合肥网页
  • 海珠一站式网站建设商业网站有什么作用
  • 如何在工商局网站做企业年报毕设网站开发需要做什么
  • 巨人科技网站建设在演示文稿上网站怎么做
  • 中国建设建筑教育网站wordpress5.0老版编辑器
  • 专业网站设计联系电话建设网上银行个人登录入口
  • 品牌网站排名软件wordpress修改logo地址
  • 工行网站跟建设网站区别自助建设网站软件
  • 汉化版网站开发软件万网商标注册
  • 网络营销的相关知识广安seo
  • 保定市住房保障和城乡建设局网站甘肃省建设厅网站首页
  • 乐清 网站建设安徽质量工程建设网站
  • wordpress作者页面显示评论搜索引擎seo优化怎么做
  • 黑龙江省建设网站wordpress打开慢 cdn
  • 便宜点的网站空间做古玩的网站
  • 网站开发美学 2.0wordpress 评论ajax
  • 想开网站建设公司软件开发的八个步骤