[{"data":1,"prerenderedAt":1012},["ShallowReactive",2],{"content:\u002Fen\u002Fprojects\u002Fmydb\u002Fmydb7":3,"series:content_en":301},{"id":4,"title":5,"authorship":6,"body":7,"categories":273,"date":275,"description":276,"draft":277,"extension":278,"image":279,"meta":280,"navigation":282,"path":283,"permalink":284,"published":284,"readingTime":285,"recommend":284,"references":284,"seo":290,"seoDescription":291,"seoTitle":284,"sitemap":292,"stem":293,"tags":294,"type":299,"__hash__":300},"content_en\u002Fposts\u002Fprojects\u002Fmydb\u002Fmydb7.md","MYDB 7. Deadlock Detection and the Version Manager","human-only",{"type":8,"value":9,"toc":265},"minimark",[10,22,27,30,34,37,40,51,54,57,60,70,73,81,85,88,91,97,100,106,109,115,118,121,127,130,136,139,145,148,152,155,161,168,174,180,186,192,198,201,207,213,219,225,231,237,243,246,249],[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],{},"This chapter finishes VM. We will look at the version-skipping problem MVCC can introduce, how MYDB avoids deadlocks caused by 2PL, and how everything comes together in the Version Manager.",[23,31,33],{"id":32},"the-version-skipping-problem","The Version-Skipping Problem",[11,35,36],{},"Before discussing version skipping, a quick aside: MVCC makes canceling or rolling back transactions very easy in MYDB. We only need to mark the transaction as aborted. Under the visibility rules from the previous chapter, a transaction can see data from other transactions only if they have committed. Data produced by an aborted transaction therefore has no effect on other transactions. It is as though that transaction never existed.",[11,38,39],{},"For version skipping, consider the following scenario. X initially has only version x0, and T1 and T2 both use repeatable read:",[41,42,47],"pre",{"className":43,"code":45,"language":46},[44],"language-text","T1 begin\nT2 begin\nR1(X) \u002F\u002F T1 读取 x0\nR2(X) \u002F\u002F T2 读取 x0\nU1(X) \u002F\u002F T1 将 X 更新到 x1\nT1 commit\nU2(X) \u002F\u002F T2 将 X 更新到 x2\nT2 commit\n","text",[48,49,45],"code",{"__ignoreMap":50},"",[11,52,53],{},"This runs without a problem, but the logic is not quite right. T1 updates X from x0 to x1, which is fine. T2, however, updates X from x0 to x2, skipping x1.",[11,55,56],{},"Read committed allows version skipping; repeatable read does not. The solution is straightforward: if Ti needs to modify X, but X has already been modified by a transaction Tj invisible to Ti, require Ti to roll back.",[11,58,59],{},"The previous chapter identified two cases in which Tj is invisible to Ti:",[61,62,63,67],"ol",{},[64,65,66],"li",{},"XID(Tj) > XID(Ti)",[64,68,69],{},"Tj in SP(Ti)",[11,71,72],{},"Checking for version skipping is therefore simple: get the newest committed version of X and check whether its creator is visible to the current transaction:",[41,74,79],{"className":75,"code":77,"language":78,"meta":50},[76],"language-java","public static boolean isVersionSkip(TransactionManager tm, Transaction t, Entry e) {\n    long xmax = e.getXmax();\n    if(t.level == 0) {\n        return false;\n    } else {\n        return tm.isCommitted(xmax) && (xmax > t.xid  t.isInSnapshot(xmax));\n  }\n}\n","java",[48,80,77],{"__ignoreMap":50},[23,82,84],{"id":83},"deadlock-detection","Deadlock Detection",[11,86,87],{},"As discussed previously, 2PL blocks a transaction until the thread holding the lock releases it. We can represent this waiting relationship as a directed edge: Tj waiting for Ti becomes Tj --> Ti. Together, these edges form a graph, which need not be connected. Detecting a deadlock then amounts to checking whether the graph contains a cycle.",[11,89,90],{},"MYDB uses a LockTable object to maintain this graph in memory, with the following structures:",[41,92,95],{"className":93,"code":94,"language":78,"meta":50},[76],"public class LockTable {\n\n    private Map\u003CLong, List\u003CLong>> x2u;  \u002F\u002F 某个 XID 已经获得的资源的 UID 列表\n    private Map\u003CLong, Long> u2x;        \u002F\u002F UID 被某个 XID 持有\n    private Map\u003CLong, List\u003CLong>> wait; \u002F\u002F 正在等待 UID 的 XID 列表\n    private Map\u003CLong, Lock> waitLock;   \u002F\u002F 正在等待资源的 XID 的锁\n    private Map\u003CLong, Long> waitU;      \u002F\u002F XID 正在等待的 UID\n    private Lock lock;\n\n    ...\n}\n",[48,96,94],{"__ignoreMap":50},[11,98,99],{},"Whenever a transaction needs to wait, we try adding an edge and check for deadlocks. If one is detected, we remove and reject the edge and abort the transaction.",[41,101,104],{"className":102,"code":103,"language":78,"meta":50},[76],"\u002F\u002F 不需要等待则返回 null，否则返回锁对象\n\u002F\u002F 会造成死锁则抛出异常\npublic Lock add(long xid, long uid) throws Exception {\n    lock.lock();\n    try {\n        if(isInList(x2u, xid, uid)) {\n            return null;\n        }\n        if(!u2x.containsKey(uid)) {\n            u2x.put(uid, xid);\n            putIntoList(x2u, xid, uid);\n            return null;\n        }\n        waitU.put(xid, uid);\n        putIntoList(wait, xid, uid);\n        if(hasDeadLock()) {\n            waitU.remove(xid);\n            removeFromList(wait, uid, xid);\n            throw Error.DeadlockException;\n        }\n        Lock l = new ReentrantLock();\n        l.lock();\n        waitLock.put(xid, l);\n        return l;\n    } finally {\n        lock.unlock();\n    }\n}\n",[48,105,103],{"__ignoreMap":50},[11,107,108],{},"If add determines that waiting is necessary, it returns a locked Lock object. The caller then attempts to acquire that lock, thereby blocking the thread. For example:",[41,110,113],{"className":111,"code":112,"language":78,"meta":50},[76],"Lock l = lt.add(xid, uid);\nif(l != null) {\n    l.lock();   \u002F\u002F 阻塞在这一步\n    l.unlock();\n}\n",[48,114,112],{"__ignoreMap":50},[11,116,117],{},"Cycle detection is a simple depth-first search, with the caveat that the graph may be disconnected. Give each node a visitation stamp initialized to -1. Then traverse all nodes, starting a DFS at each node whose stamp is not -1. All nodes encountered in one connected graph receive the same number, with different numbers for different graphs. Encountering a previously visited node while traversing a graph indicates a cycle.",[11,119,120],{},"The implementation is simple:",[41,122,125],{"className":123,"code":124,"language":78,"meta":50},[76],"private boolean hasDeadLock() {\n    xidStamp = new HashMap\u003C>();\n    stamp = 1;\n    for(long xid : x2u.keySet()) {\n        Integer s = xidStamp.get(xid);\n        if(s != null && s > 0) {\n            continue;\n        }\n        stamp ++;\n        if(dfs(xid)) {\n            return true;\n        }\n    }\n    return false;\n}\n\nprivate boolean dfs(long xid) {\n    Integer stp = xidStamp.get(xid);\n    if(stp != null && stp == stamp) {\n        return true;\n    }\n    if(stp != null && stp \u003C stamp) {\n        return false;\n    }\n    xidStamp.put(xid, stamp);\n\n    Long uid = waitU.get(xid);\n    if(uid == null) return false;\n    Long x = u2x.get(uid);\n    assert x != null;\n    return dfs(x);\n}\n",[48,126,124],{"__ignoreMap":50},[11,128,129],{},"When a transaction commits or aborts, it can release all its locks and remove itself from the wait-for graph.",[41,131,134],{"className":132,"code":133,"language":78,"meta":50},[76],"public void remove(long xid) {\n    lock.lock();\n    try {\n        List\u003CLong> l = x2u.get(xid);\n        if(l != null) {\n            while(l.size() > 0) {\n                Long uid = l.remove(0);\n                selectNewXID(uid);\n            }\n        }\n        waitU.remove(xid);\n        x2u.remove(xid);\n        waitLock.remove(xid);\n    } finally {\n        lock.unlock();\n    }\n}\n",[48,135,133],{"__ignoreMap":50},[11,137,138],{},"The while loop releases the locks on every resource held by this thread, allowing waiting threads to acquire them:",[41,140,143],{"className":141,"code":142,"language":78,"meta":50},[76],"\u002F\u002F 从等待队列中选择一个 xid 来占用 uid\nprivate void selectNewXID(long uid) {\n    u2x.remove(uid);\n    List\u003CLong> l = wait.get(uid);\n    if(l == null) return;\n    assert l.size() > 0;\n    while(l.size() > 0) {\n        long xid = l.remove(0);\n        if(!waitLock.containsKey(xid)) {\n            continue;\n        } else {\n            u2x.put(uid, xid);\n            Lock lo = waitLock.remove(xid);\n            waitU.remove(xid);\n            lo.unlock();\n            break;\n        }\n    }\n    if(l.size() == 0) wait.remove(uid);\n}\n",[48,144,142],{"__ignoreMap":50},[11,146,147],{},"We try releasing waiters from the beginning of the List, so this is even a fair lock. Simply unlock the Lock object; the application thread can then acquire it and continue.",[23,149,151],{"id":150},"implementing-vm","Implementing VM",[11,153,154],{},"VM exposes its functionality to higher-level modules through the VersionManager interface:",[41,156,159],{"className":157,"code":158,"language":78,"meta":50},[76],"public interface VersionManager {\n    byte[] read(long xid, long uid) throws Exception;\n    long insert(long xid, byte[] data) throws Exception;\n    boolean delete(long xid, long uid) throws Exception;\n\n    long begin(int level);\n    void commit(long xid) throws Exception;\n    void abort(long xid);\n}\n",[48,160,158],{"__ignoreMap":50},[11,162,163,164,167],{},"Its implementation also serves as an Entry cache, extending ",[48,165,166],{"code":166},"AbstractCache\u003CEntry>",". The methods for loading and releasing cache entries are simple:",[41,169,172],{"className":170,"code":171,"language":78,"meta":50},[76],"@Override\nprotected Entry getForCache(long uid) throws Exception {\n    Entry entry = Entry.loadEntry(this, uid);\n    if(entry == null) {\n        throw Error.NullEntryException;\n    }\n    return entry;\n}\n\n@Override\nprotected void releaseForCache(Entry entry) {\n    entry.remove();\n}\n",[48,173,171],{"__ignoreMap":50},[11,175,176,179],{},[48,177,178],{"code":178},"begin()"," starts a transaction, initializes its structure, and stores it in activeTransaction for checks and snapshots:",[41,181,184],{"className":182,"code":183,"language":78,"meta":50},[76],"@Override\npublic long begin(int level) {\n    lock.lock();\n    try {\n        long xid = tm.begin();\n        Transaction t = Transaction.newTransaction(xid, level, activeTransaction);\n        activeTransaction.put(xid, t);\n        return xid;\n    } finally {\n        lock.unlock();\n    }\n}\n",[48,185,183],{"__ignoreMap":50},[11,187,188,191],{},[48,189,190],{"code":190},"commit()"," commits a transaction, mainly freeing the relevant structures, releasing its locks, and updating its state in TM:",[41,193,196],{"className":194,"code":195,"language":78,"meta":50},[76],"@Override\npublic void commit(long xid) throws Exception {\n    lock.lock();\n    Transaction t = activeTransaction.get(xid);\n    lock.unlock();\n    try {\n        if(t.err != null) {\n            throw t.err;\n        }\n    } catch(NullPointerException n) {\n        System.out.println(xid);\n        System.out.println(activeTransaction.keySet());\n        Panic.panic(n);\n    }\n    lock.lock();\n    activeTransaction.remove(xid);\n    lock.unlock();\n    lt.remove(xid);\n    tm.commit(xid);\n}\n",[48,197,195],{"__ignoreMap":50},[11,199,200],{},"There are two ways to abort a transaction: manually and automatically. A manual abort calls abort(). An automatic abort rolls the transaction back when a deadlock is detected or when version skipping occurs:",[41,202,205],{"className":203,"code":204,"language":78,"meta":50},[76],"private void internAbort(long xid, boolean autoAborted) {\n    lock.lock();\n    Transaction t = activeTransaction.get(xid);\n    if(!autoAborted) {\n        activeTransaction.remove(xid);\n    }\n    lock.unlock();\n    if(t.autoAborted) return;\n    lt.remove(xid);\n    tm.abort(xid);\n}\n",[48,206,204],{"__ignoreMap":50},[11,208,209,212],{},[48,210,211],{"code":211},"read()"," reads an entry. We just need to remember the visibility check:",[41,214,217],{"className":215,"code":216,"language":78,"meta":50},[76],"@Override\npublic byte[] read(long xid, long uid) throws Exception {\n    lock.lock();\n    Transaction t = activeTransaction.get(xid);\n    lock.unlock();\n    if(t.err != null) {\n        throw t.err;\n    }\n    Entry entry = super.get(uid);\n    try {\n        if(Visibility.isVisible(tm, t, entry)) {\n            return entry.data();\n        } else {\n            return null;\n        }\n    } finally {\n        entry.release();\n    }\n}\n",[48,218,216],{"__ignoreMap":50},[11,220,221,224],{},[48,222,223],{"code":223},"insert()"," wraps the data in an Entry and hands it straight to DM for insertion:",[41,226,229],{"className":227,"code":228,"language":78,"meta":50},[76],"@Override\npublic long insert(long xid, byte[] data) throws Exception {\n    lock.lock();\n    Transaction t = activeTransaction.get(xid);\n    lock.unlock();\n    if(t.err != null) {\n        throw t.err;\n    }\n    byte[] raw = Entry.wrapEntryRaw(xid, data);\n    return dm.insert(xid, raw);\n}\n",[48,230,228],{"__ignoreMap":50},[11,232,233,236],{},[48,234,235],{"code":235},"delete()"," looks a little more complicated:",[41,238,241],{"className":239,"code":240,"language":78,"meta":50},[76],"@Override\npublic boolean delete(long xid, long uid) throws Exception {\n    lock.lock();\n    Transaction t = activeTransaction.get(xid);\n    lock.unlock();\n\n    if(t.err != null) {\n        throw t.err;\n    }\n    Entry entry = super.get(uid);\n    try {\n        if(!Visibility.isVisible(tm, t, entry)) {\n            return false;\n        }\n        Lock l = null;\n        try {\n            l = lt.add(xid, uid);\n        } catch(Exception e) {\n            t.err = Error.ConcurrentUpdateException;\n            internAbort(xid, true);\n            t.autoAborted = true;\n            throw t.err;\n        }\n        if(l != null) {\n            l.lock();\n            l.unlock();\n        }\n        if(entry.getXmax() == xid) {\n            return false;\n        }\n        if(Visibility.isVersionSkip(tm, t, entry)) {\n            t.err = Error.ConcurrentUpdateException;\n            internAbort(xid, true);\n            t.autoAborted = true;\n            throw t.err;\n        }\n        entry.setXmax(xid);\n        return true;\n    } finally {\n        entry.release();\n    }\n}\n",[48,242,240],{"__ignoreMap":50},[11,244,245],{},"Most of it is actually three preliminary steps: checking visibility, acquiring the resource lock, and checking for version skipping. The deletion itself only sets XMAX.",[11,247,248],{},"Today is December 24, 2021. Christmas Eve.",[250,251,252],"blockquote",{},[11,253,254,255,258,259,261,262,264],{},"May your future be bright",[256,257],"br",{},"\nMay you and the one you love be together at last",[256,260],{},"\nMay you find happiness in this earthly world",[256,263],{},"\nI wish only to face the sea, with spring warmth and flowers in bloom",{"title":50,"searchDepth":266,"depth":266,"links":267},4,[268,270,271,272],{"id":25,"depth":269,"text":26},3,{"id":32,"depth":269,"text":33},{"id":83,"depth":269,"text":84},{"id":150,"depth":269,"text":151},[274],"projects","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.",false,"md","https:\u002F\u002Fblog-img.774352199.xyz\u002FBF3yDW.webp",{"slots":281},{},true,"\u002Fprojects\u002Fmydb\u002Fmydb7",null,{"text":286,"minutes":287,"time":288,"words":289},"8 min read",7.265,435900,1453,{"title":5,"description":276},"Complete MYDB’s version manager with version-skip checks, wait-for graph deadlock detection, automatic rollback, lock release, and record visibility checks.",{"loc":283},"posts\u002Fprojects\u002Fmydb\u002Fmydb7",[295,296,297,298],"MYDB","Java","Deadlock detection","Version management","tech","1T7cM0KDr_5NZV9WlK8T7Fa6vb8dAP6IEgCYlJyyGsA",[302,320,337,355,372,391,409,427,445,461,477,492,507,523,540,558,573,590,604,620,637,654,670,687,703,722,738,754,772,786,804,821,837,853,867,882,896,911,926,940,954,968,983,987,998],{"categories":303,"date":305,"description":306,"image":307,"path":308,"readingTime":309,"recommend":284,"tags":314,"title":319,"type":299},[304],"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":310,"minutes":311,"time":312,"words":313},"4 min read",3.08,184800,616,[315,316,317,318],"Chronic gastritis","Medical care experiences","Gastroscopy","Health journal","My Journey with Chronic Gastritis",{"categories":321,"date":322,"description":323,"image":324,"path":325,"readingTime":326,"recommend":284,"tags":331,"title":336,"type":299},[304],"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":327,"minutes":328,"time":329,"words":330},"9 min read",8.635,518100,1727,[332,333,334,335],"The Three-Body Problem","Liu Cixin","Science fiction","Reading notes","The “Majority” in The Three-Body Problem",{"categories":338,"date":339,"description":340,"image":341,"path":342,"readingTime":343,"recommend":284,"tags":348,"title":354,"type":299},[304],"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":344,"minutes":345,"time":346,"words":347},"1 min read",0.15,9000,30,[349,350,351,352,353],"Annual planning","Learning Japanese","SICP","TAPL","Operating systems","My Learning Plan for 2024",{"categories":356,"date":357,"description":358,"image":359,"path":360,"readingTime":361,"recommend":284,"tags":366,"title":371,"type":299},[304],"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":362,"minutes":363,"time":364,"words":365},"10 min read",9.74,584400,1948,[367,368,369,370],"ByteDance","Software engineering careers","Career retrospective","Mental health","Working at ByteDance for Three Years and Staying Somewhat Sane Is Not Entirely Impossible",{"categories":373,"date":375,"description":376,"image":377,"path":378,"readingTime":379,"recommend":284,"tags":384,"title":390,"type":299},[374],"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":380,"minutes":381,"time":382,"words":383},"2 min read",1.785,107100,357,[385,386,387,388,389],"Astro","Google Analytics","Google Tag Manager","Partytown","Web analytics","Adding Google Analytics to Astro with Tag Manager",{"categories":392,"date":393,"description":394,"image":395,"path":396,"readingTime":397,"recommend":402,"tags":403,"title":408,"type":299},[374],"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":398,"minutes":399,"time":400,"words":401},"15 min read",14.275,856500,2855,2,[404,405,406,407],"Programming language design","Type systems","Compiler design","RISC-V","Some Thoughts on Programming Languages",{"categories":410,"date":411,"description":412,"image":413,"path":414,"readingTime":415,"recommend":266,"tags":420,"title":426,"type":299},[374],"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":416,"minutes":417,"time":418,"words":419},"5 min read",4.865,291900,973,[421,422,423,424,425],"Tailscale","mihomo","Site-to-site networking","Transparent proxy","Home networking","Connecting My Shanghai and Hangzhou Networks",{"categories":428,"date":429,"description":430,"image":431,"path":432,"readingTime":433,"recommend":284,"tags":438,"title":444,"type":299},[374],"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":434,"minutes":435,"time":436,"words":437},"6 min read",5.295,317700,1059,[439,440,441,442,443],"CSAPP","WSL2","Linux","GDB","Lab environment","Setting Up the CSAPP Lab Environment",{"categories":446,"date":447,"description":448,"image":449,"path":450,"readingTime":451,"recommend":284,"tags":456,"title":460,"type":299},[374],"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":452,"minutes":453,"time":454,"words":455},"12 min read",11.79,707400,2358,[457,458,422,459,424],"Debian","Side router","AdGuard Home","Using Debian as a Side Router",{"categories":462,"date":463,"description":464,"image":465,"path":466,"readingTime":467,"recommend":284,"tags":471,"title":476,"type":299},[374],"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":362,"minutes":468,"time":469,"words":470},9.395,563700,1879,[472,473,424,474,475],"FakeIP","sing-box","Policy-based routing","Traffic routing","Routing Transparent Proxy Traffic with FakeIP",{"categories":478,"date":479,"description":480,"image":481,"path":482,"readingTime":483,"recommend":284,"tags":487,"title":491,"type":299},[374],"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":310,"minutes":484,"time":485,"words":486},3.03,181800,606,[458,488,489,490],"Port forwarding","NAT","Network troubleshooting","Fixing Port Forwarding with a Side Router",{"categories":493,"date":494,"description":495,"image":496,"path":497,"readingTime":498,"recommend":284,"tags":502,"title":506,"type":299},[374],"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":286,"minutes":499,"time":500,"words":501},7.29,437400,1458,[503,407,353,504,505],"Go","Bare-metal programming","Runtime","A Project That Failed: Seven Not-So-Happy Days over Chinese New Year",{"categories":508,"date":509,"description":510,"image":511,"path":512,"readingTime":513,"recommend":284,"tags":518,"title":522,"type":299},[374],"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":514,"minutes":515,"time":516,"words":517},"3 min read",2.855,171300,571,[503,519,520,521],"Reflection","Deep copy","Struct conversion","Deep Copying Between Different Struct Types in Go",{"categories":524,"date":525,"description":526,"image":527,"path":528,"readingTime":529,"recommend":284,"tags":533,"title":539,"type":299},[374],"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":514,"minutes":530,"time":531,"words":532},2.45,147000,490,[534,535,536,537,538],"Apple Watch","Health Auto Export","InfluxDB","Grafana","Heart rate monitoring","My Heart Beats for U: Visualizing Heart Rate in Grafana",{"categories":541,"date":542,"description":543,"image":544,"path":545,"readingTime":546,"recommend":550,"tags":551,"title":557,"type":299},[374],"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":310,"minutes":547,"time":548,"words":549},3.305,198300,661,5,[552,553,554,555,556],"macOS 26","iPadOS 26","Liquid Glass","Apple Intelligence","Operating system impressions","Trying Out macOS 26 and iPadOS 26",{"categories":559,"date":560,"description":561,"image":562,"path":563,"readingTime":564,"recommend":284,"tags":568,"title":572,"type":299},[374],"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":434,"minutes":565,"time":566,"words":567},5.1,306000,1020,[569,555,570,571],"macOS 27","ChatGPT","Mainland China Mac","Getting Apple Intelligence Working on a China-Market Mac: Region Changes and Extracting ChatGPT",{"categories":574,"date":575,"description":576,"image":577,"path":578,"readingTime":579,"recommend":284,"tags":583,"title":589,"type":299},[374],"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":434,"minutes":580,"time":581,"words":582},5.76,345600,1152,[584,585,586,587,588],"MoonTV","LunaTV","Vibe Coding","Cursor","AI-assisted development","MoonTV: An Experiment in Vibe Coding",{"categories":591,"date":592,"description":593,"image":594,"path":595,"readingTime":596,"recommend":284,"tags":600,"title":603,"type":299},[374],"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":310,"minutes":597,"time":598,"words":599},3.805,228300,761,[601,602,474,475],"BGP","IP address database","More Accurate Routing for Chinese and Overseas IPs with BGP",{"categories":605,"date":606,"description":607,"image":608,"path":609,"readingTime":610,"recommend":284,"tags":614,"title":619,"type":299},[374],"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":416,"minutes":611,"time":612,"words":613},4.68,280800,936,[615,616,617,618],"Microsoft Flight Simulator 2024","Thrustmaster TCA","PICO VR","Flight simulation","Adventures with Microsoft Flight Simulator 2024",{"categories":621,"date":622,"description":623,"image":624,"path":625,"readingTime":626,"recommend":284,"tags":630,"title":636,"type":299},[374],"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":286,"minutes":627,"time":628,"words":629},7.61,456600,1522,[631,632,633,634,635],"Android","OPPO","iOS","Smartphone impressions","Ecosystem migration","One Month After Switching to Android",{"categories":638,"date":639,"description":640,"image":641,"path":642,"readingTime":643,"recommend":284,"tags":647,"title":653,"type":299},[374],"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":434,"minutes":644,"time":645,"words":646},5.735,344100,1147,[648,649,650,651,652],"TREK","Docker Compose","Dockge","VPS","Self-hosting","One TREK, Twenty Stacks",{"categories":655,"date":656,"description":657,"image":658,"path":659,"readingTime":660,"recommend":284,"tags":665,"title":669,"type":299},[374],"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":661,"minutes":662,"time":663,"words":664},"7 min read",6.47,388200,1294,[666,667,422,668,424,475],"OPNsense","FreeBSD","tun2socks","Transparent Proxying and Traffic Routing with OPNsense",{"categories":671,"date":672,"description":673,"image":674,"path":675,"readingTime":676,"recommend":269,"tags":680,"title":686,"type":299},[374],"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":286,"minutes":677,"time":678,"words":679},7.475,448500,1495,[681,682,683,684,685],"Parsing","GLR","Symbol table","Scope","Disambiguation","Resolving Type Name and Variable Name Ambiguity in Parsing",{"categories":688,"date":689,"description":690,"image":691,"path":692,"readingTime":693,"recommend":284,"tags":697,"title":702,"type":299},[374],"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":380,"minutes":694,"time":695,"words":696},1.92,115200,384,[407,698,699,700,701],"Spike","riscv-pk","Cross-compilation","Toolchain","Installing the RISC-V Toolchain and Emulator",{"categories":704,"date":705,"description":706,"image":707,"path":708,"readingTime":709,"recommend":713,"tags":714,"title":721,"type":299},[374],"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":286,"minutes":710,"time":711,"words":712},7.345,440700,1469,7,[715,716,717,718,719,720],"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":723,"date":724,"description":725,"image":726,"path":727,"readingTime":728,"recommend":284,"tags":732,"title":737,"type":299},[374],"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":452,"minutes":729,"time":730,"words":731},11.885,713100,2377,[733,734,735,736],"GFW","DNS poisoning","TCP","Internet censorship","How the Great Firewall Works",{"categories":739,"date":740,"description":741,"image":742,"path":743,"readingTime":744,"recommend":284,"tags":748,"title":753,"type":299},[374],"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":514,"minutes":745,"time":746,"words":747},2.305,138300,461,[296,749,750,751,752],"javac","String concatenation","Constant propagation","Bytecode","How Java’s this Keyword Can Prevent Compile-Time Constant Propagation",{"categories":755,"date":756,"description":757,"image":758,"path":759,"readingTime":760,"recommend":284,"tags":765,"title":771,"type":299},[374],"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":761,"minutes":762,"time":763,"words":764},"19 min read",18.96,1137600,3792,[766,767,768,769,770],"VitePress","Vue","Cloudflare Workers","Cloudflare KV","Microblogging","Adding a Microblog to VitePress",{"categories":773,"date":774,"description":775,"image":776,"path":777,"readingTime":778,"recommend":284,"tags":782,"title":785,"type":299},[374],"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":514,"minutes":779,"time":780,"words":781},2.34,140400,468,[783,784,651,474,475],"Cloudflare WARP","IPv6","Routing Selected VPS Traffic Through WARP over IPv6",{"categories":787,"date":788,"description":789,"image":790,"path":791,"readingTime":792,"recommend":796,"tags":797,"title":803,"type":299},[374],"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":416,"minutes":793,"time":794,"words":795},4.545,272700,909,6,[798,799,800,801,802],"Xiaomi 17","Bootloader","Android Root","Firmware flashing","Root hiding","Making the Xiaomi 17 My Daily Driver: Unlocking, Flashing, Rooting, and Hiding Root",{"categories":805,"date":807,"description":808,"image":809,"path":810,"readingTime":811,"recommend":284,"tags":815,"title":820,"type":299},[806],"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":286,"minutes":812,"time":813,"words":814},7.21,432600,1442,[816,817,503,818,819],"MIT 6.5840","MapReduce","RPC","Concurrent programming","6.5840 Lab 1: MapReduce",{"categories":822,"date":823,"description":824,"image":825,"path":826,"readingTime":827,"recommend":284,"tags":831,"title":836,"type":299},[806],"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":416,"minutes":828,"time":829,"words":830},4.12,247200,824,[817,832,833,834,835],"Distributed systems","Paper notes","Parallel computing","Fault tolerance","Reading the MapReduce Paper",{"categories":838,"date":839,"description":840,"image":841,"path":842,"readingTime":843,"recommend":284,"tags":848,"title":852,"type":299},[806],"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":844,"minutes":845,"time":846,"words":847},"13 min read",12.235,734100,2447,[816,849,503,850,851],"Raft","Leader election","Distributed consensus","6.5840 Lab 2A: Leader Election",{"categories":854,"date":855,"description":856,"image":857,"path":858,"readingTime":859,"recommend":284,"tags":864,"title":866,"type":299},[806],"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":860,"minutes":861,"time":862,"words":863},"16 min read",15.98,958800,3196,[849,851,865,833],"Log replication","Reading the Raft Paper",{"categories":868,"date":869,"description":870,"image":871,"path":872,"readingTime":873,"recommend":877,"tags":878,"title":881,"type":299},[274],"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":416,"minutes":874,"time":875,"words":876},4.15,249000,830,1,[295,296,879,880],"Database implementation","Database architecture","MYDB 0. Project Structure and a Few Things I Had to Say",{"categories":883,"date":884,"description":885,"image":886,"path":887,"readingTime":888,"recommend":284,"tags":892,"title":895,"type":299},[274],"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":416,"minutes":889,"time":890,"words":891},4.755,285300,951,[295,296,893,894],"Transaction management","XID","MYDB 1. Starting with the Transaction Manager",{"categories":897,"date":898,"description":899,"image":900,"path":901,"readingTime":902,"recommend":284,"tags":906,"title":910,"type":299},[274],"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":416,"minutes":903,"time":904,"words":905},4.305,258300,861,[295,296,907,908,909],"Socket","Client-server architecture","Communication protocol","MYDB 10. Implementing the Server, Client, and Wire Protocol",{"categories":912,"date":913,"description":914,"image":915,"path":916,"readingTime":917,"recommend":284,"tags":921,"title":925,"type":299},[274],"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":434,"minutes":918,"time":919,"words":920},5.725,343500,1145,[295,296,922,923,924],"Reference counting","Cache design","Shared memory","MYDB 2. A Reference-Counted Cache Framework and Shared Byte Arrays",{"categories":927,"date":928,"description":929,"image":930,"path":931,"readingTime":932,"recommend":284,"tags":936,"title":939,"type":299},[274],"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":416,"minutes":933,"time":934,"words":935},4.7,282000,940,[295,296,937,938],"Data pages","Cache management","MYDB 3. Caching and Managing Data Pages",{"categories":941,"date":942,"description":943,"image":944,"path":945,"readingTime":946,"recommend":284,"tags":950,"title":953,"type":299},[274],"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":286,"minutes":947,"time":948,"words":949},7.885,473100,1577,[295,296,951,952],"Database logging","Crash recovery","MYDB 4. Log Files and Recovery Strategies",{"categories":955,"date":956,"description":957,"image":958,"path":959,"readingTime":960,"recommend":284,"tags":964,"title":967,"type":299},[274],"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":661,"minutes":961,"time":962,"words":963},6.37,382200,1274,[295,296,965,966],"Page index","Data management","MYDB 5. The Page Index and the Data Manager",{"categories":969,"date":970,"description":971,"image":972,"path":973,"readingTime":974,"recommend":284,"tags":978,"title":982,"type":299},[274],"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.","https:\u002F\u002Fblog-img.774352199.xyz\u002F8YzotA.webp","\u002Fprojects\u002Fmydb\u002Fmydb6",{"text":327,"minutes":975,"time":976,"words":977},8.64,518400,1728,[295,296,979,980,981],"MVCC","Transaction isolation","Two-phase locking","MYDB 6. Record Versions and Transaction Isolation",{"categories":984,"date":275,"description":276,"image":279,"path":283,"readingTime":985,"recommend":284,"tags":986,"title":5,"type":299},[274],{"text":286,"minutes":287,"time":288,"words":289},[295,296,297,298],{"categories":988,"date":989,"description":990,"image":991,"path":992,"readingTime":993,"recommend":284,"tags":994,"title":997,"type":299},[274],"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":416,"minutes":874,"time":875,"words":876},[295,296,995,996],"B+ tree","Database indexing","MYDB 8. Index Management",{"categories":999,"date":1000,"description":1001,"image":1002,"path":1003,"readingTime":1004,"recommend":284,"tags":1008,"title":1011,"type":299},[274],"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":434,"minutes":1005,"time":1006,"words":1007},5.035,302100,1007,[295,296,1009,1010],"SQL parsing","Table management","MYDB 9. Field and Table Management",1789914054049]