Opened 17 years ago

Last modified 21 months ago

#229 new defect

Stub databases should be read with msvc_posix_open

Reported by: Richard Boulton Owned by: Olly Betts
Priority: normal Milestone: 2.0.0
Component: Other Version: git master
Severity: normal Keywords:
Cc: Olly Betts Blocked By:
Blocking: Operating System: Microsoft Windows

Description (last modified by Olly Betts)

Currently, stub databases are read using a standard C++ ifstream. (See backends/database.cc, function open_stub()) This works fine, except that if a user (or the database replication code) tries, on Windows, to atomically rename a new stub db file over an existing one, it will receive an error if the old stub DB file was open.

This can be avoided if we instead use msvc_posix_open() (or just open() on unix) in open_stub() to get a file handle for the stub database, and access it using C file-handling routines.

Change History (8)

comment:1 by Richard Boulton, 17 years ago

Status: newassigned

comment:2 by Olly Betts, 17 years ago

Cc: olly@… added
Operating System: Microsoft Windows

hmm, but if we do this, what happens on windows if the file is overwritten while we're reading it? The read will fail I believe...

comment:3 by Richard Boulton, 17 years ago

So, a full fix would probably have to handle failures of the read, and retry. What a pain.

comment:4 by Olly Betts, 17 years ago

Ah yes, that should work if the read returns a suitable error (which I think it does).

comment:6 by Olly Betts, 13 years ago

Description: modified (diff)

For MSVC it looks like we could just write:

ifstream stub(msvc_posix_open(file.c_str(), O_RDONLY));

But GCC's libstdc++ doesn't have this non-standard form, so we can't use this for mingw, but there is stdio_filebuf, which allows you to wrap an fd or FILE* as an istream or ostream. This would allow us to keep the current code with only minor changes on the affected platform.

We should perhaps check if iostream imposes an overhead over the C FILE* routines, and if there is much of one have a policy to avoid istream and ostream instead.

Also while one option is to retry the whole stub read upon read failing, another is to simply require that the stub update attempt retries. It is perhaps better to have the writer blocked by heavy reader activity than have readers blocked by heavy writer activity as readers tend to be more performance sensitive.

Last edited 11 years ago by Olly Betts (previous) (diff)

comment:7 by Olly Betts, 8 years ago

Milestone: 1.4.x

comment:8 by Olly Betts, 8 years ago

Owner: changed from Richard Boulton to Olly Betts
Status: assignednew

comment:9 by Olly Betts, 21 months ago

Milestone: 1.4.x2.0.0
Version: SVN trunkgit master
Note: See TracTickets for help on using tickets.