Hi All,
We have a few users reporting Metakit database corruption. Having investigated, they are all opening a database that is residing on a remote volume - in particular one user is opening a database from Windows XP that resides on a Mac running 10.3.8 (the Mac uses SAMBA to share files to PC clients).
After doing some investigation, the problem seems to be with memory mapped files. If I turn off memory mapping for Windows, we get no problems.
Looking at the Metakit sources, I think I see why. MK maps the file, but then also uses fread() and fwrite() to access the file at the same time. This confuses me somewhat - I would have thought that data would have been modified in-place rather than using fwrite().
Reading up on Windows file mapping, I find this comment in the docs for CreateFileMapping():
Creating a file mapping object creates the potential for mapping a view of the file, but does not map the view. The MapViewOfFile and MapViewOfFileEx functions map a view of a file into a process address space.
With one important exception, file views derived from a single file mapping object are coherent or identical at a specific time. If multiple processes have handles of the same file mapping object, they see a coherent view of the data when they map a view of the file.
The exception is related to remote files. Although CreateFileMapping works with remote files, it does not keep them coherent. For example, if two computers both map a file as writable, and both change the same page, each computer only sees its own writes to the page. When the data gets updated on the disk, it is not merged.
A mapped file and a file that is accessed by using the input and output (I/O) functions (ReadFile and WriteFile) are not necessarily coherent.
That last bit is the killer - Windows does not guarantee that files accessed by ReadFile and WriteFile (which I suspect fread() and fwrite() eventually call) are coherent with memory mapped on those files.
So, I can think of a couple of ways of solving this:
(a) Turn off file mapping for remote volumes.
(b) Modify MK so that writes inside the mapped area are done using memmove() (or whatever) rather than fwrite().
This is not guaranteed to work on Unix either:
http://www.opengroup.org/onlinepubs/009695399/functions/mmap.html
The application must ensure correct synchronization when using mmap() in conjunction with any other file access method, such as read() and write(), standard input/output, and shmat().
Has anyone come across this before? Any fixes?
Cheers,
Steve.
Stephen Baxter Software Development Manager Improvision [EMAIL PROTECTED] +44-2476-692229
_____________________________________________ Metakit mailing list - [email protected] http://www.equi4.com/mailman/listinfo/metakit
