I believe, I've found out the cause of the problem. 

When H2 seeks beyond the current file-size and tries to write at the new 
channel position, it creates a hole in the file. So far, so good. 

However, it then erroneously assumes (in its page-allocation internals 
somewhere) that this hole would always be initialized to zero's, which may 
or may not be the case, especially for custom file-systems like the one I'm 
dealing with right now. For sake of efficiency, this file-system does not 
-- and similarly many others may not -- initialize this hole to zero. 

Even the Java 7 spec on FileChannel.position(long) 
<http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#position(long)>has
 
this to say:

       * "Setting the position to a value that is greater than the file's 
current size is legal but does not change the size of the file. A later 
attempt to read bytes at such a position will immediately return an 
end-of-file indication. A later attempt to write bytes at such a position 
will cause the file to be grown to accommodate the new bytes; the values of 
any bytes between the previous end-of-file and the newly-written bytes are 
unspecified."*

I have verified now...
    1. that the default file/channel implementation in Java 7 does indeed 
initialize this hole to zero's, This could cease being the case in future.
    2. that when I initialize this hole to zero's in my file-system code, 
both the corruption and the file-increase problems do indeed disappear. 

So, H2 is reading some junk in this hole as valid data and (rightly) 
throwing corruption-exception.

I am aware by now that H2 uses its own channel and does not use the Java 7 
semantics but... Do you agree with the above? If yes, would a fix for this 
be available soon? 

Regards,
/PN



-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to