123
返回列表 发新帖
楼主: Alex螺丝钉

Oracle是否需要保证同一个事务的改变向量顺序写出呢?

[复制链接]
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
21#
发表于 2015-10-23 22:43 | 只看该作者
I'm not sure why you still have problems. As I said, your picture is fine. That is, one transaction can have its change vectors in different log buffers. In this case, each transaction must have multiple redo records. Just don't replace "transaction" with "redo record" in your picture.

使用道具 举报

回复
论坛徽章:
0
22#
 楼主| 发表于 2015-10-24 21:58 | 只看该作者
本帖最后由 Alex螺丝钉 于 2015-10-26 08:26 编辑
Yong Huang 发表于 2015-10-23 22:43
I'm not sure why you still have problems. As I said, your picture is fine. That is, one transaction  ...

Thanks for your patience, I really appreciate it.
I know what you mean, but pictures(in 15# of the topic there's one of them) of the book show that *change#*s of one transaction scattered in multiple log buffers, I think change# represents change vector here, and change# is the basic unit in the picture. As we can see, change vectors  scattered in multiple log buffers. Since redo record is made up of change vectors, that is to say the picture shows that change vectors of one redo record can scatter in multiple log buffers as well.
Even if change vectors of one redo record are  continuous in the log buffer and redo records scattered in multiple log buffers, it's still a problem how Oracle can write redo records to disk exactly as the order they are produced(or in other words, in the right order).
For example, how will Oracle handle the situation described in the following picture?  which block should be written first, block1 or block3?


使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
23#
发表于 2015-10-27 04:33 | 只看该作者
> that is to say the picture shows that change vectors of one redo record can scatter in multiple log buffers as well.

Change vectors of one redo record will be merged right before they're copied into the public redo strand (area). They will be continuous. Jonathan Lewis's book "Oracle Core Essential Internals" talks about this.

>  how Oracle can write redo records to disk exactly as the order they are produced(or in other words, in the right order)

Easy. Oracle just writes redo buffers sequentially. The buffers are filled sequentially. Are you thinking they are not? When I say a transaction can scatter redo records in multiple log buffers, I mean this trivial scenario: the redo records are generated at different times and a new log buffer is assigned in the middle. For example, time1: rr1 (redo record 1) of tx1; time2: rr1 of tx2; time3: rr2 of tx1, ... and suppose between time2 and time3, a log buffer is full and a new buffer is allocated. You see, tx1 has two redo records in two buffers.

In the picture you showed, the order of log buffers will be written to disk sequentially, blocks 1 and 2, then blocks 3 and 4. The two blocks in one buffer are written out in one I/O, at least from Oracle's point of view (and usually from the storage layer's point of view as well, unless log block size mismatches disk sector size). It makes little sense to say block 1 in your picture goes to disk before block 2, since they're in one I/O. But it's OK to say block 1 is written before block 3.

使用道具 举报

回复
论坛徽章:
0
24#
 楼主| 发表于 2015-10-28 12:05 | 只看该作者
Yong Huang 发表于 2015-10-27 04:33
> that is to say the picture shows that change vectors of one redo record can scatter in multiple lo ...

Thanks.
>They will be continuous. Jonathan Lewis's book "Oracle Core Essential Internals" talks about this.

In which chapter? I want to read about this.

>tx1 has two redo records in two buffers.

I still have a problem. A transaction can scatter redo records in multiple log buffers,  but are these redo records continuous in the log file?

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
25#
发表于 2015-10-28 23:13 | 只看该作者
> In which chapter? I want to read about this.

In Chapter 2, on p.6:

--- begin copy ---
1. Create a redo change vector describing how to insert an undo record into an
undo block.
2. Create a redo change vector for the data block change.
3. Combine the redo change vectors into a redo record and write it to the log
buffer.
4. Insert the undo record into the undo block.
5. Change the data block.
--- end copy ---

Step 3 is what I was talking about.

> A transaction can scatter redo records in multiple log buffers,  but are these redo records continuous in the log file?

Each redo record is continuous within itself. Two redo records that belong to one transaction may not be, because another redo record that belongs to a different transaction could be created in the middle of this transaction. When I say "continuous", I mean both in memory and in log files.

使用道具 举报

回复
论坛徽章:
70
夏利
日期:2013-09-29 21:02:15天蝎座
日期:2016-03-08 22:25:51嫦娥
日期:2014-03-04 16:46:45ITPUB年度最佳技术原创精华奖
日期:2014-03-04 16:19:29马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:11
26#
发表于 2015-10-29 09:45 | 只看该作者
"那么在多事务并发的时候就可能会出现同一个块中各个事务的改变向量相互交叉的情况"

是的,会出现这样的情况。

在上图所示的情况之下,不管事务1、事务2哪个先提交,换句话说就是不管先写哪个log buffer块,都会导致其中一个事务的改变向量无法顺序写到磁盘。那么到底Oracle是如何保证同一个事务的改变向量顺序写出呢?还是说Oracle本来就不需要同一个事务的改变向量顺序写出?如果不需要保证顺序写出,那么恢复的时候又怎么保证顺序应用改变向量呢?求解!

LGWR每次写都会尝试写所有的Log Buffer数据到磁盘。而且Oracle是根据顺序来的,假设有4个Log Buffer,以起始地址高低,分别是LB1,LB2,LB3,LB4,LB1的头地址最低,LGWR每次都是从LB1开始写(写的过程,获得Allcation Latch,确定要写的范围,释放allocation latch,在redo writing latch的保护下开始写)。Oracle不保证写进磁盘时,事务的redo record是按SCN顺序写。也就是说,有可能一个事务的commit的redo record写到log file中的前面了,但事务相关的DML写到Log file的后面。

Oracle在做recover时,包括在dump logfile时,Oracle都会根据SCN和sub scn排序的。

使用道具 举报

回复
论坛徽章:
0
27#
 楼主| 发表于 2015-10-30 12:28 | 只看该作者
Yong Huang 发表于 2015-10-28 23:13
> In which chapter? I want to read about this.

In Chapter 2, on p.6:

Thank you!

使用道具 举报

回复
论坛徽章:
0
28#
 楼主| 发表于 2015-10-30 14:10 | 只看该作者
vage 发表于 2015-10-29 09:45
"那么在多事务并发的时候就可能会出现同一个块中各个事务的改变向量相互交叉的情况"

是的,会出现这样的 ...

懂了,谢谢~~书很好,现在在读第三遍啦

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表