jankotek/JDBM3 — pull request #68 by hamishmorgan (2012-04-18 18:27:04+00:00)
Title: Option to disabled file locking

Hi Jan,

I've integrated JDBM3 into my application (https://github.com/MLCL/Byblo) and for the most part it performs perfectly. Thanks for the great work you are putting into this.

The only issue I've had is that my application is frequently run on a non-local file-system such as Lustre or NFS. These file-systems do not support locking. Calls to ```FileChannel.tryLock``` and ```FileChannel.lock``` result in an IOException:

```
Exception in thread "main" java.io.IOError: java.io.IOException: Could not lock DB file: ../out/medtest.entry-index
at net.kotek.jdbm.DBStore.reopen(DBStore.java:172)
at net.kotek.jdbm.DBStore.(DBStore.java:154)
at net.kotek.jdbm.DBCache.(DBCache.java:45)
at net.kotek.jdbm.DBCacheMRU.(DBCacheMRU.java:73)
at net.kotek.jdbm.DBMaker.make(DBMaker.java:335)
at [... application stack trace ...]
Caused by: java.io.IOException: Could not lock DB file: ../out/medtest.entry-index
at net.kotek.jdbm.StorageDiskMapped.(StorageDiskMapped.java:51)
at net.kotek.jdbm.PageFile.(PageFile.java:97)
at net.kotek.jdbm.DBStore.reopen(DBStore.java:160)
... 19 more
Caused by: java.io.IOException: Function not implemented
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:832)
at java.nio.channels.FileChannel.lock(FileChannel.java:860)
at net.kotek.jdbm.StorageDiskMapped.(StorageDiskMapped.java:49)
... 21 more
```

There doesn't seem to any elegant way of detecting this problem before hand. Catching the exception is difficult since a generic IOException could be caused by any number of things. The only clue is in the message text, which presumably changes with the system language, and besides the text is hardly defined in the API so could change at any time.

As a work-around I've added a "disableLocking" option to DBMaker, which is passed down to StorageDiskMapped and StorageDisk.

I'm not sure of the significance of this issue. It's critical in terms of my use case, but I suspect that few people will be running their software on this kind of infrastructure. So anyway... I submit this patch for you consideration.

Thanks again for your work on this great project.

Kind regards,

Hamish