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

借贷网站建设方案收录网

借贷网站建设方案,收录网,永嘉网站开发公司,行业网站程序总结 PG的子事务回滚是真回滚(直接回滚了,不管顶层事务提交还是回滚)。 PG的子事务提交是假提交(子事务提交后会把决定权交给顶层事务,随顶层事务提交、回滚)。 子事务提交后,将xid记录到父事…

总结

  • PG的子事务回滚是真回滚(直接回滚了,不管顶层事务提交还是回滚)。

  • PG的子事务提交是假提交(子事务提交后会把决定权交给顶层事务,随顶层事务提交、回滚)。

子事务提交后,将xid记录到父事务的childXids,父事务的childXids就表示下面已经提交的子事务,这些子事务xid在后续mvcc计算中,会完全等效与所属父事务xid。

childXids

在Postgresql的事务状态中,存在childXids数组,本篇分析该结构的用途和原理。

typedef struct TransactionStateData
{...TransactionId *childXids;	/* subcommitted child XIDs, in XID order */int			nChildXids;		/* # of subcommitted child XIDs */int			maxChildXids;	/* allocated size of childXids[] */...struct TransactionStateData *parent;	/* back link to parent */
} TransactionStateData;typedef TransactionStateData *TransactionState;

用途

1 读取childXids:TransactionIdIsCurrentTransactionId

判断事务ID是否为当前事务。

如果xid和当前事务的xid不同,另外会从当前事务记录的childXids中再找一遍。

  • 因为childXids里面记录了当前事务下,已经提交了的子事务(只有提交了的,没有回滚的),所以这些提交的子事务xid就等同于主事务xid。
  • childXids是有序的,二分法即可。
bool
TransactionIdIsCurrentTransactionId(TransactionId xid)
{...if (TransactionIdEquals(xid, GetTopTransactionIdIfAny()))return true;...for (s = CurrentTransactionState; s != NULL; s = s->parent){...low = 0;high = s->nChildXids - 1;while (low <= high){int			middle;TransactionId probe;middle = low + (high - low) / 2;probe = s->childXids[middle];if (TransactionIdEquals(probe, xid))return true;else if (TransactionIdPrecedes(probe, xid))low = middle + 1;elsehigh = middle - 1;}}return false;
}

2 写入childXids:AtSubCommit_childXids

在子事务提交时,会执行AtSubCommit_childXids:

  1. 将本层的xid添加到上层事务的childXids中。
  2. 将本层记录的childXids传递到上层事务的childXids中。
static void
AtSubCommit_childXids(void)
{...new_nChildXids = s->parent->nChildXids + s->nChildXids + 1;...s->parent->childXids[s->parent->nChildXids] = XidFromFullTransactionId(s->fullTransactionId);if (s->nChildXids > 0)memcpy(&s->parent->childXids[s->parent->nChildXids + 1],s->childXids,s->nChildXids * sizeof(TransactionId));s->parent->nChildXids = new_nChildXids;/* Release child's array to avoid leakage */if (s->childXids != NULL)pfree(s->childXids);/* We must reset these to avoid double-free if fail later in commit */s->childXids = NULL;s->nChildXids = 0;s->maxChildXids = 0;
}

PG子事务维护链式结构,当子事务提交时,需要把自己记录“commited childs”信息逐层上交。

例如三层子事务的场景下:

												childXids
top-transaction     		    []sub-transaction-16401     []sub-transaction-16402   []sub-transaction-16403 []        <-- will commit
														childXids
top-transaction     		    		[]sub-transaction-16401     		[]sub-transaction-16402   		[]^|sub-transaction-16403 		[]				<-- committing
														childXids
top-transaction        					[]sub-transaction-16401     		[]sub-transaction-16402   		[16403]  	<-- committed
														childXids
top-transaction        					[]sub-transaction-16401     		[]sub-transaction-16402   		[16403]  	<-- will commit
														childXids
top-transaction        					[]sub-transaction-16401     		[16402, 16403]  <-- committed

当前事务记录的childXids在进行mvcc判断时,完全等效于自己的xid。

3 其他

AtSubAbort_childXids:子事务回滚时,需要清理childXids。

SerializeTransactionState:序列化事务状态。

其他还有初始化、清理等,不在列举。

http://www.cadmedia.cn/news/8214.html

相关文章:

  • 网站开发与设计教程友情链接交换条件
  • 中山建设网站的公司百度关键词排名爬虫
  • 手机免费图片制作软件站长工具seo优化
  • 全国精品课程建设网站网站代运营价格
  • 网站建设公司一年赚多少网络营销软文
  • 智慧社区背景图自动seo网站源码
  • 绍兴做网站公司seo专业培训班
  • 学校网站建设项目可行性分析最有效的推广学校的方式
  • 网站建设的知识和技能做关键词优化的公司
  • ruby 网站开发市场营销策划方案
  • 一个完整的网站推广方案网络推广网络营销软件
  • 中山市交通建设发展集团网站网站建设找哪家公司好
  • 江夏区建设局网站品牌广告策划方案
  • 网站建设状态栏新发布的新闻
  • 湖州网站推广有没有免费的crm系统软件
  • 天河区门户网站教育局板块怎么做app推广
  • 网站数据库连接错误百度网盘官方网站
  • 中石化第五建设有限公司官方网站武汉关键词seo排名
  • 一定要建设好网站才能备案吗seo工具包
  • 什么做自己的网站武汉网络推广公司排名
  • 网站设计空间蚁百杭州网站seo优化
  • 网站开发助理主要工作网店推广运营策略
  • 邯郸网站制作网站域名解析ip
  • 网站banner轮播代码网络推广渠道分类
  • 简洁网站首页模板seo怎么推排名
  • 微梦网站建设成都百度
  • 支付宝 手机网站支付接口2.0四川seo整站优化费用
  • 吕梁建设机械网站百度入驻
  • 商用图片做公司网站可以吗专业软文
  • 都匀网站建设公司新平台怎么推广