Hi, This is quite an uncommon use case. I suggest to use your own locks in this case.
In the future, H2 will probably use regular native file locks, using FileChannel.lock (exclusive locks for writing, shared locks when opening the database in read-only mode). So I suggest to use this if possible. It is supported by H2 already, by appending ";FILE_LOCK=FS" to the database URL. I will document it. Regards, Thomas On Thu, Dec 27, 2012 at 2:25 PM, Björn Melinder <[email protected]>wrote: > Hello, > > we use h2 database internally in this application<http://www.jetprofiler.com> > - > users can save and load data using BACKUP TO ... and Restore.execute(...). > Multiple instances of the application are allowed, and the h2 file lock > mechanism is used to avoid using the same workspace database per instance. > If an instance fails to open the workspace because > of DATABASE_ALREADY_OPEN_1 or ERROR_OPENING_DATABASE_1, we create a new > second workspace and so on. > > The problem: If instance A of the application is started and begins a > lengthy Restore-operation, and a new instance B is started, it will > overwrite A's workspace since the A's file lock is not in place until after > the database itself has been opened. The error is: > > java.lang.ClassCastException: org.h2.index.PageDataLeaf cannot be cast to > org.h2.store.PageStreamTrunk > > probably because the page store gets corrupted by concurrent writing from > two different processes. More information on the error can be found > here<http://www.jetprofiler.com/forum/discussion/80/enterprise-jetprofiler-saved-jpp--monitoring-crash/> > . > > I know this might not classify as a bug, but may I suggest that you add a > FileLock to the Restore-operation to make it thread-safe? Alternatively, I > can write my own file locks. > > Best regards, > Bjorn > > -- > You received this message because you are subscribed to the Google Groups > "H2 Database" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/h2-database/-/2UESn8eq2ucJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/h2-database?hl=en. > -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
