﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-死神永生</title><link>http://www.cppblog.com/knzeus/</link><description /><language>zh-cn</language><lastBuildDate>Thu, 23 Apr 2026 10:12:52 GMT</lastBuildDate><pubDate>Thu, 23 Apr 2026 10:12:52 GMT</pubDate><ttl>60</ttl><item><title>【转载】复杂是大敌</title><link>http://www.cppblog.com/knzeus/archive/2012/01/10/163962.html</link><dc:creator>knzeus</dc:creator><author>knzeus</author><pubDate>Tue, 10 Jan 2012 11:48:00 GMT</pubDate><guid>http://www.cppblog.com/knzeus/archive/2012/01/10/163962.html</guid><wfw:comment>http://www.cppblog.com/knzeus/comments/163962.html</wfw:comment><comments>http://www.cppblog.com/knzeus/archive/2012/01/10/163962.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/knzeus/comments/commentRss/163962.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/knzeus/services/trackbacks/163962.html</trackback:ping><description><![CDATA[<div><h2><a href="http://dirlt.com/blog/?p=1148" title="链向 复杂是大敌 的固定链接" rel="bookmark" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #000000; text-decoration: none; ">复杂是大敌</a></h2><div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; vertical-align: baseline; font-family: 'Helvetica Neue', Arial, Helvetica, 'Nimbus Sans L', sans-serif; color: #888888; font-size: 12px; line-height: 24px; "><span meta-prep-author"="" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">发表于</span>&nbsp;<a href="http://dirlt.com/blog/?p=1148" title="上午 3:33" rel="bookmark" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #888888; background-position: initial initial; background-repeat: initial initial; "><span style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">2012 年 1 月 6 日</span></a>&nbsp;<span style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">由</span>&nbsp;<span vcard"="" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; "><a fn=""  n"="" href="http://dirlt.com/blog/?author=1" title="查看所有由 dirtysalt 发布的文章" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #888888; background-position: initial initial; background-repeat: initial initial; ">dirtysalt</a></span></div><div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 12px; vertical-align: baseline; clear: both; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; "><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">原文链接&nbsp;<a href="http://www.aqee.net/complexity-is-the-enemy/" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #743399; background-position: initial initial; background-repeat: initial initial; ">http://www.aqee.net/complexity-is-the-enemy/</a><br />英文原文&nbsp;<a href="http://neugierig.org/software/blog/2011/04/complexity.html" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #743399; background-position: initial initial; background-repeat: initial initial; ">http://neugierig.org/software/blog/2011/04/complexity.html</a></p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">差不多在Google工作有7个年头了(!)。我在这学到了很多东西，写都写不完。然而不管怎样，我至少要向你们分享一条只有在我有了更多经验后才得到的东西。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">复杂是软件的死神。你无法用数字评估它所造成的代价，它会悄悄慢慢的出现，就像是用小火在煮你，让软件变得越来越糟，你很难察觉到，而当你察觉到时，那已经太晚了。在另一方面，你经常的会很容易的看到增加复杂度带来的好处：增加一个新的扩展层，你可以实现新功能X，或把本来运行在一个机器上的进程分成两个，用来解决当前系统的扩展瓶颈。但现在你的大脑里必须想着这个新增加的层，或这还要实现一个远程调用层来管理这两台机器。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">基本上，程序员老手和新手一样都很容易出现上面的情况。<strong style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">我认为这些年我在这个行业里学到的只是更擅长在两者之前取得平衡；何时复杂一点是合理的，何时必须要拒绝。我经常回想起一个朋友在Ken Thompson写的Go语言编译器上的一句评论：它很快，因为它没有做多少事，代码直接明了。</strong></p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">事实表明，就像你能很容易的写出一篇很长的博客但把相同的观点叙述的简明扼要却很难，你很难把软件写的简单明了。<strong style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">在编程语言的设计上你最容易看出这一点；新手设计出的语言总是包含大量的功能特征，而很少像C语言那样清爽明晰。如今的程序，动不动就牵涉多少个对象；这在分布式系统里就意味这你要移动多少的东西。</strong></p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">另外一个用来描述这个问题的词是&#8220;才智&#8221;：引用另外一个C程序员的话，&#8220;调试纠错程序比第一次编写出这程序要困难两倍，如果你是用尽了你所有的聪明才智写出这程序，那根据这定义，你就没有最够的才智去调试debug它了。&#8221;</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">建议吗？我怀疑只有通过经验才能理解这个道理&#8212;&#8212;有一个事很刺激我，太多的项目里都有人认为元数据编程很酷。我发现制定一个详细的设计目标来评估新代码是否有必要，这很有帮助。如果你可以说&#8220;这些代码不能帮助项目的最初设计目标上解决任何问题&#8221;，你就能很容易的拒绝这些代码。在Google，用来描述一个新项目的设计方案的文档模板上，在其右上角有个区域专门列着目标外内容：对项目的合理扩展将会被拒绝。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; "><strong style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">很讽刺的是，我发现使用弱智的工具或语言能帮助我们抵制复杂。你很难写出一个很复杂的C程序，因为它里面没有太多的东西。C程序大多用大量的数组，因为你只能用它，但结果却证明，数组是非常好的东西&#8212;&#8212;紧凑的内存使用，O(1)次的数据访问，很好的数据存储。</strong>但我从来没有倡导过特意的使用一种弱智的工具。相反，我的心得是：像C一样编写Python程序。</p></div></div><img src ="http://www.cppblog.com/knzeus/aggbug/163962.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/knzeus/" target="_blank">knzeus</a> 2012-01-10 19:48 <a href="http://www.cppblog.com/knzeus/archive/2012/01/10/163962.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转载】我希望四年前就有人告诉我的事情</title><link>http://www.cppblog.com/knzeus/archive/2012/01/10/163961.html</link><dc:creator>knzeus</dc:creator><author>knzeus</author><pubDate>Tue, 10 Jan 2012 11:44:00 GMT</pubDate><guid>http://www.cppblog.com/knzeus/archive/2012/01/10/163961.html</guid><wfw:comment>http://www.cppblog.com/knzeus/comments/163961.html</wfw:comment><comments>http://www.cppblog.com/knzeus/archive/2012/01/10/163961.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/knzeus/comments/commentRss/163961.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/knzeus/services/trackbacks/163961.html</trackback:ping><description><![CDATA[<div><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">原文链接&nbsp;<a href="http://www.aqee.net/what-i-wish-someone-had-told-me-5-years-ago/" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #743399; background-position: initial initial; background-repeat: initial initial; ">http://www.aqee.net/what-i-wish-someone-had-told-me-5-years-ago/</a><br />英文原文&nbsp;<a href="http://blog.amirkhella.com/2011/02/23/what-i-wish-someone-had-told-me-5-years-ago/" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #743399; background-position: initial initial; background-repeat: initial initial; ">http://blog.amirkhella.com/2011/02/23/what-i-wish-someone-had-told-me-5-years-ago/</a></p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">就在2007年，我毅然离开了微软，加入了创业者的队伍。像很多第一次创业的人一样，我对这种冒险非常的兴奋。同样也跟很多第一次创业的人一样，我茫然没有头绪。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">我参加各种活动，聚会，研讨会，和西雅图本地的创业社区密切交往。当我到了硅谷后，我发现这里有更多的活动，聚会，更多的研讨会。在这个创业生态系统里，一切很忙、很活跃，我收获了大量的人们共享出来的知识和体验，我如饥似渴的享用着。我还满腔热情的看了很多的博客，视频和书籍。活动、聚会、研讨会中人们分享和讨论的都是非常好的主题。我甚至还加入了一个创业孵化机构！</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; "><strong style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">直到决定开办自己的公司时，我才意识到，所有我的阅读、观看、参加的活动实际上没有给我带来任何的用处。我是认真的。完全没有任何用处。</strong>大部分我学到的东西都想不起来了，剩下一点能记住的也很少能应用到我现在的处境里。学习他人的经验和成功对我就像是在吃快餐，像是吃那些味道很好的垃圾食品，让我膨胀，让我自满。抱歉我在泼冷水，但这是事实。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">起初，我努力把我学到的东西应用到我自己的问题里。不灵。这不可思议的时刻真的到来了，我平静的接受了这个事实：我浪费了大量的时间去学了一些根本不需要的东西，我相信有人说过的一句话正是在嘲笑我的这些行为：所有的这些活动，研讨会，博客文章都只是用来多拖延你一天立即行动的另一个借口。我默默的接受这个事实，以一个新手的心情往前走，沿着这个方向，我相信我将会理解出什么才是我需要的。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">所有的变化由此而来。<strong style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">我们每个人身上都有一种东西，想在这种存在着不确定性、具有风险的创业冒险活动中创造，成就，前进。但我们还有另外一种东西，每个人都希望能感到确定，可靠，让我们能做出正确的决策，让我们在这条道路上不至于失败、使自己受伤。</strong>矛盾冲突就是从此产生的。可是这些博客，活动，访谈并不能真正的消解这些矛盾。只是暂时的，它让我知道，有很多人在做和我同样的事情，让我放松。去创业是让我走出我的安逸环境，而我所做的只是从一个安逸环境跳到另外一个安逸环境。你知道吗？我就职于一个不错的公司！</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">一天，我反省一下我目前的状况，发现自己忙于很多事情，唯独没有把时间用于自己的产品上。几个月后，我终于鼓足勇气对自己说：这唯一重要的事情是真正的坐下来去做事。别误会。我觉得有些博客和研讨会还是有价值的。但除非你真正的去实施什么事情、给你所学所扩展的关系网创造一个用武之地，你就是在浪费你的宝贵时间。</p><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">下面就是一些帮助了我去克服这&#8220;创业困惑综合症&#8221;的东西：</p><ol style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 1.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; list-style-position: initial; list-style-image: initial; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; "><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">我数周内不再阅读创业新闻和博客，我意识到对于我的产品我不缺任何东西。至于谁又获得了融资，谁被收购了，以及为什么在Google Chrome的竞争下IE丧失了它的市场份额，这跟我没有任何关系。我唯一要关新的人是客户，我唯一要关注的事情他们的需求和愿望、如何提供他们最有价值的东西。</li><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">我数月不去参加那些创业相关的活动，而且开始通过咖啡和酒去交接朋友。每月我仍可能会去参加一两个活动，但那只是为了娱乐。我不再迷惑于为了成为一个企业家而且参加那些创业相关的活动。</li><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">我通过小项目来实践学习。我把一些想法细化成容易管理的细目，给自己设定期限去完成它们。项目和试验品是神奇的教学工具，因为你在学习你想要的，你在获得第一手资料。就像Keynotopia这个项目极大的帮助了我产生灵感，形成思路，我可以看见它，和它交互，展示给别人 &#8212;&#8212; 这就是我首先要把它做出来的原因！有时一些小项目还可以让你获得不少收入&nbsp;<img src="http://dirlt.com/blog/wp-includes/images/smilies/icon_wink.gif" alt=";)" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; " /></li><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">每走一步，我都准备好一个问题清单，它能让我知道下一步该往哪里走。是该去获得更多的访问量？改进产品？还是在不提高访问量的情况下提高收入？我整理出最好的问题，然后研究它，咨询人们，然后把获得的答案立即付诸于行动。这些信息我都不会让它们在我的大脑里转的太久。</li><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">这是我的最爱：我更多的恐惧是产生于因为没有去行动，而不是相反的害怕去行动。我认识到，晚一天我没有让客户接受我的方案，竞争对手就多一天的机会比我先达到客户要求。我甚至设想到了如果我不能行动起来，最终将会看到最可怕的噩梦：从办公室又回到密尔顿，在Innotech的小隔间里饱食终日，拿着那个红色的订书机，等着下一次的发薪日。这正是我需要的充满魔力的紧迫感。</li><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">我第一是要把事情完成，然后才是把事情办对。我知道(深受教训)，做事的劲头重要无比。如果你在得到一个想法后不能立即付诸实施，最终很有可能的结局是这个想法被束之高阁。如今不论何时我得到了一个想法，我会盯着它让它成为现实，让它变成实际。我立即行动，虽然方式不成熟，但之后想办法改进，这样就学会了自己真正需要的东西。</li><li style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">面对现实：如果你不走出你的安逸环境、动手去干，什么事情都不会发生。等待再等待，罕有行动。</li></ol><p style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; color: #333333; font-family: Georgia, 'Bitstream Charter', serif; font-size: 16px; line-height: 24px; ">我想留给你们一句改变了我的生活的名言：<strong style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; vertical-align: baseline; background-position: initial initial; background-repeat: initial initial; ">成功的人并不是一定比别人更有才智和更幸运。他们只是在不断的尝试、不断的失败，直到成功。不要做想象中的企业家。用行动和成果成为企业家。</strong></p></div><img src ="http://www.cppblog.com/knzeus/aggbug/163961.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/knzeus/" target="_blank">knzeus</a> 2012-01-10 19:44 <a href="http://www.cppblog.com/knzeus/archive/2012/01/10/163961.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【zz】Journaling file system</title><link>http://www.cppblog.com/knzeus/archive/2012/01/05/163592.html</link><dc:creator>knzeus</dc:creator><author>knzeus</author><pubDate>Wed, 04 Jan 2012 16:44:00 GMT</pubDate><guid>http://www.cppblog.com/knzeus/archive/2012/01/05/163592.html</guid><wfw:comment>http://www.cppblog.com/knzeus/comments/163592.html</wfw:comment><comments>http://www.cppblog.com/knzeus/archive/2012/01/05/163592.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/knzeus/comments/commentRss/163592.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/knzeus/services/trackbacks/163592.html</trackback:ping><description><![CDATA[转载：<a href="http://en.wikipedia.org/wiki/Journaling_file_system">http://en.wikipedia.org/wiki/Journaling_file_system</a><br /><br /><div><h1>Journaling file system</h1><div id="bodyContent" style="font-size: 0.8em; position: relative; width: 745px; line-height: 1.5em; font-family: sans-serif; background-color: #ffffff; border-image: initial; "><div id="siteSub" style="display: inline; ">From Wikipedia, the free encyclopedia</div><div id="contentSub" style="font-size: 11px; line-height: 1.2em; margin-top: 0px; margin-right: 0px; margin-bottom: 1.4em; margin-left: 1em; color: #7d7d7d; width: auto; "></div><div dir="ltr" style="direction: ltr; "><div style="font-style: italic; padding-left: 1.6em; margin-bottom: 0.5em; ">For the IBM Journaled File System, see&nbsp;<a href="http://en.wikipedia.org/wiki/JFS_(file_system)" title="JFS (file system)" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">JFS (file system)</a>.</div><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">A&nbsp;<strong>journaling</strong>&nbsp;<strong>file system</strong>&nbsp;is a&nbsp;<a href="http://en.wikipedia.org/wiki/File_system" title="File system" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">file system</a>&nbsp;that keeps track of the changes that will be made in a&nbsp;<em>journal</em>&nbsp;(usually a circular log in a dedicated area of the file system) before committing them to the main file system. In the event of a system crash or power failure, such file systems are quicker to bring back online and less likely to become corrupted.<sup id="cite_ref-developerworks-1_0-0" style="line-height: 1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_note-developerworks-1-0" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">[1]</a></sup></p><table id="toc" style="font-size: 13px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-color: #aaaaaa; background-color: #f9f9f9; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; "><tbody><tr><td><div id="toctitle" style="direction: ltr; text-align: center; "><h2>Contents</h2>&nbsp;<span style="font-size: 11px; ">&nbsp;[<a href="http://en.wikipedia.org/wiki/Journaling_file_system#" id="togglelink" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">hide</a>]&nbsp;</span></div><ul style="line-height: 1.5em; list-style-type: none; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0.3em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; text-align: left; "><li tocsection-1"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Rationale" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">1&nbsp;Rationale</a></li><li tocsection-2"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Techniques" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">2&nbsp;Techniques</a><ul style="line-height: 1.5em; list-style-type: none; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; "><li tocsection-3"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Physical_journals" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">2.1&nbsp;Physical journals</a></li><li tocsection-4"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Logical_journals" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">2.2&nbsp;Logical journals</a></li><li tocsection-5"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Write_hazards" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">2.3&nbsp;Write hazards</a></li></ul></li><li tocsection-6"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Alternatives" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">3&nbsp;Alternatives</a><ul style="line-height: 1.5em; list-style-type: none; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; "><li tocsection-7"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Soft_updates" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">3.1&nbsp;Soft updates</a></li><li tocsection-8"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Log-structured_file_systems" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">3.2&nbsp;Log-structured file systems</a></li><li tocsection-9"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#Copy-on-write_file_systems" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">3.3&nbsp;Copy-on-write file systems</a></li></ul></li><li tocsection-10"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#See_also" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">4&nbsp;See also</a></li><li tocsection-11"="" style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#References" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">5&nbsp;References</a></li></ul></td></tr></tbody></table><h2><span style="float: right; margin-left: 5px; font-size: 13px; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=1" title="Edit section: Rationale" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Rationale">Rationale</span></h2><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">Updating file systems to reflect changes to files and directories usually requires many separate write operations. This makes it possible for an interruption (like a power failure or system&nbsp;<a href="http://en.wikipedia.org/wiki/Crash_(computing)" title="Crash (computing)" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">crash</a>) between writes to leave data structures in an invalid intermediate state.<sup id="cite_ref-developerworks-1_0-1" style="line-height: 1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_note-developerworks-1-0" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">[1]</a></sup></p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">For example, deleting a file on a Unix file system involves two steps:</p><ol style="line-height: 1.5em; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 3.2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; "><li style="margin-bottom: 0.1em; ">Removing its directory entry.</li><li style="margin-bottom: 0.1em; ">Marking space for the file and its&nbsp;<a href="http://en.wikipedia.org/wiki/Inode" title="Inode" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">inode</a>&nbsp;as free in the free space map.</li></ol><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">If a crash occurs between steps 1 and 2, there will be an orphaned inode and hence a&nbsp;<a href="http://en.wikipedia.org/wiki/Storage_leak" title="Storage leak" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">storage leak</a>. On the other hand, if only step 2 is performed first before the crash, the not-yet-deleted file will be marked free and possibly be overwritten by something else.</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">In a non-journaled file system, detecting and recovering from such inconsistencies requires a complete&nbsp;<a href="http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Walks" title="Glossary of graph theory" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">walk</a>&nbsp;of its data structures. This must typically be done before the file system is next mounted for read-write access. If the file system is large and if there is relatively little I/O bandwidth, this can take a long time and result in longer downtimes if it blocks the rest of the system from coming back online.</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">To prevent this, a journaled file system allocates a special area&#8212;the journal&#8212;in which it records the changes it will make, ahead of time. After a crash, recovery simply involves reading the journal from the file system and replaying changes from this journal until the file system is consistent again. The changes are thus said to be&nbsp;<a href="http://en.wikipedia.org/wiki/Atomicity_(database_systems)" title="Atomicity (database systems)" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">atomic</a>&nbsp;(or indivisible) in that they either:</p><ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.6em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAANCAMAAABW4lS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFAFKM////QIUK9QAAAAJ0Uk5T/wDltzBKAAAAGklEQVR42mJgBAEGokgGBjBGBxBxsBqAAAMACHwALd5r8ygAAAAASUVORK5CYII=); "><li style="margin-bottom: 0.1em; ">succeed (succeeded originally or are replayed completely during recovery), or</li><li style="margin-bottom: 0.1em; ">are not replayed at all (are skipped because they had not yet been completely written to the journal before the crash occurred).</li></ul><h2><span style="float: right; margin-left: 5px; font-size: 13px; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=2" title="Edit section: Techniques" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Techniques">Techniques</span></h2><table plainlinks="" ambox="" ambox-content=""  ambox-disputed"="" style="font-size: 13px; margin-top: 0px; margin-right: 10%; margin-bottom: 0px; margin-left: 10%; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-top-color: #aaaaaa; border-right-color: #aaaaaa; border-bottom-color: #aaaaaa; border-left-width: 10px; border-left-style: solid; border-left-color: #f28500; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #fbfbfb; "><tbody><tr><td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 2px; padding-right: 0px; padding-bottom: 2px; padding-left: 0.5em; text-align: center; "><div style="width: 52px; "><img alt="" src="http://upload.wikimedia.org/wikipedia/en/f/f4/Ambox_content.png" width="40" height="40" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; vertical-align: middle; " /></div></td><td style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0.25em; padding-right: 0.5em; padding-bottom: 0.25em; padding-left: 0.5em; width: 512px; ">This Physical vs. logical's&nbsp;<strong>factual accuracy is&nbsp;<a href="http://en.wikipedia.org/wiki/Wikipedia:Accuracy_dispute" title="Wikipedia:Accuracy dispute" style="text-decoration: none; color: #0b0080; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: initial !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; background-position: initial initial !important; background-repeat: initial initial !important; ">disputed</a></strong>. Please help to ensure that disputed facts are&nbsp;<a href="http://en.wikipedia.org/wiki/Wikipedia:RS" title="Wikipedia:RS" style="text-decoration: none; color: #0b0080; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: initial !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; background-position: initial initial !important; background-repeat: initial initial !important; ">reliably sourced</a>. See the relevant discussion on the&nbsp;<a href="http://en.wikipedia.org/wiki/Talk:Journaling_file_system#Physical_vs._logical" title="Talk:Journaling file system" style="text-decoration: none; color: #0b0080; background-image: none !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; background-color: initial !important; padding-top: 0px !important; padding-right: 0px !important; padding-bottom: 0px !important; padding-left: 0px !important; background-position: initial initial !important; background-repeat: initial initial !important; ">talk page</a>.&nbsp;<small><em>(December 2011)</em></small></td></tr></tbody></table><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">Some file systems allow the journal to grow, shrink and be re-allocated just as a regular file, while others put the journal in a contiguous area or a hidden file that is guaranteed not to move or change size while the file system is mounted. Some file systems may also allow&nbsp;<em>external journals</em>&nbsp;on a separate device, such as a solid-state disk or battery-backed non-volatile RAM. Changes to the journal may themselves be journaled for additional redundancy, or the journal may be distributed across multiple physical volumes to protect against device failure.</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">The internal format of the journal must guard against crashes while the journal itself is being written to. Many journal implementations (such as the JBD2 layer in ext4) bracket every change logged with a checksum, on the understanding that a crash would leave a partially-written change with a missing (or mismatched) checksum that can simply be ignored when replaying the journal at next remount.</p><h3><span style="float: right; margin-left: 5px; font-weight: normal; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=3" title="Edit section: Physical journals" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Physical_journals">Physical journals</span></h3><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">A&nbsp;<em>physical journal</em>&nbsp;logs an advance copy of every block that will later be written to the main file system. If there is a crash when the main file system is being written to, the write can simply be replayed to completion when the file system is next mounted. If there is a crash when the write is being logged to the journal, the partial write will have a missing or mismatched checksum and can be ignored at next mount.</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">Physical journals impose a significant performance penalty because every changed block must be committed&nbsp;<em>twice</em>&nbsp;to storage, but may be acceptable when absolute fault protection is required.<sup id="cite_ref-tweedie-1_1-0" style="line-height: 1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_note-tweedie-1-1" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">[2]</a></sup></p><h3><span style="float: right; margin-left: 5px; font-weight: normal; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=4" title="Edit section: Logical journals" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Logical_journals">Logical journals</span></h3><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">A&nbsp;<em>logical journal</em>&nbsp;stores only changes to file&nbsp;<a href="http://en.wikipedia.org/wiki/Metadata" title="Metadata" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">metadata</a>&nbsp;in the journal, and trades fault tolerance for substantially better write performance.<sup id="cite_ref-2" style="line-height: 1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_note-2" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">[3]</a></sup>&nbsp;A file system with a logical journal still recovers quickly after a crash, but may allow unjournaled file data and journaled metadata to fall out of sync with each other, causing data corruption.</p><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">For example, appending to a file may involve three separate writes to:</p><ol style="line-height: 1.5em; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 3.2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; "><li style="margin-bottom: 0.1em; ">The file's&nbsp;<a href="http://en.wikipedia.org/wiki/Inode" title="Inode" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">inode</a>, to increase its size.</li><li style="margin-bottom: 0.1em; ">The free space map, to mark out an allocation of space for append.</li><li style="margin-bottom: 0.1em; ">The newly-allocated space, to actually write the appended data.</li></ol><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">In a metadata-only journal, step 3 would not be logged. If step 3 was not done, but steps 1 and 2 are replayed during recovery, the file will be appended with garbage.</p><h3><span style="float: right; margin-left: 5px; font-weight: normal; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=5" title="Edit section: Write hazards" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Write_hazards">Write hazards</span></h3><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">The write cache in most operating systems sorts its writes (using the&nbsp;<a href="http://en.wikipedia.org/wiki/Elevator_algorithm" title="Elevator algorithm" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">elevator algorithm</a>&nbsp;or some similar scheme) to maximize throughput. To avoid an out-of-order write hazard with a metadata-only journal, writes for file data must be sorted so that they are committed to storage before their associated metadata. This can be tricky to implement because it requires coordination within the operating system kernel between the file system driver and write cache. An out-of-order write hazard can also exist if the underlying storage:</p><ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.6em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAANCAMAAABW4lS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFAFKM////QIUK9QAAAAJ0Uk5T/wDltzBKAAAAGklEQVR42mJgBAEGokgGBjBGBxBxsBqAAAMACHwALd5r8ygAAAAASUVORK5CYII=); "><li style="margin-bottom: 0.1em; ">cannot write blocks atomically, or</li><li style="margin-bottom: 0.1em; ">does not honor requests to flush its write cache</li></ul><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">To complicate matters, many mass storage devices have their own write caches, in which they may aggressively reorder writes for better performance. (This is particularly common on magnetic hard drives, which have large seek latencies that can be minimized with elevator sorting.) Some journaling file systems conservatively assume such write-reordering always takes place, and sacrifice performance for correctness by forcing the device to flush its cache at certain points in the journal (called barriers in&nbsp;<a href="http://en.wikipedia.org/wiki/Ext3" title="Ext3" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">ext3</a>&nbsp;and&nbsp;<a href="http://en.wikipedia.org/wiki/Ext4" title="Ext4" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">ext4</a>).<sup id="cite_ref-3" style="line-height: 1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_note-3" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">[4]</a></sup></p><h2><span style="float: right; margin-left: 5px; font-size: 13px; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=6" title="Edit section: Alternatives" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Alternatives">Alternatives</span></h2><h3><span style="float: right; margin-left: 5px; font-weight: normal; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=7" title="Edit section: Soft updates" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Soft_updates">Soft updates</span></h3><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">Some&nbsp;<a href="http://en.wikipedia.org/wiki/Unix_File_System" title="Unix File System" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">UFS</a>&nbsp;implementations avoid journaling and instead implement&nbsp;<a href="http://en.wikipedia.org/wiki/Soft_updates" title="Soft updates" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">soft updates</a>: they order their writes in such a way that the on-disk file system is never inconsistent, or that the only inconsistency that can be created in the event of a crash is a storage leak. To recover from these leaks, the free space map is reconciled against a full walk of the file system at next mount. This&nbsp;<a href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)" title="Garbage collection (computer science)" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">garbage collection</a>&nbsp;is usually done in the background.<sup id="cite_ref-4" style="line-height: 1em; "><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_note-4" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">[5]</a></sup></p><h3><span style="float: right; margin-left: 5px; font-weight: normal; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=8" title="Edit section: Log-structured file systems" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Log-structured_file_systems">Log-structured file systems</span></h3><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">In&nbsp;<a href="http://en.wikipedia.org/wiki/Log-structured_file_system" title="Log-structured file system" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">log-structured file systems</a>, the write-twice penalty does not apply because the journal itself&nbsp;<em>is</em>&nbsp;the file system: it occupies the entire storage device and is structured so that it can be traversed as would a normal file system.</p><h3><span style="float: right; margin-left: 5px; font-weight: normal; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=9" title="Edit section: Copy-on-write file systems" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="Copy-on-write_file_systems">Copy-on-write file systems</span></h3><p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em; ">Full&nbsp;<a href="http://en.wikipedia.org/wiki/Copy-on-write" title="Copy-on-write" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">copy-on-write</a>&nbsp;file systems (such as&nbsp;<a href="http://en.wikipedia.org/wiki/ZFS" title="ZFS" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">ZFS</a>&nbsp;and&nbsp;<a href="http://en.wikipedia.org/wiki/Btrfs" title="Btrfs" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Btrfs</a>) avoid in-place changes to file data by writing out the data in newly allocated blocks, followed by updated metadata that would point to the new data and disown the old, followed by metadata pointing to that, and so on up to the superblock, or the root of the file system hierarchy. This has the same correctness-preserving properties as a journal, without the write-twice overhead.</p><h2><span style="float: right; margin-left: 5px; font-size: 13px; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=10" title="Edit section: See also" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="See_also">See also</span></h2><ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0px; margin-left: 1.6em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAANCAMAAABW4lS6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFAFKM////QIUK9QAAAAJ0Uk5T/wDltzBKAAAAGklEQVR42mJgBAEGokgGBjBGBxBxsBqAAAMACHwALd5r8ygAAAAASUVORK5CYII=); "><li style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Comparison_of_file_systems" title="Comparison of file systems" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Comparison of file systems</a></li><li style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/ACID" title="ACID" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">ACID</a></li><li style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Database" title="Database" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Database</a></li><li style="margin-bottom: 0.1em; ">IBM's&nbsp;<a href="http://en.wikipedia.org/wiki/JFS_(file_system)" title="JFS (file system)" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Journaled File System (JFS)</a></li><li style="margin-bottom: 0.1em; "><a href="http://en.wikipedia.org/wiki/Transaction_processing" title="Transaction processing" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">Transaction processing</a></li></ul><h2><span style="float: right; margin-left: 5px; font-size: 13px; ">[<a href="http://en.wikipedia.org/w/index.php?title=Journaling_file_system&amp;action=edit&amp;section=11" title="Edit section: References" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">edit</a>]</span><span id="References">References</span></h2><div references-column-count=""  references-column-count-2"="" style="margin-bottom: 0.5em; -webkit-column-count: 2; list-style-type: decimal; "><ol style="line-height: 1.5em; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 3.2em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; list-style-type: inherit; "><li id="cite_note-developerworks-1-0" style="margin-bottom: 0.1em; ">^&nbsp;<a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_ref-developerworks-1_0-0" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><sup style="line-height: 1em; "><em><strong>a</strong></em></sup></a>&nbsp;<a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_ref-developerworks-1_0-1" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; "><sup style="line-height: 1em; "><em><strong>b</strong></em></sup></a>&nbsp;<span id="CITEREFJones2008" style="word-wrap: break-word; ">Jones, M Tim (2008-06-04),&nbsp;<a rel="nofollow"  text"="" href="http://www.ibm.com/developerworks/library/l-journaling-filesystems/index.html" style="text-decoration: none; color: #663366; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAFZJREFUeF59z4EJADEIQ1F36k7u5E7ZKXeUQPACJ3wK7UNokVxVk9kHnQH7bY9hbDyDhNXgjpRLqFlo4M2GgfyJHhjq8V4agfrgPQX3JtJQGbofmCHgA/nAKks+JAjFAAAAAElFTkSuQmCC); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; "><em>Anatomy of Linux journaling file systems</em></a>,&nbsp;<a href="http://en.wikipedia.org/wiki/IBM_DeveloperWorks" title="IBM DeveloperWorks" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">IBM DeveloperWorks</a>, retrieved 2009-04-13</span></li><li id="cite_note-tweedie-1-1" style="margin-bottom: 0.1em; "><strong><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_ref-tweedie-1_1-0" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">^</a></strong>&nbsp;<span id="CITEREFTweedie2000" style="word-wrap: break-word; ">Tweedie, Stephen (2000), "Ext3, journaling filesystem",&nbsp;<em>Proceedings of the Ottawa Linux Symposium</em>: 24&#8211;29</span></li><li id="cite_note-2" style="margin-bottom: 0.1em; "><strong><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_ref-2" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">^</a></strong>&nbsp;<span id="CITEREFPrabhakaranArpaci-DusseauArpaci-Dusseau" style="word-wrap: break-word; ">Prabhakaran, Vijayan; Arpaci-Dusseau, Andrea C; Arpaci-Dusseau, Remzi H,&nbsp;<a rel="nofollow"  text"="" href="https://www.usenix.org/events/usenix05/tech/general/full_papers/prabhakaran/prabhakaran.pdf" style="text-decoration: none; color: #663366; background-image: url(http://upload.wikimedia.org/wikipedia/commons/2/23/Icons-mini-file_acrobat.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 18px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">"Analysis and Evolution of Journaling File Systems"</a>&nbsp;(PDF),&nbsp;<em>2005 USENIX Annual Technical Conference</em>&nbsp;(USENIX Association)</span>.</li><li id="cite_note-3" style="margin-bottom: 0.1em; "><strong><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_ref-3" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">^</a></strong>&nbsp;<span id="CITEREFCorbet2008" style="word-wrap: break-word; ">Corbet, Jonathan (2008-05-21),&nbsp;<a rel="nofollow"  text"="" href="http://lwn.net/Articles/283161/" style="text-decoration: none; color: #663366; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAFZJREFUeF59z4EJADEIQ1F36k7u5E7ZKXeUQPACJ3wK7UNokVxVk9kHnQH7bY9hbDyDhNXgjpRLqFlo4M2GgfyJHhjq8V4agfrgPQX3JtJQGbofmCHgA/nAKks+JAjFAAAAAElFTkSuQmCC); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; "><em>Barriers and journaling filesystems</em></a>, retrieved 2010-03-06</span></li><li id="cite_note-4" style="margin-bottom: 0.1em; "><strong><a href="http://en.wikipedia.org/wiki/Journaling_file_system#cite_ref-4" style="text-decoration: none; color: #0b0080; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: initial initial; ">^</a></strong>&nbsp;<span id="CITEREFSeltzerGangerMcKusick" style="word-wrap: break-word; ">Seltzer, Margo I; Ganger, Gregory R; McKusick, M Kirk,&nbsp;<a rel="nofollow"  text"="" href="http://www.usenix.org/event/usenix2000/general/full_papers/seltzer/seltzer_html" style="text-decoration: none; color: #663366; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAFZJREFUeF59z4EJADEIQ1F36k7u5E7ZKXeUQPACJ3wK7UNokVxVk9kHnQH7bY9hbDyDhNXgjpRLqFlo4M2GgfyJHhjq8V4agfrgPQX3JtJQGbofmCHgA/nAKks+JAjFAAAAAElFTkSuQmCC); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-right: 13px; background-position: 100% 50%; background-repeat: no-repeat no-repeat; ">""Journaling Versus Soft Updates: Asynchronous Meta-data Protection in File Systems""</a>,&nbsp;<em>2000 USENIX Annual Technical Conference</em>&nbsp;(USENIX Association)</span>.</li></ol></div></div></div></div><img src ="http://www.cppblog.com/knzeus/aggbug/163592.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/knzeus/" target="_blank">knzeus</a> 2012-01-05 00:44 <a href="http://www.cppblog.com/knzeus/archive/2012/01/05/163592.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【zz】MySQL事务隔离级别详解</title><link>http://www.cppblog.com/knzeus/archive/2012/01/05/163588.html</link><dc:creator>knzeus</dc:creator><author>knzeus</author><pubDate>Wed, 04 Jan 2012 16:08:00 GMT</pubDate><guid>http://www.cppblog.com/knzeus/archive/2012/01/05/163588.html</guid><wfw:comment>http://www.cppblog.com/knzeus/comments/163588.html</wfw:comment><comments>http://www.cppblog.com/knzeus/archive/2012/01/05/163588.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/knzeus/comments/commentRss/163588.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/knzeus/services/trackbacks/163588.html</trackback:ping><description><![CDATA[转载地址：<a href="http://xm-king.iteye.com/blog/770721">http://xm-king.iteye.com/blog/770721<br /><br /><div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp; &nbsp; &nbsp; &nbsp;SQL标准定义了4类隔离级别，包括了一些具体规则，用来限定事务内外的哪些改变是可见的，哪些是不可见的。低级别的隔离级一般支持更高的并发处理，并拥有更低的系统开销。<br /><strong style="font-weight: bold; ">Read Uncommitted（读取未提交内容）</strong></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在该隔离级别，所有事务都可以看到其他未提交事务的执行结果。本隔离级别很少用于实际应用，因为它的性能也不比其他级别好多少。读取未提交的数据，也被称之为脏读（Dirty Read）。<br /><strong style="font-weight: bold; ">Read Committed（读取提交内容）</strong></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是大多数数据库系统的默认隔离级别（但不是MySQL默认的）。它满足了隔离的简单定义：一个事务只能看见已经提交事务所做的改变。这种隔离级别 也支持所谓的不可重复读（Nonrepeatable Read），因为同一事务的其他实例在该实例处理其间可能会有新的commit，所以同一select可能返回不同结果。<br /><strong style="font-weight: bold; ">Repeatable Read（可重读）</strong></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是MySQL的默认事务隔离级别，它确保同一事务的多个实例在并发读取数据时，会看到同样的数据行。不过理论上，这会导致另一个棘手的问题：幻读 （Phantom Read）。简单的说，幻读指当用户读取某一范围的数据行时，另一个事务又在该范围内插入了新行，当用户再读取该范围的数据行时，会发现有新的&#8220;幻影&#8221; 行。InnoDB和Falcon存储引擎通过多版本并发控制（MVCC，Multiversion Concurrency Control）机制解决了该问题。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; "><strong style="font-weight: bold; ">Serializable（可串行化）</strong>&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是最高的隔离级别，它通过强制事务排序，使之不可能相互冲突，从而解决幻读问题。简言之，它是在每个读的数据行上加上共享锁。在这个级别，可能导致大量的超时现象和锁竞争。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: medium; ">这四种隔离级别采取不同的锁类型来实现，若读取的是同一个数据的话，就容易发生问题。例如：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: medium; ">&nbsp;&nbsp; 脏读(Drity Read)：某个事务已更新一份数据，另一个事务在此时读取了同一份数据，由于某些原因，前一个RollBack了操作，则后一个事务所读取的数据就会是不正确的。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: medium; ">不可重复读(Non-repeatable read):在一个事务的两次查询之中数据不一致，这可能是两次查询过程中间插入了一个事务更新的原有的数据。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 幻读(Phantom Read):在一个事务的两次查询中数据笔数不一致，例如有一个事务查询了几列(Row)数据，而另一个事务却在此时插入了新的几列数据，先前的事务在接下来的查询中，就会发现有几列数据是它先前所没有的。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在MySQL中，实现了这四种隔离级别，分别有可能产生问题如下所示：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; background-color: #ffffff; text-align: center; "><img src="http://dl.iteye.com/upload/picture/pic/72610/af5b9c1e-4517-3df2-ad62-af25d1672d12.jpg" alt="" width="700" height="223" title="点击查看原始大小图片" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: url(http://www.iteye.com/images/magplus.gif), pointer; vertical-align: middle; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; "><br /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">下面，将利用MySQL的客户端程序，分别测试几种隔离级别。测试数据库为test，表为tx；表结构：</span></p><table border="0" width="440" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; height: 50px; "><tbody><tr><td style="font-size: 1em; text-align: center; "><span style="font-size: medium; ">id</span></td><td style="font-size: 1em; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int</span></td></tr><tr><td style="font-size: 1em; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-align: center; "><span style="font-size: medium; ">num</span></p></td><td style="font-size: 1em; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int</span></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">两个命令行客户端分别为A，B；不断改变A的隔离级别，在B端修改数据。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; "><strong style="font-weight: bold; ">（一）、将A的隔离级别设置为read uncommitted(未提交读)</strong></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;在B未更新数据之前：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端A：</span></strong><img src="http://dl.iteye.com/upload/picture/pic/72618/1ca8ec0d-3b6c-3ae1-babc-5dd541c4d1a4.jpg" alt="" width="645" height="379" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">B更新数据：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端B：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72620/b37214c3-7726-3306-95ee-1b2fae5ccd6c.jpg" alt="" width="640" height="397" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端A：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72622/200d9c94-197a-3fe5-8925-3411cd88555e.jpg" alt="" width="640" height="481" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: medium; ">&nbsp;&nbsp;&nbsp; 经过上面的实验可以得出结论，事务B更新了一条记录，但是没有提交，此时事务A可以查询出未提交记录。造成脏读现象。未提交读是最低的隔离级别。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">（二）、将客户端A的事务隔离级别设置为read committed(已提交读)</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;在B未更新数据之前：</span></p><strong style="font-weight: bold; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">客户端A：</span></strong><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><a href="http://xm-king.iteye.com/upload/picture/pic/72626/ae414e52-c216-3bbb-b005-0d972f593456.jpg" style="color: #006600; "><img src="http://dl.iteye.com/upload/picture/pic/72626/ae414e52-c216-3bbb-b005-0d972f593456.jpg" alt="" width="644" height="351" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">B更新数据：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端B：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72628/12051f3d-c01e-34b3-a6b6-8b71e1b1dcc8.jpg" alt="" width="641" height="313" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端A：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72630/cc80744e-eb9f-3104-bb24-2218e9986d78.jpg" alt="" width="642" height="351" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 经过上面的实验可以得出结论，已提交读隔离级别解决了脏读的问题，但是出现了不可重复读的问题，即事务A在两次查询的数据不一致，因为在两次查询之间事务B更新了一条数据。已提交读只允许读取已提交的记录，但不要求可重复读。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">(三)、<span style="font-size: medium; "><strong style="font-weight: bold; ">将A的隔离级别设置为repeatable read(可重复读)</strong></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;在B未更新数据之前：</span></p><div style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端A：</span></strong></div><div style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72632/0bf52be3-e873-3f3f-8d56-d703a8f678ab.jpg" alt="" width="643" height="319" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">B更新数据：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端B：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72634/e58d1814-bdca-3313-bcf5-339e3678536a.jpg" alt="" width="645" height="333" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端A：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72636/83bfe583-2d57-345a-917e-4ee163235b62.jpg" alt="" width="640" height="497" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">B插入数据：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端B：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72638/192348aa-4fa5-3d5f-a4f9-4660ddd725cd.jpg" alt="" width="641" height="366" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">客户端A：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72640/4398c5b1-434c-3380-ba19-060154cf2070.jpg" alt="" width="641" height="351" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 由以上的实验可以得出结论，可重复读隔离级别只允许读取已提交记录，而且在一个事务两次读取一个记录期间，其他事务部的更新该记录。但该事务不要求与其他事务可串行化。例如，当一个事务可以找到由一个已提交事务更新的记录，但是可能产生幻读问题(注意是可能，因为数据库对隔离级别的实现有所差别)。像以上的实验，就没有出现数据幻读的问题。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">(<strong style="font-weight: bold; ">四)、<span style="font-size: medium; "><strong style="font-weight: bold; ">将A的隔离级别设置为&nbsp;</strong></span><span style="font-size: medium; ">可串行化&nbsp;(Serializable)</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">A端打开事务，B端插入一条记录</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">事务A端：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72642/c604c5ce-311d-3923-8dcd-36b0188f4f31.jpg" alt="" width="639" height="234" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">事务B端：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72644/c488f9d9-7da2-3e6d-9a82-2b92d1051afd.jpg" alt="" width="640" height="141" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">因为此时事务A的隔离级别设置为serializable，开始事务后，并没有提交，所以事务B只能等待。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">事务A提交事务：</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">事务A端</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72646/322ed59a-b2b9-338c-a2f0-09c9b7707577.jpg" alt="" width="639" height="73" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><span style="font-size: medium; ">事务B端</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://dl.iteye.com/upload/picture/pic/72648/8e60e19b-09af-31a7-b8d3-8e638bbf177c.jpg" alt="" width="644" height="47" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: medium; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: medium; ">serializable完全锁定字段，若一个事务来查询同一份数据就必须等待，直到前一个事务完成并解除锁定为止</span>&nbsp;。<span style="font-size: medium; ">是完整的隔离级别，会锁定对应的数据表格，因而会有效率的问题。</span></p></div></a><img src ="http://www.cppblog.com/knzeus/aggbug/163588.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/knzeus/" target="_blank">knzeus</a> 2012-01-05 00:08 <a href="http://www.cppblog.com/knzeus/archive/2012/01/05/163588.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>