简体   繁体   中英

Writing to a files raw disk sectors

I'm working on a OS portable database server and I want to know what is the best way to read/write to a index file disk sectors without locking the entire file. My database disk manager have a bitmap that keep track of where all used/unused the sectors are inside the index file. Also, is there a OS portable way of doing this?

...read/write to a index file disk sectors without locking the entire file.

You can lock just the portion (of the file) you are writing to. Under Windows, this would be accomplished using LockFile . BTW, why is it important not to lock the whole file? Your server will have exclusive access to it anyway, and it can manage the locking internally (unless you want a server-less/embedded database while still allowing multiple client connections to it).

To achieve transaction durability , you'll also need to make sure the data you write doesn't linger in the cache/buffers and is being physically written to the disk at correct times. Under Windows, consider passing FILE_FLAG_WRITE_THROUGH (and possibly FILE_FLAG_NO_BUFFERING, assuming you do your own cache management) to CreateFile .

I don't think there are OS-independent APis for any of this - you'll need to do it in a special way under each supported OS. Of course, nothing prevents you from encapsulating OS-specific code and presenting the uniform interface toward the rest of your system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM