On 18/05/12 03:23, Paul Gearon wrote:
There's a standard practice on Linux/Unix systems of opening a file
and deleting it while keeping it open. This file is fully visible
through it's handle, but the inode has been released on disk and no
other process can see it any more. It's been a while, but I don't
think this works on Windows.
Indeed - windows does not treat open files as if a hard link existed
like Linux does. Linux keeps a reference to files which is incremented
for open files and all hard links (in the in-memory inode). When it
goes to zero, the file pace can be reclaimed.
In Windows, open files can't be deleted.
Truncate is move the file pointer to zero without releasing the disk
inode or OS filehandle.
What we found was that Linux and Solaris behaved themselves quite well
when we tried to release a mapping. Run the GC, and the mapping has
probably been released. If not, then run it again the mapping has
*definitely* been released.
This seemed to work in general, until we had a problem with Windows
where it wasn't released on the second GC. So we called the GC a third
time. About a month later we had an occasion where that failed too ...
so we increased it more. Then 6 months later it failed again (it had
worked thousands of times in between). Finally we took the approach of
counting down from about 10 and re-attempting the truncation after a
GC on each iteration. This appeared to fix the problem, and we never
saw it go over 4 attempts in the log (though we don't log the number
of attempts any more).
At some point, someone (I think David) discovered the "clean" method,
and this gets called on objects in Windows. You'll see it gets pulled
out via reflection.
We recently pulled most of this code out and put it into a single file.
http://mulgara.org/svn/mulgara/trunk/src/jar/util/java/org/mulgara/util/io/MappingUtil.java
Hopefully it's clear enough, but ask questions if there's anything too obtuse.
Thanks for that.
TDB itself does not delete files (the tests do ... but the test
framework wokrs differently on Windows and Linux for portability) -
Simon is doing the delete in his code.
Andy