[{"data":1,"prerenderedAt":942},["ShallowReactive",2],{"content:\u002Fen\u002Fprojects\u002Fmydb\u002Fmydb1":3,"series:content_en":231},{"id":4,"title":5,"authorship":6,"body":7,"categories":203,"date":205,"description":206,"draft":207,"extension":208,"image":209,"meta":210,"navigation":212,"path":213,"permalink":214,"published":214,"readingTime":215,"recommend":214,"references":214,"seo":220,"seoDescription":221,"seoTitle":214,"sitemap":222,"stem":223,"tags":224,"type":229,"__hash__":230},"content_en\u002Fposts\u002Fprojects\u002Fmydb\u002Fmydb1.md","MYDB 1. Starting with the Transaction Manager","human-only",{"type":8,"value":9,"toc":197},"minimark",[10,22,25,31,36,39,42,45,58,61,64,75,79,82,88,91,94,100,103,106,112,119,125,136,150,165,171,174,185,191,194],[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\u002Ftm",[19],"nofollow","backend\u002Ftm",".",[11,23,24],{},"As described in Chapter 0:",[26,27,28],"blockquote",{},[11,29,30],{},"TM maintains transaction states in an XID file and exposes interfaces that other modules use to query a transaction’s state.",[32,33,35],"h3",{"id":34},"the-xid-file","The XID File",[11,37,38],{},"First, let us define the rules.",[11,40,41],{},"Every transaction in MYDB has an XID that uniquely identifies it. XIDs start at 1 and increase, with no duplicates. XID 0 is reserved for a Super Transaction. An operation that needs to run without explicitly starting a transaction can use XID 0. The transaction with XID 0 is always committed.",[11,43,44],{},"TransactionManager maintains a file in the XID format to record each transaction’s state. In MYDB, a transaction has one of three states:",[46,47,48,52,55],"ol",{},[49,50,51],"li",{},"active: still in progress, not yet finished",[49,53,54],{},"committed: committed",[49,56,57],{},"aborted: canceled (rolled back)",[11,59,60],{},"The XID file allocates one byte per transaction to store its state. The file header also contains an 8-byte number recording how many transactions the file manages. Transaction xid’s state is therefore stored at byte offset (xid-1)+8. We subtract 1 because xid 0 (the Super XID) does not need its state recorded.",[11,62,63],{},"TransactionManager exposes interfaces for other modules to create transactions and query their states. Specifically:",[65,66,72],"pre",{"className":67,"code":69,"language":70,"meta":71},[68],"language-java","public interface TransactionManager {\n    long begin();                       \u002F\u002F 开启一个新事务\n    void commit(long xid);              \u002F\u002F 提交一个事务\n    void abort(long xid);               \u002F\u002F 取消一个事务\n    boolean isActive(long xid);         \u002F\u002F 查询一个事务的状态是否是正在进行的状态\n    boolean isCommitted(long xid);      \u002F\u002F 查询一个事务的状态是否是已提交\n    boolean isAborted(long xid);        \u002F\u002F 查询一个事务的状态是否是已取消\n    void close();                       \u002F\u002F 关闭 TM\n}\n","java","",[73,74,69],"code",{"__ignoreMap":71},[32,76,78],{"id":77},"implementation","Implementation",[11,80,81],{},"The rules are simple; now we just need to code them. First, define the necessary constants:",[65,83,86],{"className":84,"code":85,"language":70,"meta":71},[68],"\u002F\u002F XID 文件头长度\nstatic final int LEN_XID_HEADER_LENGTH = 8;\n\u002F\u002F 每个事务的占用长度\nprivate static final int XID_FIELD_SIZE = 1;\n\u002F\u002F 事务的三种状态\nprivate static final byte FIELD_TRAN_ACTIVE   = 0;\nprivate static final byte FIELD_TRAN_COMMITTED = 1;\nprivate static final byte FIELD_TRAN_ABORTED  = 2;\n\u002F\u002F 超级事务，永远为 commited 状态\npublic static final long SUPER_XID = 0;\n\u002F\u002F XID 文件后缀\nstatic final String XID_SUFFIX = \".xid\";\n",[73,87,85],{"__ignoreMap":71},[11,89,90],{},"All file reads and writes use NIO’s FileChannel. This differs somewhat from traditional IO’s Input\u002FOutput Streams, mainly in the API; you just need to get familiar with it.",[11,92,93],{},"After constructing a TransactionManager, we first validate the XID file. The check is simple: use the 8-byte number in its header to calculate the expected file length and compare it with the actual length. If they differ, the file is invalid.",[65,95,98],{"className":96,"code":97,"language":70,"meta":71},[68],"private void checkXIDCounter() {\n    long fileLen = 0;\n    try {\n        fileLen = file.length();\n    } catch (IOException e1) {\n        Panic.panic(Error.BadXIDFileException);\n    }\n    if(fileLen \u003C LEN_XID_HEADER_LENGTH) {\n        Panic.panic(Error.BadXIDFileException);\n    }\n\n    ByteBuffer buf = ByteBuffer.allocate(LEN_XID_HEADER_LENGTH);\n    try {\n        fc.position(0);\n        fc.read(buf);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n    this.xidCounter = Parser.parseLong(buf.array());\n    long end = getXidPosition(this.xidCounter + 1);\n    if(end != fileLen) {\n        Panic.panic(Error.BadXIDFileException);\n    }\n}\n",[73,99,97],{"__ignoreMap":71},[11,101,102],{},"If validation fails, the panic method forcibly shuts the process down. Errors in some foundational modules are handled this way too: an unrecoverable error leaves us no choice but to stop.",[11,104,105],{},"First, a small helper finds the file offset of an xid’s state:",[65,107,110],{"className":108,"code":109,"language":70,"meta":71},[68],"\u002F\u002F 根据事务 xid 取得其在 xid 文件中对应的位置\nprivate long getXidPosition(long xid) {\n    return LEN_XID_HEADER_LENGTH + (xid-1)*XID_FIELD_SIZE;\n}\n",[73,111,109],{"__ignoreMap":71},[11,113,114,115,118],{},"The ",[73,116,117],{"code":117},"begin()"," method starts a transaction: it sets transaction xidCounter+1 to active, then increments xidCounter and updates the file header.",[65,120,123],{"className":121,"code":122,"language":70,"meta":71},[68],"\u002F\u002F 开始一个事务，并返回 XID\npublic long begin() {\n    counterLock.lock();\n    try {\n        long xid = xidCounter + 1;\n        updateXID(xid, FIELD_TRAN_ACTIVE);\n        incrXIDCounter();\n        return xid;\n    } finally {\n        counterLock.unlock();\n    }\n}\n\n\u002F\u002F 更新 xid 事务的状态为 status\nprivate void updateXID(long xid, byte status) {\n    long offset = getXidPosition(xid);\n    byte[] tmp = new byte[XID_FIELD_SIZE];\n    tmp[0] = status;\n    ByteBuffer buf = ByteBuffer.wrap(tmp);\n    try {\n        fc.position(offset);\n        fc.write(buf);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n    try {\n        fc.force(false);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n}\n\n\u002F\u002F 将 XID 加一，并更新 XID Header\nprivate void incrXIDCounter() {\n    xidCounter ++;\n    ByteBuffer buf = ByteBuffer.wrap(Parser.long2Byte(xidCounter));\n    try {\n        fc.position(0);\n        fc.write(buf);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n    try {\n        fc.force(false);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n}\n",[73,124,122],{"__ignoreMap":71},[11,126,127,128,131,132,135],{},"Every file operation here must immediately be flushed to the file to prevent data loss in a crash. FileChannel’s ",[73,129,130],{"code":130},"force()"," forces cached contents to be synchronized to the file, much like BIO’s ",[73,133,134],{"code":134},"flush()",". Its boolean argument specifies whether to synchronize file metadata too, such as the last-modified time.",[11,137,114,138,141,142,145,146,149],{},[73,139,140],{"code":140},"commit()"," and ",[73,143,144],{"code":144},"abort()"," methods can use ",[73,147,148],{"code":148},"updateXID()"," directly.",[11,151,152,153,156,157,160,161,164],{},"Similarly, ",[73,154,155],{"code":155},"isActive()",", ",[73,158,159],{"code":159},"isCommitted()",", and ",[73,162,163],{"code":163},"isAborted()"," all check an xid’s state, so one common helper can handle them:",[65,166,169],{"className":167,"code":168,"language":70,"meta":71},[68],"\u002F\u002F 检测 XID 事务是否处于 status 状态\nprivate boolean checkXID(long xid, byte status) {\n    long offset = getXidPosition(xid);\n    ByteBuffer buf = ByteBuffer.wrap(new byte[XID_FIELD_SIZE]);\n    try {\n        fc.position(offset);\n        fc.read(buf);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n    return buf.array()[0] == status;\n}\n",[73,170,168],{"__ignoreMap":71},[11,172,173],{},"Of course, remember to handle SUPER_XID separately before checking.",[11,175,176,177,180,181,184],{},"There are also two static methods: ",[73,178,179],{"code":179},"create()"," creates an xid file and a TM, while ",[73,182,183],{"code":183},"open()"," creates a TM from an existing xid file. When creating an XID file from scratch, write an empty header by setting xidCounter to 0; otherwise it will fail validation later:",[65,186,189],{"className":187,"code":188,"language":70,"meta":71},[68],"public static TransactionManagerImpl create(String path) {\n    ...\n    \u002F\u002F 写空 XID 文件头\n    ByteBuffer buf = ByteBuffer.wrap(new byte[TransactionManagerImpl.LEN_XID_HEADER_LENGTH]);\n    try {\n        fc.position(0);\n        fc.write(buf);\n    } catch (IOException e) {\n        Panic.panic(e);\n    }\n    ...\n}\n",[73,190,188],{"__ignoreMap":71},[11,192,193],{},"And that is TM done. Does not look too hard, does it? （￣ c￣）y-～",[11,195,196],{},"Just wait: the really difficult part, DM, is still ahead. That will take more than one chapter~",{"title":71,"searchDepth":198,"depth":198,"links":199},4,[200,202],{"id":34,"depth":201,"text":35},3,{"id":77,"depth":201,"text":78},[204],"projects","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.",false,"md","https:\u002F\u002Fblog-img.774352199.xyz\u002FH4zZAK.webp",{"slots":211},{},true,"\u002Fprojects\u002Fmydb\u002Fmydb1",null,{"text":216,"minutes":217,"time":218,"words":219},"5 min read",4.755,285300,951,{"title":5,"description":206},"Implement MYDB’s transaction manager in Java with an XID state file, covering ID allocation, begin, commit, abort, validation, and persistent file updates.",{"loc":213},"posts\u002Fprojects\u002Fmydb\u002Fmydb1",[225,226,227,228],"MYDB","Java","Transaction management","XID","tech","IjNdJgyqUUOYUdiX0F12Ig-RkxG6kE6o1J36l4LPSkU",[232,250,267,285,302,321,339,356,374,390,406,421,437,453,470,488,503,520,534,550,567,584,600,617,633,652,668,684,702,716,734,751,767,783,797,812,816,831,846,860,874,888,903,917,928],{"categories":233,"date":235,"description":236,"image":237,"path":238,"readingTime":239,"recommend":214,"tags":244,"title":249,"type":229},[234],"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":240,"minutes":241,"time":242,"words":243},"4 min read",3.08,184800,616,[245,246,247,248],"Chronic gastritis","Medical care experiences","Gastroscopy","Health journal","My Journey with Chronic Gastritis",{"categories":251,"date":252,"description":253,"image":254,"path":255,"readingTime":256,"recommend":214,"tags":261,"title":266,"type":229},[234],"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":257,"minutes":258,"time":259,"words":260},"9 min read",8.635,518100,1727,[262,263,264,265],"The Three-Body Problem","Liu Cixin","Science fiction","Reading notes","The “Majority” in The Three-Body Problem",{"categories":268,"date":269,"description":270,"image":271,"path":272,"readingTime":273,"recommend":214,"tags":278,"title":284,"type":229},[234],"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":274,"minutes":275,"time":276,"words":277},"1 min read",0.15,9000,30,[279,280,281,282,283],"Annual planning","Learning Japanese","SICP","TAPL","Operating systems","My Learning Plan for 2024",{"categories":286,"date":287,"description":288,"image":289,"path":290,"readingTime":291,"recommend":214,"tags":296,"title":301,"type":229},[234],"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":292,"minutes":293,"time":294,"words":295},"10 min read",9.74,584400,1948,[297,298,299,300],"ByteDance","Software engineering careers","Career retrospective","Mental health","Working at ByteDance for Three Years and Staying Somewhat Sane Is Not Entirely Impossible",{"categories":303,"date":305,"description":306,"image":307,"path":308,"readingTime":309,"recommend":214,"tags":314,"title":320,"type":229},[304],"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":310,"minutes":311,"time":312,"words":313},"2 min read",1.785,107100,357,[315,316,317,318,319],"Astro","Google Analytics","Google Tag Manager","Partytown","Web analytics","Adding Google Analytics to Astro with Tag Manager",{"categories":322,"date":323,"description":324,"image":325,"path":326,"readingTime":327,"recommend":332,"tags":333,"title":338,"type":229},[304],"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":328,"minutes":329,"time":330,"words":331},"15 min read",14.275,856500,2855,2,[334,335,336,337],"Programming language design","Type systems","Compiler design","RISC-V","Some Thoughts on Programming Languages",{"categories":340,"date":341,"description":342,"image":343,"path":344,"readingTime":345,"recommend":198,"tags":349,"title":355,"type":229},[304],"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":216,"minutes":346,"time":347,"words":348},4.865,291900,973,[350,351,352,353,354],"Tailscale","mihomo","Site-to-site networking","Transparent proxy","Home networking","Connecting My Shanghai and Hangzhou Networks",{"categories":357,"date":358,"description":359,"image":360,"path":361,"readingTime":362,"recommend":214,"tags":367,"title":373,"type":229},[304],"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":363,"minutes":364,"time":365,"words":366},"6 min read",5.295,317700,1059,[368,369,370,371,372],"CSAPP","WSL2","Linux","GDB","Lab environment","Setting Up the CSAPP Lab Environment",{"categories":375,"date":376,"description":377,"image":378,"path":379,"readingTime":380,"recommend":214,"tags":385,"title":389,"type":229},[304],"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":381,"minutes":382,"time":383,"words":384},"12 min read",11.79,707400,2358,[386,387,351,388,353],"Debian","Side router","AdGuard Home","Using Debian as a Side Router",{"categories":391,"date":392,"description":393,"image":394,"path":395,"readingTime":396,"recommend":214,"tags":400,"title":405,"type":229},[304],"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":292,"minutes":397,"time":398,"words":399},9.395,563700,1879,[401,402,353,403,404],"FakeIP","sing-box","Policy-based routing","Traffic routing","Routing Transparent Proxy Traffic with FakeIP",{"categories":407,"date":408,"description":409,"image":410,"path":411,"readingTime":412,"recommend":214,"tags":416,"title":420,"type":229},[304],"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":240,"minutes":413,"time":414,"words":415},3.03,181800,606,[387,417,418,419],"Port forwarding","NAT","Network troubleshooting","Fixing Port Forwarding with a Side Router",{"categories":422,"date":423,"description":424,"image":425,"path":426,"readingTime":427,"recommend":214,"tags":432,"title":436,"type":229},[304],"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":428,"minutes":429,"time":430,"words":431},"8 min read",7.29,437400,1458,[433,337,283,434,435],"Go","Bare-metal programming","Runtime","A Project That Failed: Seven Not-So-Happy Days over Chinese New Year",{"categories":438,"date":439,"description":440,"image":441,"path":442,"readingTime":443,"recommend":214,"tags":448,"title":452,"type":229},[304],"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":444,"minutes":445,"time":446,"words":447},"3 min read",2.855,171300,571,[433,449,450,451],"Reflection","Deep copy","Struct conversion","Deep Copying Between Different Struct Types in Go",{"categories":454,"date":455,"description":456,"image":457,"path":458,"readingTime":459,"recommend":214,"tags":463,"title":469,"type":229},[304],"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":444,"minutes":460,"time":461,"words":462},2.45,147000,490,[464,465,466,467,468],"Apple Watch","Health Auto Export","InfluxDB","Grafana","Heart rate monitoring","My Heart Beats for U: Visualizing Heart Rate in Grafana",{"categories":471,"date":472,"description":473,"image":474,"path":475,"readingTime":476,"recommend":480,"tags":481,"title":487,"type":229},[304],"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":240,"minutes":477,"time":478,"words":479},3.305,198300,661,5,[482,483,484,485,486],"macOS 26","iPadOS 26","Liquid Glass","Apple Intelligence","Operating system impressions","Trying Out macOS 26 and iPadOS 26",{"categories":489,"date":490,"description":491,"image":492,"path":493,"readingTime":494,"recommend":214,"tags":498,"title":502,"type":229},[304],"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":363,"minutes":495,"time":496,"words":497},5.1,306000,1020,[499,485,500,501],"macOS 27","ChatGPT","Mainland China Mac","Getting Apple Intelligence Working on a China-Market Mac: Region Changes and Extracting ChatGPT",{"categories":504,"date":505,"description":506,"image":507,"path":508,"readingTime":509,"recommend":214,"tags":513,"title":519,"type":229},[304],"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":363,"minutes":510,"time":511,"words":512},5.76,345600,1152,[514,515,516,517,518],"MoonTV","LunaTV","Vibe Coding","Cursor","AI-assisted development","MoonTV: An Experiment in Vibe Coding",{"categories":521,"date":522,"description":523,"image":524,"path":525,"readingTime":526,"recommend":214,"tags":530,"title":533,"type":229},[304],"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":240,"minutes":527,"time":528,"words":529},3.805,228300,761,[531,532,403,404],"BGP","IP address database","More Accurate Routing for Chinese and Overseas IPs with BGP",{"categories":535,"date":536,"description":537,"image":538,"path":539,"readingTime":540,"recommend":214,"tags":544,"title":549,"type":229},[304],"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":216,"minutes":541,"time":542,"words":543},4.68,280800,936,[545,546,547,548],"Microsoft Flight Simulator 2024","Thrustmaster TCA","PICO VR","Flight simulation","Adventures with Microsoft Flight Simulator 2024",{"categories":551,"date":552,"description":553,"image":554,"path":555,"readingTime":556,"recommend":214,"tags":560,"title":566,"type":229},[304],"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":428,"minutes":557,"time":558,"words":559},7.61,456600,1522,[561,562,563,564,565],"Android","OPPO","iOS","Smartphone impressions","Ecosystem migration","One Month After Switching to Android",{"categories":568,"date":569,"description":570,"image":571,"path":572,"readingTime":573,"recommend":214,"tags":577,"title":583,"type":229},[304],"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":363,"minutes":574,"time":575,"words":576},5.735,344100,1147,[578,579,580,581,582],"TREK","Docker Compose","Dockge","VPS","Self-hosting","One TREK, Twenty Stacks",{"categories":585,"date":586,"description":587,"image":588,"path":589,"readingTime":590,"recommend":214,"tags":595,"title":599,"type":229},[304],"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":591,"minutes":592,"time":593,"words":594},"7 min read",6.47,388200,1294,[596,597,351,598,353,404],"OPNsense","FreeBSD","tun2socks","Transparent Proxying and Traffic Routing with OPNsense",{"categories":601,"date":602,"description":603,"image":604,"path":605,"readingTime":606,"recommend":201,"tags":610,"title":616,"type":229},[304],"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":428,"minutes":607,"time":608,"words":609},7.475,448500,1495,[611,612,613,614,615],"Parsing","GLR","Symbol table","Scope","Disambiguation","Resolving Type Name and Variable Name Ambiguity in Parsing",{"categories":618,"date":619,"description":620,"image":621,"path":622,"readingTime":623,"recommend":214,"tags":627,"title":632,"type":229},[304],"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":310,"minutes":624,"time":625,"words":626},1.92,115200,384,[337,628,629,630,631],"Spike","riscv-pk","Cross-compilation","Toolchain","Installing the RISC-V Toolchain and Emulator",{"categories":634,"date":635,"description":636,"image":637,"path":638,"readingTime":639,"recommend":643,"tags":644,"title":651,"type":229},[304],"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":428,"minutes":640,"time":641,"words":642},7.345,440700,1469,7,[645,646,647,648,649,650],"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":653,"date":654,"description":655,"image":656,"path":657,"readingTime":658,"recommend":214,"tags":662,"title":667,"type":229},[304],"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":381,"minutes":659,"time":660,"words":661},11.885,713100,2377,[663,664,665,666],"GFW","DNS poisoning","TCP","Internet censorship","How the Great Firewall Works",{"categories":669,"date":670,"description":671,"image":672,"path":673,"readingTime":674,"recommend":214,"tags":678,"title":683,"type":229},[304],"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":444,"minutes":675,"time":676,"words":677},2.305,138300,461,[226,679,680,681,682],"javac","String concatenation","Constant propagation","Bytecode","How Java’s this Keyword Can Prevent Compile-Time Constant Propagation",{"categories":685,"date":686,"description":687,"image":688,"path":689,"readingTime":690,"recommend":214,"tags":695,"title":701,"type":229},[304],"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":691,"minutes":692,"time":693,"words":694},"19 min read",18.96,1137600,3792,[696,697,698,699,700],"VitePress","Vue","Cloudflare Workers","Cloudflare KV","Microblogging","Adding a Microblog to VitePress",{"categories":703,"date":704,"description":705,"image":706,"path":707,"readingTime":708,"recommend":214,"tags":712,"title":715,"type":229},[304],"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":444,"minutes":709,"time":710,"words":711},2.34,140400,468,[713,714,581,403,404],"Cloudflare WARP","IPv6","Routing Selected VPS Traffic Through WARP over IPv6",{"categories":717,"date":718,"description":719,"image":720,"path":721,"readingTime":722,"recommend":726,"tags":727,"title":733,"type":229},[304],"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":216,"minutes":723,"time":724,"words":725},4.545,272700,909,6,[728,729,730,731,732],"Xiaomi 17","Bootloader","Android Root","Firmware flashing","Root hiding","Making the Xiaomi 17 My Daily Driver: Unlocking, Flashing, Rooting, and Hiding Root",{"categories":735,"date":737,"description":738,"image":739,"path":740,"readingTime":741,"recommend":214,"tags":745,"title":750,"type":229},[736],"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":428,"minutes":742,"time":743,"words":744},7.21,432600,1442,[746,747,433,748,749],"MIT 6.5840","MapReduce","RPC","Concurrent programming","6.5840 Lab 1: MapReduce",{"categories":752,"date":753,"description":754,"image":755,"path":756,"readingTime":757,"recommend":214,"tags":761,"title":766,"type":229},[736],"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":216,"minutes":758,"time":759,"words":760},4.12,247200,824,[747,762,763,764,765],"Distributed systems","Paper notes","Parallel computing","Fault tolerance","Reading the MapReduce Paper",{"categories":768,"date":769,"description":770,"image":771,"path":772,"readingTime":773,"recommend":214,"tags":778,"title":782,"type":229},[736],"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":774,"minutes":775,"time":776,"words":777},"13 min read",12.235,734100,2447,[746,779,433,780,781],"Raft","Leader election","Distributed consensus","6.5840 Lab 2A: Leader Election",{"categories":784,"date":785,"description":786,"image":787,"path":788,"readingTime":789,"recommend":214,"tags":794,"title":796,"type":229},[736],"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":790,"minutes":791,"time":792,"words":793},"16 min read",15.98,958800,3196,[779,781,795,763],"Log replication","Reading the Raft Paper",{"categories":798,"date":799,"description":800,"image":801,"path":802,"readingTime":803,"recommend":807,"tags":808,"title":811,"type":229},[204],"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":216,"minutes":804,"time":805,"words":806},4.15,249000,830,1,[225,226,809,810],"Database implementation","Database architecture","MYDB 0. Project Structure and a Few Things I Had to Say",{"categories":813,"date":205,"description":206,"image":209,"path":213,"readingTime":814,"recommend":214,"tags":815,"title":5,"type":229},[204],{"text":216,"minutes":217,"time":218,"words":219},[225,226,227,228],{"categories":817,"date":818,"description":819,"image":820,"path":821,"readingTime":822,"recommend":214,"tags":826,"title":830,"type":229},[204],"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":216,"minutes":823,"time":824,"words":825},4.305,258300,861,[225,226,827,828,829],"Socket","Client-server architecture","Communication protocol","MYDB 10. Implementing the Server, Client, and Wire Protocol",{"categories":832,"date":833,"description":834,"image":835,"path":836,"readingTime":837,"recommend":214,"tags":841,"title":845,"type":229},[204],"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":363,"minutes":838,"time":839,"words":840},5.725,343500,1145,[225,226,842,843,844],"Reference counting","Cache design","Shared memory","MYDB 2. A Reference-Counted Cache Framework and Shared Byte Arrays",{"categories":847,"date":848,"description":849,"image":850,"path":851,"readingTime":852,"recommend":214,"tags":856,"title":859,"type":229},[204],"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":216,"minutes":853,"time":854,"words":855},4.7,282000,940,[225,226,857,858],"Data pages","Cache management","MYDB 3. Caching and Managing Data Pages",{"categories":861,"date":862,"description":863,"image":864,"path":865,"readingTime":866,"recommend":214,"tags":870,"title":873,"type":229},[204],"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":428,"minutes":867,"time":868,"words":869},7.885,473100,1577,[225,226,871,872],"Database logging","Crash recovery","MYDB 4. Log Files and Recovery Strategies",{"categories":875,"date":876,"description":877,"image":878,"path":879,"readingTime":880,"recommend":214,"tags":884,"title":887,"type":229},[204],"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":591,"minutes":881,"time":882,"words":883},6.37,382200,1274,[225,226,885,886],"Page index","Data management","MYDB 5. The Page Index and the Data Manager",{"categories":889,"date":890,"description":891,"image":892,"path":893,"readingTime":894,"recommend":214,"tags":898,"title":902,"type":229},[204],"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":257,"minutes":895,"time":896,"words":897},8.64,518400,1728,[225,226,899,900,901],"MVCC","Transaction isolation","Two-phase locking","MYDB 6. Record Versions and Transaction Isolation",{"categories":904,"date":905,"description":906,"image":907,"path":908,"readingTime":909,"recommend":214,"tags":913,"title":916,"type":229},[204],"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":428,"minutes":910,"time":911,"words":912},7.265,435900,1453,[225,226,914,915],"Deadlock detection","Version management","MYDB 7. Deadlock Detection and the Version Manager",{"categories":918,"date":919,"description":920,"image":921,"path":922,"readingTime":923,"recommend":214,"tags":924,"title":927,"type":229},[204],"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":216,"minutes":804,"time":805,"words":806},[225,226,925,926],"B+ tree","Database indexing","MYDB 8. Index Management",{"categories":929,"date":930,"description":931,"image":932,"path":933,"readingTime":934,"recommend":214,"tags":938,"title":941,"type":229},[204],"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":363,"minutes":935,"time":936,"words":937},5.035,302100,1007,[225,226,939,940],"SQL parsing","Table management","MYDB 9. Field and Table Management",1789914053376]