[{"data":1,"prerenderedAt":1081},["ShallowReactive",2],{"content:\u002Fen\u002Fprojects\u002Fmydb\u002Fmydb6":3,"series:content_en":371},{"id":4,"title":5,"authorship":6,"body":7,"categories":343,"date":345,"description":346,"draft":347,"extension":348,"image":349,"meta":350,"navigation":352,"path":353,"permalink":354,"published":354,"readingTime":355,"recommend":354,"references":354,"seo":360,"seoDescription":361,"seoTitle":354,"sitemap":362,"stem":363,"tags":364,"type":369,"__hash__":370},"content_en\u002Fposts\u002Fprojects\u002Fmydb\u002Fmydb6.md","MYDB 6. Record Versions and Transaction Isolation","human-only",{"type":8,"value":9,"toc":329},"minimark",[10,22,27,30,36,39,43,48,51,64,67,75,83,86,97,100,103,106,110,113,116,119,122,131,134,138,141,144,152,155,161,168,174,177,183,190,196,205,209,213,216,219,222,231,234,237,240,246,249,252,258,261,265,268,271,277,280,283,288,291,299,302,305,311,314,320,323],[11,12,13,14,21],"p",{},"All the code in this chapter is in ",[15,16,20],"a",{"href":17,"rel":18},"https:\u002F\u002Fgithub.com\u002FCN-GuoZiyang\u002FMYDB\u002Ftree\u002Fmaster\u002Fsrc\u002Fmain\u002Fjava\u002Ftop\u002Fguoziyang\u002Fmydb\u002Fbackend\u002Fvm",[19],"nofollow","backend\u002Fvm",".",[23,24,26],"h3",{"id":25},"introduction","Introduction",[11,28,29],{},"In this chapter, we start discussing the Version Manager.",[31,32,33],"blockquote",{},[11,34,35],{},"VM uses two-phase locking (2PL) to make schedules serializable and implements MVCC to eliminate blocking between reads and writes. It also implements two isolation levels.",[11,37,38],{},"Just as the Data Manager is the core of MYDB’s data management, the Version Manager is the core of its transaction and data version management.",[23,40,42],{"id":41},"_2pl-and-mvcc","2PL and MVCC",[44,45,47],"h4",{"id":46},"conflicts-and-2pl","Conflicts and 2PL",[11,49,50],{},"First, let us define a database conflict. Ignore inserts for now and consider only updates (U) and reads (R). Two operations conflict if all three conditions hold:",[52,53,54,58,61],"ol",{},[55,56,57],"li",{},"They are performed by different transactions.",[55,59,60],{},"They operate on the same data item.",[55,62,63],{},"At least one is an update.",[11,65,66],{},"That leaves only two kinds of conflict over the same data:",[52,68,69,72],{},[55,70,71],{},"U operations from two different transactions conflict.",[55,73,74],{},"A U and an R from two different transactions conflict.",[11,76,77,78,82],{},"Why does it matter whether operations conflict? Because ",[79,80,81],"strong",{},"swapping the order of two non-conflicting operations does not affect the final result",", whereas swapping conflicting operations does.",[11,84,85],{},"Set conflicts aside for a moment. Remember the example in Chapter 4, where two concurrent transactions operate on x? Suppose x initially equals 0:",[87,88,93],"pre",{"className":89,"code":91,"language":92},[90],"language-text","T1 begin\nT2 begin\nR1(x) \u002F\u002F T1 读到 0\nR2(x) \u002F\u002F T2 读到 0\nU1(0+1) \u002F\u002F T1 尝试把 x+1\nU2(0+1) \u002F\u002F T2 尝试把 x+1\nT1 commit\nT2 commit\n","text",[94,95,91],"code",{"__ignoreMap":96},"",[11,98,99],{},"The final value of x is 1, clearly not the result we expect.",[11,101,102],{},"One of VM’s most important jobs is ensuring that schedules are serializable. MYDB uses two-phase locking (2PL) for this. If transaction i has locked x and transaction j wants to perform an operation on x that conflicts with i’s earlier operation, j blocks. For example, if T1 has locked x for U1(x), both reads and writes of x by T2 will block. T2 must wait for T1 to release the lock on x.",[11,104,105],{},"So 2PL does guarantee serializable schedules, but it inevitably makes transactions block one another and can even cause deadlocks. To improve transaction throughput and reduce the chance of blocking, MYDB implements MVCC.",[44,107,109],{"id":108},"mvcc","MVCC",[11,111,112],{},"Before introducing MVCC, let us clarify what records and versions mean.",[11,114,115],{},"DM exposes Data Items to higher-level modules. VM manages those Data Items and exposes records, or Entries. A record is the smallest unit of data a higher-level module can operate on through VM. Internally, VM maintains multiple Versions of each record. Whenever a higher-level module changes a record, VM creates a new version of it.",[11,117,118],{},"MVCC reduces the probability of transactions blocking in MYDB. Suppose T1 wants to update record X. It first acquires the lock on X, then updates it by creating a new version, say x3. Before T1 releases the lock, T2 wants to read X. Instead of blocking, MYDB returns an older version, such as x2. The result is equivalent to T2 running before T1, so the schedule remains serializable. If X has no older version, T2 has to wait for T1 to release the lock. That is why it only reduces the probability of blocking.",[11,120,121],{},"Recall that in Chapter 4, recoverability required the operation sequences passed from VM to DM to satisfy two rules:",[31,123,124],{},[11,125,126,127,130],{},"Rule 1: An ongoing transaction must not read data produced by any other uncommitted transaction.",[128,129],"br",{},"\nRule 2: An ongoing transaction must not modify data modified or produced by any other uncommitted transaction.",[11,132,133],{},"With 2PL and MVCC, we can see that both conditions are easily satisfied.",[23,135,137],{"id":136},"implementing-records","Implementing Records",[11,139,140],{},"MYDB uses Entry to represent a record’s structure. Although MVCC conceptually provides multiple versions, VM does not implement an Update operation. Field updates are handled by the Table Manager (TBM), which we will cover later. Thus, in VM’s actual implementation, a record has only one version.",[11,142,143],{},"Each record is stored in a Data Item, so Entry only needs to hold a DataItem reference:",[87,145,150],{"className":146,"code":148,"language":149,"meta":96},[147],"language-java","public class Entry {\n    private static final int OF_XMIN = 0;\n    private static final int OF_XMAX = OF_XMIN+8;\n    private static final int OF_DATA = OF_XMAX+8;\n\n    private long uid;\n    private DataItem dataItem;\n    private VersionManager vm;\n\n    public static Entry loadEntry(VersionManager vm, long uid) throws Exception {\n        DataItem di = ((VersionManagerImpl)vm).dm.read(uid);\n        return newEntry(vm, di, uid);\n    }\n\n    public void remove() {\n        dataItem.release();\n    }\n}\n","java",[94,151,148],{"__ignoreMap":96},[11,153,154],{},"We define the data format inside an Entry as follows:",[87,156,159],{"className":157,"code":158,"language":92},[90],"[XMIN] [XMAX] [DATA]\n",[94,160,158],{"__ignoreMap":96},[11,162,163,164,167],{},"XMIN is the ID of the transaction that created this record (version), and XMAX is the ID of the transaction that deleted it. We will explain their roles in the next section. DATA is the record’s actual data. Based on this structure, ",[94,165,166],{"code":166},"wrapEntryRaw()",", called when creating a record, looks like this:",[87,169,172],{"className":170,"code":171,"language":149,"meta":96},[147],"public static byte[] wrapEntryRaw(long xid, byte[] data) {\n    byte[] xmin = Parser.long2Byte(xid);\n    byte[] xmax = new byte[8];\n    return Bytes.concat(xmin, xmax, data);\n}\n",[94,173,171],{"__ignoreMap":96},[11,175,176],{},"To retrieve the record’s data, we likewise parse this structure:",[87,178,181],{"className":179,"code":180,"language":149,"meta":96},[147],"\u002F\u002F 以拷贝的形式返回内容\npublic byte[] data() {\n    dataItem.rLock();\n    try {\n        SubArray sa = dataItem.data();\n        byte[] data = new byte[sa.end - sa.start - OF_DATA];\n        System.arraycopy(sa.raw, sa.start+OF_DATA, data, 0, data.length);\n        return data;\n    } finally {\n        dataItem.rUnLock();\n    }\n}\n",[94,182,180],{"__ignoreMap":96},[11,184,185,186,189],{},"We return a copy of the data here. To modify it, we must first call the DataItem’s ",[94,187,188],{"code":188},"before()"," method, as shown when setting XMAX:",[87,191,194],{"className":192,"code":193,"language":149,"meta":96},[147],"public void setXmax(long xid) {\n    dataItem.before();\n    try {\n        SubArray sa = dataItem.data();\n        System.arraycopy(Parser.long2Byte(xid), 0, sa.raw, sa.start+OF_XMAX, 8);\n    } finally {\n        dataItem.after(xid);\n    }\n}\n",[94,195,193],{"__ignoreMap":96},[11,197,198,200,201,204],{},[94,199,188],{"code":188}," and ",[94,202,203],{"code":203},"after()"," follow the data modification rules established in the DataItem chapter.",[23,206,208],{"id":207},"transaction-isolation-levels","Transaction Isolation Levels",[44,210,212],{"id":211},"read-committed","Read Committed",[11,214,215],{},"As noted above, if the newest version of a record is locked, MYDB returns an older version when another transaction wants to modify or read that record. We can say the latest, locked version is invisible to the other transaction. This gives us the concept of version visibility.",[11,217,218],{},"Version visibility depends on the transaction’s isolation level. The lowest isolation level MYDB supports is read committed: transactions may read only data produced by committed transactions. Chapter 4 explained why we require at least read committed: it prevents cascading rollbacks from conflicting with commit semantics.",[11,220,221],{},"To implement read committed, MYDB maintains the two variables introduced above for each version:",[223,224,225,228],"ul",{},[55,226,227],{},"XMIN: the ID of the transaction that created the version",[55,229,230],{},"XMAX: the ID of the transaction that deleted the version",[11,232,233],{},"XMIN is filled in when the version is created. XMAX is filled in when the version is deleted or a new version appears.",[11,235,236],{},"XMAX also explains why DM has no delete operation. To delete a version, we only need to set its XMAX. The version then becomes invisible to every transaction after XMAX, which is equivalent to deleting it.",[11,238,239],{},"Under read committed, version visibility is determined as follows:",[87,241,244],{"className":242,"code":243,"language":92},[90],"(XMIN == Ti and                             \u002F\u002F 由 Ti 创建且\n    XMAX == NULL                            \u002F\u002F 还未被删除\n)\nor                                          \u002F\u002F 或\n(XMIN is commited and                       \u002F\u002F 由一个已提交的事务创建且\n    (XMAX == NULL or                        \u002F\u002F 尚未删除或\n    (XMAX != Ti and XMAX is not commited)   \u002F\u002F 由一个未提交的事务删除\n))\n",[94,245,243],{"__ignoreMap":96},[11,247,248],{},"If the condition is true, the version is visible to Ti. To find a suitable version for Ti, start from the newest version and check visibility backward, returning the first visible one.",[11,250,251],{},"The following method determines whether a record is visible to transaction t:",[87,253,256],{"className":254,"code":255,"language":149,"meta":96},[147],"private static boolean readCommitted(TransactionManager tm, Transaction t, Entry e) {\n    long xid = t.xid;\n    long xmin = e.getXmin();\n    long xmax = e.getXmax();\n    if(xmin == xid && xmax == 0) return true;\n\n    if(tm.isCommitted(xmin)) {\n        if(xmax == 0) return true;\n        if(xmax != xid) {\n            if(!tm.isCommitted(xmax)) {\n                return true;\n            }\n        }\n    }\n    return false;\n}\n",[94,257,255],{"__ignoreMap":96},[11,259,260],{},"The Transaction structure here provides only an XID.",[44,262,264],{"id":263},"repeatable-read","Repeatable Read",[11,266,267],{},"You probably know the problems with read committed from all those interview questions: non-repeatable reads and phantom reads. Here, we will solve non-repeatable reads.",[11,269,270],{},"A non-repeatable read means a transaction can read the same data item more than once during its execution and get different results. For example, suppose X initially equals 0:",[87,272,275],{"className":273,"code":274,"language":92},[90],"T1 begin\nR1(X) \u002F\u002F T1 读得 0\nT2 begin\nU2(X) \u002F\u002F 将 X 修改为 1\nT2 commit\nR1(X) \u002F\u002F T1 读的 1\n",[94,276,274],{"__ignoreMap":96},[11,278,279],{},"T1 reads X twice and gets different values. To avoid this, we need a stricter isolation level: repeatable read.",[11,281,282],{},"The problem arises because T1’s second read sees the value changed by T2, which has since committed. We can therefore impose this rule:",[31,284,285],{},[11,286,287],{},"A transaction may read only data versions produced by transactions that had already finished when it began.",[11,289,290],{},"This adds the requirement that a transaction ignore:",[52,292,293,296],{},[55,294,295],{},"Data from transactions that began after it.",[55,297,298],{},"Data from transactions that were still active when it began.",[11,300,301],{},"For the first, simply compare transaction IDs. For the second, when Ti begins, record all currently active transactions as SP(Ti). If a record version’s XMIN is in SP(Ti), that version must also be invisible to Ti.",[11,303,304],{},"The repeatable-read visibility logic is therefore:",[87,306,309],{"className":307,"code":308,"language":92},[90],"(XMIN == Ti and                 \u002F\u002F 由 Ti 创建且\n (XMAX == NULL                  \u002F\u002F 尚未被删除\n))\nor                              \u002F\u002F 或\n(XMIN is commited and           \u002F\u002F 由一个已提交的事务创建且\n XMIN \u003C XID and                 \u002F\u002F 这个事务小于 Ti 且\n XMIN is not in SP(Ti) and      \u002F\u002F 这个事务在 Ti 开始前提交且\n (XMAX == NULL or               \u002F\u002F 尚未被删除或\n  (XMAX != Ti and               \u002F\u002F 由其他事务删除但是\n   (XMAX is not commited or     \u002F\u002F 这个事务尚未提交或\nXMAX > Ti or                    \u002F\u002F 这个事务在 Ti 开始之后才开始或\nXMAX is in SP(Ti)               \u002F\u002F 这个事务在 Ti 开始前还未提交\n))))\n",[94,310,308],{"__ignoreMap":96},[11,312,313],{},"We need a structure representing a transaction to store this snapshot:",[87,315,318],{"className":316,"code":317,"language":149,"meta":96},[147],"public class Transaction {\n    public long xid;\n    public int level;\n    public Map\u003CLong, Boolean> snapshot;\n    public Exception err;\n    public boolean autoAborted;\n\n    public static Transaction newTransaction(long xid, int level, Map\u003CLong, Transaction> active) {\n        Transaction t = new Transaction();\n        t.xid = xid;\n        t.level = level;\n        if(level != 0) {\n            t.snapshot = new HashMap\u003C>();\n            for(Long x : active.keySet()) {\n                t.snapshot.put(x, true);\n            }\n        }\n        return t;\n    }\n\n    public boolean isInSnapshot(long xid) {\n        if(xid == TransactionManagerImpl.SUPER_XID) {\n            return false;\n        }\n        return snapshot.containsKey(xid);\n    }\n}\n",[94,319,317],{"__ignoreMap":96},[11,321,322],{},"The constructor’s active argument contains all currently active transactions. Visibility under repeatable read is then checked as follows:",[87,324,327],{"className":325,"code":326,"language":149,"meta":96},[147],"private static boolean repeatableRead(TransactionManager tm, Transaction t, Entry e) {\n    long xid = t.xid;\n    long xmin = e.getXmin();\n    long xmax = e.getXmax();\n    if(xmin == xid && xmax == 0) return true;\n\n    if(tm.isCommitted(xmin) && xmin \u003C xid && !t.isInSnapshot(xmin)) {\n        if(xmax == 0) return true;\n        if(xmax != xid) {\n            if(!tm.isCommitted(xmax) || xmax > xid || t.isInSnapshot(xmax)) {\n                return true;\n            }\n        }\n    }\n    return false;\n}\n",[94,328,326],{"__ignoreMap":96},{"title":96,"searchDepth":330,"depth":330,"links":331},4,[332,334,338,339],{"id":25,"depth":333,"text":26},3,{"id":41,"depth":333,"text":42,"children":335},[336,337],{"id":46,"depth":330,"text":47},{"id":108,"depth":330,"text":109},{"id":136,"depth":333,"text":137},{"id":207,"depth":333,"text":208,"children":340},[341,342],{"id":211,"depth":330,"text":212},{"id":263,"depth":330,"text":264},[344],"projects","2021-12-18 14:58:00","VM uses two-phase locking to ensure serializable schedules and introduces multiversion concurrency control (MVCC) to eliminate blocking between reads and writes. This chapter also defines conflicts between database operations, focusing on the interaction between updates and reads as a foundation for understanding transaction isolation levels.",false,"md","https:\u002F\u002Fblog-img.774352199.xyz\u002F8YzotA.webp",{"slots":351},{},true,"\u002Fprojects\u002Fmydb\u002Fmydb6",null,{"text":356,"minutes":357,"time":358,"words":359},"9 min read",8.64,518400,1728,{"title":5,"description":346},"Implement MYDB record visibility with XMIN, XMAX, and active-transaction snapshots, explaining two-phase locking, MVCC, read committed, and repeatable read.",{"loc":353},"posts\u002Fprojects\u002Fmydb\u002Fmydb6",[365,366,109,367,368],"MYDB","Java","Transaction isolation","Two-phase locking","tech","m9kGPvkaVoWXZ4DPyljkQhKR_uUe0V9oLBzDj_rL7vs",[372,390,406,424,441,460,478,496,514,530,546,561,577,593,610,628,643,660,674,690,707,724,740,757,773,792,808,824,842,856,874,891,907,923,937,952,966,981,996,1010,1024,1038,1042,1056,1067],{"categories":373,"date":375,"description":376,"image":377,"path":378,"readingTime":379,"recommend":354,"tags":384,"title":389,"type":369},[374],"daily","2024-09-01 22:03:10","Chronic gastritis has been a long, uneven journey: stomach trouble throughout childhood, a surprising reprieve at university, then a return of symptoms after years of late nights and drinking. Frequent nausea and reflux eventually became too much to live with. After repeated examinations and some reflection, I finally began taking the recovery process seriously.","https:\u002F\u002Fblog-img.774352199.xyz\u002F0Hr9l5.webp","\u002Fdaily\u002Fanti-chronic-gastritis",{"text":380,"minutes":381,"time":382,"words":383},"4 min read",3.08,184800,616,[385,386,387,388],"Chronic gastritis","Medical care experiences","Gastroscopy","Health journal","My Journey with Chronic Gastritis",{"categories":391,"date":392,"description":393,"image":394,"path":395,"readingTime":396,"recommend":354,"tags":400,"title":405,"type":369},[374],"2022-04-11 00:13:13","In The Three-Body Problem, Liu Cixin uses an immense historical canvas to explore the relationship between individuals and the collective. His doubts about Western democracy and the majority’s ability to determine its own fate run through the trilogy. Heroes struggle and sacrifice, only to see their work swept aside by history. Beginning with the Cultural Revolution, the story sets up a conflict between exceptional individuals and the ordinary masses, raising uncomfortable questions about humanity and society.","https:\u002F\u002Fblog-img.774352199.xyz\u002FLTzbFP.webp","\u002Fdaily\u002Fpeople-in-three-body",{"text":356,"minutes":397,"time":398,"words":399},8.635,518100,1727,[401,402,403,404],"The Three-Body Problem","Liu Cixin","Science fiction","Reading notes","The “Majority” in The Three-Body Problem",{"categories":407,"date":408,"description":409,"image":410,"path":411,"readingTime":412,"recommend":354,"tags":417,"title":423,"type":369},[374],"2024-01-04 02:06:51","My learning goals for 2024: reach N2 in Japanese, finish SICP and TAPL, build a kernel with full POSIX support, and update the blog theme. A challenging list, but a clear direction for the year.","https:\u002F\u002Fblog-img.774352199.xyz\u002FV3rSQC.webp","\u002Fdaily\u002Fplan2024",{"text":413,"minutes":414,"time":415,"words":416},"1 min read",0.15,9000,30,[418,419,420,421,422],"Annual planning","Learning Japanese","SICP","TAPL","Operating systems","My Learning Plan for 2024",{"categories":425,"date":426,"description":427,"image":428,"path":429,"readingTime":430,"recommend":354,"tags":435,"title":440,"type":369},[374],"2024-09-28 16:26:00","Three years at ByteDance have made time feel strangely accelerated. Amid the changes, I have still managed to hold on to some mental balance. Looking back at the new graduate gazing at distant mountains from the balcony of our Hangzhou office, I can trace how curiosity, workplace challenges, and shifting expectations taught me to find a rhythm of my own.","https:\u002F\u002Fblog-img.774352199.xyz\u002FhnCaht.webp","\u002Fdaily\u002Fwork-for-3-years",{"text":431,"minutes":432,"time":433,"words":434},"10 min read",9.74,584400,1948,[436,437,438,439],"ByteDance","Software engineering careers","Career retrospective","Mental health","Working at ByteDance for Three Years and Staying Somewhat Sane Is Not Entirely Impossible",{"categories":442,"date":444,"description":445,"image":446,"path":447,"readingTime":448,"recommend":354,"tags":453,"title":459,"type":369},[443],"fiddling","2025-05-28 22:09:00","After moving my blog to Astro, the usual Google Analytics integration no longer fit its performance goals. Adding event-reporting JavaScript directly to the head works, but hurts page performance. I used partytown to move the scripts off the main thread so they would not interfere with loading. With a few adjustments to the example code, Google Analytics finally worked, balancing performance with analytics.","https:\u002F\u002Fblog-img.774352199.xyz\u002FQ0w4RN.webp","\u002Ffiddling\u002Fastro-google-tag-manager",{"text":449,"minutes":450,"time":451,"words":452},"2 min read",1.785,107100,357,[454,455,456,457,458],"Astro","Google Analytics","Google Tag Manager","Partytown","Web analytics","Adding Google Analytics to Astro with Tag Manager",{"categories":461,"date":462,"description":463,"image":464,"path":465,"readingTime":466,"recommend":471,"tags":472,"title":477,"type":369},[443],"2023-04-08 13:16:36","Designing a new programming language is challenging and fun. Setting aside complicated compiler theory and implementation details to focus on where code runs helps clarify how languages are built. Starting from the RISC-VI instruction set, this discussion explores the underlying architecture, layered computer systems, and virtual-machine model, reflecting on the nature of programming languages as well as their implementation.","https:\u002F\u002Fblog-img.774352199.xyz\u002FuO420B.webp","\u002Ffiddling\u002Fchitchat-about-programming-language",{"text":467,"minutes":468,"time":469,"words":470},"15 min read",14.275,856500,2855,2,[473,474,475,476],"Programming language design","Type systems","Compiler design","RISC-V","Some Thoughts on Programming Languages",{"categories":479,"date":480,"description":481,"image":482,"path":483,"readingTime":484,"recommend":330,"tags":489,"title":495,"type":369},[443],"2025-04-18 16:43:12","My girlfriend moved from Beijing to Shanghai for work, and I helped arrange broadband too. Shanghai Telecom’s 500M connection costs more than a 1000M line in Hangzhou, frustratingly. I set out to connect the two cities’ networks: transparent proxying in Shanghai, selected traffic exiting through Hangzhou, and access between both LANs. Hangzhou already had a simple setup with a software router and an AP, configured to route my everyday traffic home and ready for the next networking adventure.","https:\u002F\u002Fblog-img.774352199.xyz\u002FO6cAGh.webp","\u002Ffiddling\u002Fcross-city-network-setup",{"text":485,"minutes":486,"time":487,"words":488},"5 min read",4.865,291900,973,[490,491,492,493,494],"Tailscale","mihomo","Site-to-site networking","Transparent proxy","Home networking","Connecting My Shanghai and Hangzhou Networks",{"categories":497,"date":498,"description":499,"image":500,"path":501,"readingTime":502,"recommend":354,"tags":507,"title":513,"type":369},[443],"2021-12-27 00:09:00","The labs are an essential part of learning CSAPP, but setting up Linux can be discouraging. Virtual machines bring installation errors, compatibility problems, and broken networking. WSL (Windows Subsystem for Linux), especially on Windows 10 version 2004 and later, provides a simpler, more direct Linux environment without the complexity and performance bottlenecks of a traditional VM.","https:\u002F\u002Fblog-img.774352199.xyz\u002FvqOC7N.webp","\u002Ffiddling\u002Fcsapplab0",{"text":503,"minutes":504,"time":505,"words":506},"6 min read",5.295,317700,1059,[508,509,510,511,512],"CSAPP","WSL2","Linux","GDB","Lab environment","Setting Up the CSAPP Lab Environment",{"categories":515,"date":516,"description":517,"image":518,"path":519,"readingTime":520,"recommend":354,"tags":525,"title":529,"type":369},[443],"2024-07-13 17:49:00","Using Debian as a side router offers a more stable and flexible alternative without depending on OpenWrt and LuCI. Configuring Debian directly gives you greater control over the system and avoids the limitations and instability of a GUI. Compared with common side-router setups, this approach makes transparent proxying more reliable and offers another option for those who value performance and efficiency.","https:\u002F\u002Fblog-img.774352199.xyz\u002FpPRU5x.webp","\u002Ffiddling\u002Fdebian-as-bypass-router",{"text":521,"minutes":522,"time":523,"words":524},"12 min read",11.79,707400,2358,[526,527,491,528,493],"Debian","Side router","AdGuard Home","Using Debian as a Side Router",{"categories":531,"date":532,"description":533,"image":534,"path":535,"readingTime":536,"recommend":354,"tags":540,"title":545,"type":369},[443],"2024-08-16 23:53:00","This FakeIP-based transparent proxy design addresses the single point of failure, poor performance, and awkward port forwarding of a traditional side router. Switching to the sing-box proxy core improves forwarding performance and simplifies configuration, with broader protocol support and better optimization than the previous Clash setup. Clash can implement the same design, but sing-box provides a flexible alternative.","https:\u002F\u002Fblog-img.774352199.xyz\u002FS2HHD5.webp","\u002Ffiddling\u002Ffake-ip-based-transparent-proxy",{"text":431,"minutes":537,"time":538,"words":539},9.395,563700,1879,[541,542,493,543,544],"FakeIP","sing-box","Policy-based routing","Traffic routing","Routing Transparent Proxy Traffic with FakeIP",{"categories":547,"date":548,"description":549,"image":550,"path":551,"readingTime":552,"recommend":354,"tags":556,"title":560,"type":369},[443],"2024-08-15 23:50:00","Port forwarding on the main router often stops working when a side router is introduced. Setting the side router as the gateway changes the forwarding path, breaking mappings that previously relied on the main router. A gateway translates addresses and forwards traffic from the internal network to the outside, and each internal device needs one to communicate externally. Understanding this mechanism helps explain how to fix the forwarding problem.","https:\u002F\u002Fblog-img.774352199.xyz\u002FmRqws9.webp","\u002Ffiddling\u002Ffix-port-forward-in-bypass-router",{"text":380,"minutes":553,"time":554,"words":555},3.03,181800,606,[527,557,558,559],"Port forwarding","NAT","Network troubleshooting","Fixing Port Forwarding with a Side Router",{"categories":562,"date":563,"description":564,"image":565,"path":566,"readingTime":567,"recommend":354,"tags":572,"title":576,"type":369},[443],"2023-02-02 23:24:55","Inspiration struck during Chinese New Year: an article read on the train about running Go on bare metal sparked an interest in low-level system interfaces. Its successful implementation suggested exciting possibilities for combining a high-level language with an OS. Further research revealed earlier work on the idea, and that growing enthusiasm became a project full of anticipation that ultimately did not work out.","https:\u002F\u002Fblog-img.774352199.xyz\u002FxB1Ni5.webp","\u002Ffiddling\u002Fgo-os",{"text":568,"minutes":569,"time":570,"words":571},"8 min read",7.29,437400,1458,[573,476,422,574,575],"Go","Bare-metal programming","Runtime","A Project That Failed: Seven Not-So-Happy Days over Chinese New Year",{"categories":578,"date":579,"description":580,"image":581,"path":582,"readingTime":583,"recommend":354,"tags":588,"title":592,"type":369},[443],"2022-08-15 01:05:01","While refactoring a system, converting entities between layers made deep copying surprisingly awkward. A product VO in the view layer, an entity in the domain layer, and a PO in the persistence layer can look nearly identical, yet small type differences complicate direct conversion. I used reflection to build a general conversion method, reducing repetitive assembler methods and making the code more maintainable and flexible.","https:\u002F\u002Fblog-img.774352199.xyz\u002FBlhm0I.webp","\u002Ffiddling\u002Fgolang-deepcopy-between-different-type",{"text":584,"minutes":585,"time":586,"words":587},"3 min read",2.855,171300,571,[573,589,590,591],"Reflection","Deep copy","Struct conversion","Deep Copying Between Different Struct Types in Go",{"categories":594,"date":595,"description":596,"image":597,"path":598,"readingTime":599,"recommend":354,"tags":603,"title":609,"type":369},[443],"2025-03-31 23:51:00","Periodically syncing heart-rate data from Apple Health to a server and visualizing it in Grafana provides an intuitive way to monitor it. Health Auto Export sends the data to an HTTP endpoint through its REST API automation, the server stores it in InfluxDB, and Grafana presents a clear dashboard for tracking and analyzing personal heart-rate changes.","https:\u002F\u002Fblog-img.774352199.xyz\u002FF4qD2T.webp","\u002Ffiddling\u002Fheart-rate-to-grafana",{"text":584,"minutes":600,"time":601,"words":602},2.45,147000,490,[604,605,606,607,608],"Apple Watch","Health Auto Export","InfluxDB","Grafana","Heart rate monitoring","My Heart Beats for U: Visualizing Heart Rate in Grafana",{"categories":611,"date":612,"description":613,"image":614,"path":615,"readingTime":616,"recommend":620,"tags":621,"title":627,"type":369},[443],"2025-06-10 20:18:00","macOS and iPadOS 26 introduce the Liquid Glass design language, refreshing icons and windows with a more modern look. Windowed apps on iPad are a step toward making it a productivity device. The transparent Control Center and the integration of Launchpad have been controversial, however, and the experience still needs work. Despite its shortcomings, this update lays groundwork for a promising future.","https:\u002F\u002Fblog-img.774352199.xyz\u002FTPSaLE.webp","\u002Ffiddling\u002Fmacos-26-trial",{"text":380,"minutes":617,"time":618,"words":619},3.305,198300,661,5,[622,623,624,625,626],"macOS 26","iPadOS 26","Liquid Glass","Apple Intelligence","Operating system impressions","Trying Out macOS 26 and iPadOS 26",{"categories":629,"date":630,"description":631,"image":632,"path":633,"readingTime":634,"recommend":354,"tags":638,"title":642,"type":369},[443],"2026-06-11 10:00:00","Another WWDC brings new Apple Intelligence features in macOS 27. The workarounds from macOS 26 no longer get through, so the battle of wits with Apple continues.","https:\u002F\u002Fblog-img.774352199.xyz\u002FfOFucm.webp","\u002Ffiddling\u002Fmacos-27-apple-intelligence-chatgpt",{"text":503,"minutes":635,"time":636,"words":637},5.1,306000,1020,[639,625,640,641],"macOS 27","ChatGPT","Mainland China Mac","Getting Apple Intelligence Working on a China-Market Mac: Region Changes and Extracting ChatGPT",{"categories":644,"date":645,"description":646,"image":647,"path":648,"readingTime":649,"recommend":354,"tags":653,"title":659,"type":369},[443],"2025-07-20 23:32:00","MoonTV is a new video aggregation platform built with Next.js and React to make following shows convenient. It began as an attempt to improve LibreTV and has attracted substantial attention and usage over several months of development. Cursor made development efficient, although multi-platform support and complex data dependencies posed challenges. As its user base grows, MoonTV continues improving in response to feedback.","https:\u002F\u002Fblog-img.774352199.xyz\u002FnIeONi.webp","\u002Ffiddling\u002Fmoontv-vibe-coding",{"text":503,"minutes":650,"time":651,"words":652},5.76,345600,1152,[654,655,656,657,658],"MoonTV","LunaTV","Vibe Coding","Cursor","AI-assisted development","MoonTV: An Experiment in Vibe Coding",{"categories":661,"date":662,"description":663,"image":664,"path":665,"readingTime":666,"recommend":354,"tags":670,"title":673,"type":369},[443],"2024-10-07 16:51:00","BGP-based routing for Chinese and overseas IPs makes transparent proxying more efficient and accurate. Marking overseas destinations with FakeIP lets the main router route traffic more intelligently for smoother connectivity. The sing-box DNS configuration is also refined to handle queries more flexibly and efficiently, improving the overall network experience.","https:\u002F\u002Fblog-img.774352199.xyz\u002FMOmM1s.webp","\u002Ffiddling\u002Fmore-accurate-chnroute",{"text":380,"minutes":667,"time":668,"words":669},3.805,228300,761,[671,672,543,544],"BGP","IP address database","More Accurate Routing for Chinese and Overseas IPs with BGP",{"categories":675,"date":676,"description":677,"image":678,"path":679,"readingTime":680,"recommend":354,"tags":684,"title":689,"type":369},[443],"2025-12-14 14:31:00","A friend’s comment got me interested in simulation games. After buying Microsoft Flight Simulator, I discovered streamed maps and models, another account login, oddly hidden tutorials, and awkward keyboard controls. A flight stick and some tinkering with Pico VR finally rounded out the experience.","https:\u002F\u002Fblog-img.774352199.xyz\u002FlfhEuE.webp","\u002Ffiddling\u002Fmsfs2024-joystick-and-pico",{"text":485,"minutes":681,"time":682,"words":683},4.68,280800,936,[685,686,687,688],"Microsoft Flight Simulator 2024","Thrustmaster TCA","PICO VR","Flight simulation","Adventures with Microsoft Flight Simulator 2024",{"categories":691,"date":692,"description":693,"image":694,"path":695,"readingTime":696,"recommend":354,"tags":700,"title":706,"type":369},[443],"2025-06-05 23:26:00","My frequent phone changes took me from OnePlus to iPhone, and from enjoying tinkering to relying on an ecosystem. At my girlfriend’s suggestion, I recently bought an OPPO Find X8 Ultra to improve my photos. Migrating apps out of Apple’s ecosystem reminded me how uneven Android’s app selection remains and how difficult finding replacements can be. A month of migration has been an exercise in friction and adaptation between platforms.","https:\u002F\u002Fblog-img.774352199.xyz\u002F19NIhZ.webp","\u002Ffiddling\u002Fone-month-using-android",{"text":568,"minutes":697,"time":698,"words":699},7.61,456600,1522,[701,702,703,704,705],"Android","OPPO","iOS","Smartphone impressions","Ecosystem migration","One Month After Switching to Android",{"categories":708,"date":709,"description":710,"image":711,"path":712,"readingTime":713,"recommend":354,"tags":717,"title":723,"type":369},[443],"2026-05-11 22:43:00","I found a trip-planning tool on GitHub Trending and wanted to host my own instance. Since I was getting a new VPS anyway, I might as well install a little extra. Well, quite a lot extra.","https:\u002F\u002Fblog-img.774352199.xyz\u002FBBdDWW.webp","\u002Ffiddling\u002Fone-trek-twenty-stacks",{"text":503,"minutes":714,"time":715,"words":716},5.735,344100,1147,[718,719,720,721,722],"TREK","Docker Compose","Dockge","VPS","Self-hosting","One TREK, Twenty Stacks",{"categories":725,"date":726,"description":727,"image":728,"path":729,"readingTime":730,"recommend":354,"tags":735,"title":739,"type":369},[443],"2025-01-16 23:09:00","OPNsense is an open-source firewall and router with an attractive interface and a comprehensive feature set. After trying several routing setups, I came to appreciate its potential for transparent proxying and traffic routing. Combining it with BGP-based routing offers better security and stability, while its automatically updated IP lists make network management more convenient.","https:\u002F\u002Fblog-img.774352199.xyz\u002FxA8C1E.webp","\u002Ffiddling\u002Fopnsense-transparent-proxy",{"text":731,"minutes":732,"time":733,"words":734},"7 min read",6.47,388200,1294,[736,737,491,738,493,544],"OPNsense","FreeBSD","tun2socks","Transparent Proxying and Traffic Routing with OPNsense",{"categories":741,"date":742,"description":743,"image":744,"path":745,"readingTime":746,"recommend":333,"tags":750,"title":756,"type":369},[443],"2025-03-15 20:35:00","Distinguishing user-defined type names from ordinary variables is a challenge during parsing. A statement such as `a*b;` can be either an arithmetic expression or a declaration. Grammar rules, especially those involving type specifiers, can misidentify variables as types, affecting correctness and readability. The prevalence of declarations without initializers makes this ambiguity especially common.","https:\u002F\u002Fblog-img.774352199.xyz\u002F2VKHK9.webp","\u002Ffiddling\u002Fparser-type-variable-ambiguity",{"text":568,"minutes":747,"time":748,"words":749},7.475,448500,1495,[751,752,753,754,755],"Parsing","GLR","Symbol table","Scope","Disambiguation","Resolving Type Name and Variable Name Ambiguity in Parsing",{"categories":758,"date":759,"description":760,"image":761,"path":762,"readingTime":763,"recommend":354,"tags":767,"title":772,"type":369},[443],"2023-05-24 17:51:09","To install the RISC-V toolchain, first obtain the riscv-gnu-toolchain source. Using `--depth=1` when cloning reduces the download size. Check the README’s Prerequisites section and install the required dependencies. On Debian, a simple package installation command prepares the environment for building the toolchain.","https:\u002F\u002Fblog-img.774352199.xyz\u002FrWNOKx.webp","\u002Ffiddling\u002Fspike-install",{"text":449,"minutes":764,"time":765,"words":766},1.92,115200,384,[476,768,769,770,771],"Spike","riscv-pk","Cross-compilation","Toolchain","Installing the RISC-V Toolchain and Emulator",{"categories":774,"date":775,"description":776,"image":777,"path":778,"readingTime":779,"recommend":783,"tags":784,"title":791,"type":369},[443],"2026-09-09 23:59:00","This counts as NTR too, surely.","https:\u002F\u002Fblog-img.774352199.xyz\u002FNDPUwc.webp","\u002Ffiddling\u002Fsteamdeck-switch-60fps",{"text":568,"minutes":780,"time":781,"words":782},7.345,440700,1469,7,[785,786,787,788,789,790],"Steam Deck","Nintendo Switch","EmuDeck","Eden","Lossless Scaling","Frame generation","A Second Life for the Steam Deck: Switch Emulation and Frame Generation at 60 FPS",{"categories":793,"date":794,"description":795,"image":796,"path":797,"readingTime":798,"recommend":354,"tags":802,"title":807,"type":369},[443],"2024-06-23 15:31:32","The GFW does more than monitor an exit gateway: it inspects international traffic through passive taps, copying inbound and outbound IP packets to a cluster for analysis and filtering. Understanding where and how this happens matters when studying censorship circumvention. Examining the GFW’s network topology helps explain its blocking mechanisms and how to work around them.","https:\u002F\u002Fblog-img.774352199.xyz\u002FsOpJuL.webp","\u002Ffiddling\u002Ftech-about-gfw",{"text":521,"minutes":799,"time":800,"words":801},11.885,713100,2377,[803,804,805,806],"GFW","DNS poisoning","TCP","Internet censorship","How the Great Firewall Works",{"categories":809,"date":810,"description":811,"image":812,"path":813,"readingTime":814,"recommend":354,"tags":818,"title":823,"type":369},[443],"2022-04-16 00:01:28","In Java, using `this` can prevent the compiler from optimizing constants. Although `ab1` and `ab2` in this example appear to refer to the same static final variable `s`, comparing them produces different results. `ab1` concatenates a direct reference to the static variable, while `ab2` accesses it through `this`, preventing the same constant propagation optimization. This illustrates how a small syntactic difference can change compilation behavior.","https:\u002F\u002Fblog-img.774352199.xyz\u002FgKtkYe.webp","\u002Ffiddling\u002Fthis-in-javac-string-concat",{"text":584,"minutes":815,"time":816,"words":817},2.305,138300,461,[366,819,820,821,822],"javac","String concatenation","Constant propagation","Bytecode","How Java’s this Keyword Can Prevent Compile-Time Constant Propagation",{"categories":825,"date":826,"description":827,"image":828,"path":829,"readingTime":830,"recommend":354,"tags":835,"title":841,"type":369},[443],"2025-01-29 21:58:00","A microblog lets you share short thoughts whenever they occur, without the overhead of publishing a full static-blog post. This implementation uses Cloudflare Workers for the backend and KV for storage and management. A Vue component embedded in VitePress displays the updates, adding a lively, interactive element to the blog.","https:\u002F\u002Fblog-img.774352199.xyz\u002FhZX6hr.webp","\u002Ffiddling\u002Fvitepress-memos-component",{"text":831,"minutes":832,"time":833,"words":834},"19 min read",18.96,1137600,3792,[836,837,838,839,840],"VitePress","Vue","Cloudflare Workers","Cloudflare KV","Microblogging","Adding a Microblog to VitePress",{"categories":843,"date":844,"description":845,"image":846,"path":847,"readingTime":848,"recommend":354,"tags":852,"title":855,"type":369},[443],"2025-03-15 16:24:00","A Telegram notification on an ordinary afternoon introduced a tempting VPS deal: a direct China Telecom CN2 route and 2.5G bandwidth. The plan includes IPv6, useful for unlocking streaming services, but not every connection needs to go through WARP. My previous script was convenient, yet its effects on speed and traffic routing called for a more flexible solution.","https:\u002F\u002Fblog-img.774352199.xyz\u002FMcjrrF.webp","\u002Ffiddling\u002Fvps-warp-ipv6",{"text":584,"minutes":849,"time":850,"words":851},2.34,140400,468,[853,854,721,543,544],"Cloudflare WARP","IPv6","Routing Selected VPS Traffic Through WARP over IPv6",{"categories":857,"date":858,"description":859,"image":860,"path":861,"readingTime":862,"recommend":866,"tags":867,"title":873,"type":369},[443],"2026-08-17 23:59:21","The more I tinker, the more I want to tinker. Still going strong in my old age, still going strong!","https:\u002F\u002Fblog-img.774352199.xyz\u002FqfxB0h.webp","\u002Ffiddling\u002Fxiaomi17-root-and-hide-root",{"text":485,"minutes":863,"time":864,"words":865},4.545,272700,909,6,[868,869,870,871,872],"Xiaomi 17","Bootloader","Android Root","Firmware flashing","Root hiding","Making the Xiaomi 17 My Daily Driver: Unlocking, Flashing, Rooting, and Hiding Root",{"categories":875,"date":877,"description":878,"image":879,"path":880,"readingTime":881,"recommend":354,"tags":885,"title":890,"type":369},[876],"notes","2022-01-20 22:29:00","Lab 1 asks us to implement a MapReduce system with two core components: a master and workers. This requires a good command of Go RPC and concurrent programming, along with a thorough understanding of the MapReduce workflow. I built two versions, starting with mutex locks and then moving to a more elegant channel-based implementation without explicit locks, whose design is simpler and clearer. The key to understanding the lab is to read the relevant documentation carefully, especially the flowcharts and explanations.","https:\u002F\u002Fblog-img.774352199.xyz\u002FibVwPJ.webp","\u002Fnotes\u002F65840\u002Fmapreducelab",{"text":568,"minutes":882,"time":883,"words":884},7.21,432600,1442,[886,887,573,888,889],"MIT 6.5840","MapReduce","RPC","Concurrent programming","6.5840 Lab 1: MapReduce",{"categories":892,"date":893,"description":894,"image":895,"path":896,"readingTime":897,"recommend":354,"tags":901,"title":906,"type":369},[876],"2022-01-16 17:32:00","MapReduce is an efficient parallel computing model designed to simplify processing large datasets. By defining the two key functions, Map and Reduce, users can break complex tasks into simple operations. The framework automatically handles data distribution and task scheduling, allowing developers to focus on the algorithm rather than low-level details. Its widespread use in distributed systems demonstrates its flexibility and practical value.","https:\u002F\u002Fblog-img.774352199.xyz\u002FApIDdC.webp","\u002Fnotes\u002F65840\u002Fmapreducepaper",{"text":485,"minutes":898,"time":899,"words":900},4.12,247200,824,[887,902,903,904,905],"Distributed systems","Paper notes","Parallel computing","Fault tolerance","Reading the MapReduce Paper",{"categories":908,"date":909,"description":910,"image":911,"path":912,"readingTime":913,"recommend":354,"tags":918,"title":922,"type":369},[876],"2022-12-16 02:06:10","Lab 2A focuses on implementing Raft leader election and heartbeats so that elections and term changes work correctly even under extreme conditions. The lab has four stages and lays the foundation for the distributed key-value store that follows. A design without explicit locks simplifies the Raft struct. The lab instructions provide the necessary background, but compared with the previous lab, this one relies on almost no reference material and places greater emphasis on implementing the system independently.","https:\u002F\u002Fblog-img.774352199.xyz\u002Fc11Uk4.webp","\u002Fnotes\u002F65840\u002Fraftlab2a",{"text":914,"minutes":915,"time":916,"words":917},"13 min read",12.235,734100,2447,[886,919,573,920,921],"Raft","Leader election","Distributed consensus","6.5840 Lab 2A: Leader Election",{"categories":924,"date":925,"description":926,"image":927,"path":928,"readingTime":929,"recommend":354,"tags":934,"title":936,"type":369},[876],"2022-12-03 21:40:09","Raft is a consensus algorithm designed to improve the efficiency of log replication. It is particularly suited to clusters of machines, allowing them to keep providing service even when some machines fail. It uses the replicated state machine model: logs record the order of commands so that every machine in the cluster can reach the same state. In Search of an Understandable Consensus Algorithm explores Raft’s design and compares it with Paxos, highlighting its understandability and providing a foundation for building reliable large-scale software systems. These reading notes aim to help explain the paper’s core concepts and their applications.","https:\u002F\u002Fblog-img.774352199.xyz\u002F7mmvIZ.webp","\u002Fnotes\u002F65840\u002Freftextendedpaper",{"text":930,"minutes":931,"time":932,"words":933},"16 min read",15.98,958800,3196,[919,921,935,903],"Log replication","Reading the Raft Paper",{"categories":938,"date":939,"description":940,"image":941,"path":942,"readingTime":943,"recommend":947,"tags":948,"title":951,"type":369},[344],"2021-11-27 14:43:00","MYDB is a personal project exploring and implementing the fundamentals of databases, built in my spare time over a little more than half a month. I picked up some basic knowledge in my university database systems course, though during my internship I mostly used the classes as an excuse to slack off. My candid answers in an interview did not cause too much trouble, but they did make me reconsider what I knew about databases and decide to learn through hands-on practice. That was how this project began.","https:\u002F\u002Fblog-img.774352199.xyz\u002Fxfci2J.webp","\u002Fprojects\u002Fmydb\u002Fmydb0",{"text":485,"minutes":944,"time":945,"words":946},4.15,249000,830,1,[365,366,949,950],"Database implementation","Database architecture","MYDB 0. Project Structure and a Few Things I Had to Say",{"categories":953,"date":954,"description":955,"image":956,"path":957,"readingTime":958,"recommend":354,"tags":962,"title":965,"type":369},[344],"2021-11-28 16:10:00","MYDB manages transactions through an XID file. Each transaction has a unique XID, incrementing from 1; XID 0 denotes a super transaction whose state is always committed. TransactionManager maintains this file and records three states: active, committed, and aborted. This mechanism supports accurate transaction state queries and management, providing a foundation for system stability and reliability.","https:\u002F\u002Fblog-img.774352199.xyz\u002FH4zZAK.webp","\u002Fprojects\u002Fmydb\u002Fmydb1",{"text":485,"minutes":959,"time":960,"words":961},4.755,285300,951,[365,366,963,964],"Transaction management","XID","MYDB 1. Starting with the Transaction Manager",{"categories":967,"date":968,"description":969,"image":970,"path":971,"readingTime":972,"recommend":354,"tags":976,"title":980,"type":369},[344],"2021-12-25 18:26:00","MYDB uses a client\u002Fserver architecture similar to MySQL, allowing multiple clients to connect to a server over sockets, execute SQL queries, and receive results. Communication uses a special binary format, though plain text would also be an option for a simpler implementation. The basic transport structure supports effective communication and processing between client and server.","https:\u002F\u002Fblog-img.774352199.xyz\u002FPAHrUZ.webp","\u002Fprojects\u002Fmydb\u002Fmydb10",{"text":485,"minutes":973,"time":974,"words":975},4.305,258300,861,[365,366,977,978,979],"Socket","Client-server architecture","Communication protocol","MYDB 10. Implementing the Server, Client, and Wire Protocol",{"categories":982,"date":983,"description":984,"image":985,"path":986,"readingTime":987,"recommend":354,"tags":991,"title":995,"type":369},[344],"2021-11-30 23:18:00","The Data Manager (DM) bridges higher-level modules and the filesystem, handling paging and caching while ensuring data safety and recovery. Its cache uses reference counting rather than traditional LRU, aiming for a reusable, efficient foundation for subsequent data operations.","https:\u002F\u002Fblog-img.774352199.xyz\u002FWdIGoG.webp","\u002Fprojects\u002Fmydb\u002Fmydb2",{"text":503,"minutes":988,"time":989,"words":990},5.725,343500,1145,[365,366,992,993,994],"Reference counting","Cache design","Shared memory","MYDB 2. A Reference-Counted Cache Framework and Shared Byte Arrays",{"categories":997,"date":998,"description":999,"image":1000,"path":1001,"readingTime":1002,"recommend":354,"tags":1006,"title":1009,"type":369},[344],"2021-12-05 15:28:00","DM abstracts the filesystem into pages and uses them as the unit of reading, writing, and caching. The default page size is 8K, with larger pages available to improve write performance under heavy loads. With the general-purpose cache framework already in place, we now define the page structure and implement efficient page caching.","https:\u002F\u002Fblog-img.774352199.xyz\u002FjlFC4E.webp","\u002Fprojects\u002Fmydb\u002Fmydb3",{"text":485,"minutes":1003,"time":1004,"words":1005},4.7,282000,940,[365,366,1007,1008],"Data pages","Cache management","MYDB 3. Caching and Managing Data Pages",{"categories":1011,"date":1012,"description":1013,"image":1014,"path":1015,"readingTime":1016,"recommend":354,"tags":1020,"title":1023,"type":369},[344],"2021-12-08 22:55:00","Log files are essential to MYDB’s design, allowing data to be recovered after a crash. DM logs every operation on underlying data, forming a continuous sequence of records. Stored in a specific binary format with checksums and individual operation records, these logs let the database accurately reconstruct its data on restart and maintain consistency and integrity.","https:\u002F\u002Fblog-img.774352199.xyz\u002FTRcbsj.webp","\u002Fprojects\u002Fmydb\u002Fmydb4",{"text":568,"minutes":1017,"time":1018,"words":1019},7.885,473100,1577,[365,366,1021,1022],"Database logging","Crash recovery","MYDB 4. Log Files and Recovery Strategies",{"categories":1025,"date":1026,"description":1027,"image":1028,"path":1029,"readingTime":1030,"recommend":354,"tags":1034,"title":1037,"type":369},[344],"2021-12-11 15:16:00","The page index is an important part of DM, optimizing insertions by caching the free space available on each page. It lets higher-level modules quickly locate a suitable page without a lengthy search, making data operations more efficient. Its implementation works closely with the DataItem abstraction to support efficient database operation.","https:\u002F\u002Fblog-img.774352199.xyz\u002F22PSG1.webp","\u002Fprojects\u002Fmydb\u002Fmydb5",{"text":731,"minutes":1031,"time":1032,"words":1033},6.37,382200,1274,[365,366,1035,1036],"Page index","Data management","MYDB 5. The Page Index and the Data Manager",{"categories":1039,"date":345,"description":346,"image":349,"path":353,"readingTime":1040,"recommend":354,"tags":1041,"title":5,"type":369},[344],{"text":356,"minutes":357,"time":358,"words":359},[365,366,109,367,368],{"categories":1043,"date":1044,"description":1045,"image":1046,"path":1047,"readingTime":1048,"recommend":354,"tags":1052,"title":1055,"type":369},[344],"2021-12-23 21:20:00","VM must handle version skipping introduced by MVCC as well as deadlocks. By simply marking a transaction, MYDB can cancel or roll it back and keep data from aborted transactions from affecting others. This design makes concurrent transaction handling more efficient and reliable, avoids the deadlock risks common with traditional 2PL, and improves overall stability and performance.","https:\u002F\u002Fblog-img.774352199.xyz\u002FBF3yDW.webp","\u002Fprojects\u002Fmydb\u002Fmydb7",{"text":568,"minutes":1049,"time":1050,"words":1051},7.265,435900,1453,[365,366,1053,1054],"Deadlock detection","Version management","MYDB 7. Deadlock Detection and the Version Manager",{"categories":1057,"date":1058,"description":1059,"image":1060,"path":1061,"readingTime":1062,"recommend":354,"tags":1063,"title":1066,"type":369},[344],"2021-12-24 21:01:00","MYDB implements a clustered index using a B+ tree. IM interacts directly with the Data Manager (DM), bypassing the Version Manager (VM), so index data is written directly to the database file. This chapter details the binary-tree index structure and its basic node fields, including the leaf flag, key count, and sibling identifier, establishing the framework for indexed lookups.","https:\u002F\u002Fblog-img.774352199.xyz\u002Ff92X4o.webp","\u002Fprojects\u002Fmydb\u002Fmydb8",{"text":485,"minutes":944,"time":945,"words":946},[365,366,1064,1065],"B+ tree","Database indexing","MYDB 8. Index Management",{"categories":1068,"date":1069,"description":1070,"image":1071,"path":1072,"readingTime":1073,"recommend":354,"tags":1077,"title":1080,"type":369},[344],"2021-12-25 15:44:00","The Table Manager (TBM) manages field and table structures. Parser turns SQL-like statements into structured representations, wrapping their information in the corresponding classes to simplify subsequent operations. This chapter also covers MYDB’s SQL syntax as a foundation for understanding the management process.","https:\u002F\u002Fblog-img.774352199.xyz\u002FzOMyv5.webp","\u002Fprojects\u002Fmydb\u002Fmydb9",{"text":503,"minutes":1074,"time":1075,"words":1076},5.035,302100,1007,[365,366,1078,1079],"SQL parsing","Table management","MYDB 9. Field and Table Management",1789914053894]