邻里 - CouchDB 如何防止数据损坏:fsync

  • CouchDB and Data Safety: Programming often raises questions about underlying fundamentals, especially data storage. CouchDB, started in 2005, is a relatively long-running software with some old parts. Abstractions help programmers forget how certain parts work. New information can lead to re-evaluating code.
  • Reading and Writing to Disk: Unix programs acquire file handles with open. They can read or write data using read and write, specifying offsets and lengths. File systems define block sizes for efficient storage use. Most programs avoid reading one byte at a time. The page cache keeps file system pages in memory for faster access.
  • The Problem and Solution: When writing to disk, Unix kernels can write to the page cache and return success. Databases like CouchDB need to ensure data reaches storage. fsync tells the kernel to write data to storage. CouchDB calls fsync after adding B+-tree nodes and writing a new footer to ensure data is safely on disk. It also performs an additional fsync on open to ensure the footer is flushed.
  • Conclusion: After working out these details, the CouchDB team can continue their work knowing that CouchDB keeps data safe. It shows CouchDB developers take data safety seriously and are constantly working to ensure durability guarantees.
阅读 9
0 条评论