2 ms·
Generally, sane file metaphors try very hard not to change stuff in the middle of the file. Try to keep with one "record" (which might be a bigger object than
by ajross 18y ago
Generally, sane file metaphors try very hard not to change stuff in the middle of the file. Try to keep with one "record" (which might be a bigger object than a single row in a database!) per file, and read/write them all in one swoop. If you need indexes other than the one you get for free (the path name, of course), keep them in separate files and make sure your toolchain can rebuild them as needed.
The filesystem has looser rules about data loss than the database will by default, so unless you want to handle this yourself (which can be done), you should probably to turn on "ordered data" journalling in your filesystem (e.g. for ext3: "mount -o data=ordered"). Then you only need to be able to recover from a crash (or killing) of your own software, which is a problem you'll have to handle anyway.
The classic application for this sort of technique is a mail server. Software like sendmail and postfix has been doing reliable on-disk storage for decades now, and they don't have to jump through too many hoops to do it.