On Thu, 28 Jan 2016 08:00:08 +0000 Meinlschmidt Stefan <Stefan.Meinlschmidt at esolutions.de> wrote:
> > But I ask you, what action could the application possibly take, in > > that subsecond interval, that it matters? > > Under the QNX OS using a QNX6 filesystem with default configuration, > that ?subsecond interval? is actually up to 10s. For any > non-journalling filesystem (SD cards, anyone?) mounted without > immediate write-through (for efficiency) on Linux the interval can > be, IIRC, up to 30s. Are we talking about the same thing? write(2) makes no guarantee about when the bits will actually be written. It transfers the data to the kernel. fsync(2) *does* commit the data to media and does not return until the hardware indicates the write is complete. That's the data, the extent of the inode. For metadata, e.g. mtime, Linux requires a second fsync is required, on the containing directory. Surely SQLite does both -- fsync on file and directory -- as part of a commit. That's not in doubt, is it? Given that the fsync has returned successfully, I don't know of any hardware that then will take 1000 ms to complete the write. That's the basis for my "subsecond interval" assumption. The OP's question involved Linux, and that I think is covered. As for QNX, if the default configuration has broken fsync semantics, it's hard to see what SQLite can do about that. The DBMS has to rely on the OS to write the data, and there has to be some way to ascertain that's been done. > The application could for example write to some non-SQLite > storage.... Or (what we did) it could shut off device power. Yes. In general it's better not to maintain state in two places; if the application writes "committed to database" status after committing to the database, it's going to have to contend with inconsistencies on startup after a crash. And your scenario is reasonable: you committed the data, and now you can turn off the device until it's needed again. In such a constrained environment, you need reliable status from the device. If you can't get that, you're definitely hosed. If you can get it, what does it look like? Perhaps the SQLite VFS can expose that as a callback or a knob. --jkl