DEFRAG SHUTDOWN not removing lock?

336 views
Skip to first unread message

Reinier L'abee

unread,
Aug 5, 2015, 11:37:26 PM8/5/15
to H2 Database
Hi all,

I use H2 version 1.4.188 in embeddded mode (mvstore enabled) and when I execute the statement DEFRAG SHUTDOWN I'm not able to open a new connection anymore. I use a single connection in my application and that gets closed when I execute the shutdown statement. (connection.isClosed() returns true). But when I then I try to open a new connection it tells me the file is locked. Am I missing something here? I believe this used to work a couple of months ago. Has something changed, or do I have to review my code? ;)

Caused by: java.lang.IllegalStateException: The file is locked: nio:C:/H2DB.mv.db [1.4.188/7]
    at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:773)
    at org.h2.mvstore.FileStore.open(FileStore.java:167)
    at org.h2.mvstore.MVStore.<init>(MVStore.java:346)
    at org.h2.mvstore.MVStore$Builder.open(MVStore.java:2888)
    at org.h2.mvstore.db.MVTableEngine$Store.open(MVTableEngine.java:154)
    ... 68 more
Caused by: java.nio.channels.OverlappingFileLockException
    at sun.nio.ch.SharedFileLockTable.checkList(Unknown Source)
    at sun.nio.ch.SharedFileLockTable.add(Unknown Source)
    at sun.nio.ch.FileChannelImpl.tryLock(Unknown Source)
    at org.h2.store.fs.FileNio.tryLock(FilePathNio.java:121)
    at org.h2.mvstore.cache.FilePathCache$FileCache.tryLock(FilePathCache.java:152)
    at java.nio.channels.FileChannel.tryLock(Unknown Source)
    at org.h2.mvstore.FileStore.open(FileStore.java:164)
    ... 71 more

sim

unread,
Aug 6, 2015, 4:59:38 AM8/6/15
to H2 Database
This works for 1.4.188 in my project with no problem

val conn = ds.getConnection
val stat = conn.createStatement()
stat.addBatch("set exclusive 2")
stat.addBatch("shutdown defrag")
stat.executeBatch()
conn.close()

Reinier L'abee

unread,
Aug 6, 2015, 6:54:02 AM8/6/15
to H2 Database
It is not the defrag that fails, it fails when I try to open the connection again....

dbConnection = DriverManager.getConnection("jdbc:h2://C:\\H2DB", "user", "password");
Statement statement = dbConnection.createStatement();
statement.execute("SHUTDOWN DEFRAG");
dbConnection.close(); //is already closed, but just to be sure...
dbConnection = DriverManager.getConnection("jdbc:h2://C:\\H2DB", "user", "password"); //<<<FAILS

The last statement fails with the stack trace I posted...

Op donderdag 6 augustus 2015 10:59:38 UTC+2 schreef sim:

Thomas Mueller

unread,
Aug 10, 2015, 7:59:45 AM8/10/15
to h2-da...@googlegroups.com
Hi,

I don't know what could be the problem. It works for me:

        Connection conn;
        Statement stat;
        DeleteDbFiles.execute("~/temp", "test", false);
        String url = "jdbc:h2:~/temp/test";
        conn = DriverManager.getConnection(url);
        stat = conn.createStatement();
        stat.execute("create table test(id int primary key, date timestamp)");
        stat.execute("shutdown defrag");
        conn = DriverManager.getConnection(url);
        conn.close();

Could you provide a simple, reproducible test case please?

Regards,
Thomas
--
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 h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Shiraz Babar

unread,
Jul 2, 2016, 6:57:52 AM7/2/16
to H2 Database

Hi
Reinier L'abee

You need to properly disconnect from your database connection. You must follow to do so:
  1. Go to your installation directory of H2 in my case(C:\Program Files\Databases\H2\)
  2. Go to bin and run the h2 jar file
  3. Press the connect button you will be login
  4. and then press the left most icon on the task bar 
See also the attach png in which the icon to be press is shown
help.PNG
Reply all
Reply to author
Forward
0 new messages