设为首页 收藏本站
查看: 846|回复: 0

[经验分享] ORACLE 一致读(Consistent Read)的步骤

[复制链接]

尚未签到

发表于 2016-7-26 09:27:03 | 显示全部楼层 |阅读模式
  1. Read the Data Block.
  2. Read the Row Header.
  3. Check the Lock Byte to determine whether there's an ITL entry.
  4. Read the ITL entry to determine the Transaction ID (Xid).
  5. Read the Transaction Table using the Transaction ID. If the transaction has been committed and has a System Commit Number less than the query's System Change Number, update the status of the block (block cleanout) and start over at step 1.
  6. Read the last undo block (Uba).
  7. Compare the block transaction ID with the transaction table transaction ID. If the Transaction ID in the undo block doesn't equal the Transaction ID from the Transaction Table, then issue ORA-1555, Snapshot Too Old.
  8. If the Transaction IDs are identical, make a copy of the data block in memory. Starting with the head undo entry, apply the changes to the copied data block.
  9. If the tail undo entry (the actual first undo entry in the chain, or the last in the chain going backwards!) indicates another data block address, read the indicated undo block into memory and repeat steps 7 and 8 until the undo entries don't contain a value for the data block address.
  10. When there's no "previous data block address," the transaction has been completely undone.
  11. If the undo entry contains:
  a. a pointer to a previous transaction undo block address, read the Transaction ID in the previous transaction undo block header and read the appropriate Transaction Table entry. Return to step 5.
  b. an ITL record, restore the ITL record to the data block. Return to step 4.
  注释说明:
  事实上在第6步之前,会先比较query scn和control scn(下面红色字体是解释),如果control scn > query scn,oracle根本就不去尝试读取undo block了,因为注定失败,立刻报1555错误.
  第7步,表示
  不是修改了当前block的事务没有commit
  就是事务commit了但是commit scn >query scn,(因为第5步已经判断commit scn<query scn的情况)
  所以准备要读取回滚段中的前镜像。
  第9步,你可以把rollback的过程想象为一个链表,从一个undo block链到另一个undo block,直到the undo entries don't contain a value for the data block address,表示整个rollback的过程完毕了。
  补充知识:
  为什么事务完成后不马上作clean out(在data block的ITI写入commit SCN,清除锁标志)呢?
  一般情况下是这样的,这种情况称为fash clean out,但是有些时候比如只会CLEANOUT 10% buffer cache中的buffers,其余的会等下一次data block被重新读入再作clean out ,这种情况称为delay clean out,万一此Transaction Table上的记录被覆盖了(很有可能,因为可能很长时间后才被重新读入),则使用upper bound commit scn 作为其commit scn
  什么是upper bound commit?
  oracle 会把query scn 去和 回滚段中 事务的提交scn比较,如果没有找到事务结束scn,说明回滚信息已经被覆盖了。这时就把query scn 去和 control scn比较,因为 control SCN is the commit SCN of the most recently reused transaction slot's previous transaction. 如果 query scn 依然小于这个control scn ,由于被覆盖的事务的commit scn 肯定比回滚段中 contrl scn 小,则暗示着 oracle 无法知道 query scn 和 commit scn 之间的大小关系,就报了 1555 错误。
  这个时候,oracle就把这个 control scn 当作 upper bound commit scn 。这是因为,真实的cmmit scn 必然小于这个 control scn .而current scn必然远大于这个 control scn。所以将 commit scn 设置为这个control scn 必然是安全的。
  commit scn < control scn (upper bound scn) < current scn
  
  
  
from:http://blog.csdn.net/wh62592855/archive/2009/12/01/4917432.aspx

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-249467-1-1.html 上篇帖子: ORACLE数据库文件丢失后的恢复测试 下篇帖子: oracle 9i 使用decode 函数编译死锁
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表