If the files for the fileDB are corrupt it is not possible to recover as the underlying file is not closed
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5.1k
- Forks
- 877
- PR merge metrics
- No merged PRs in 30d
Description
If you try to open a database (mapdb 3.0.7) that is corrupted it is not possible to recover.
That is you can not delete the files and create a clean database programatically as the files are still open (they have not been closed) and on windows this means the file is locked and can not be deleted.
32.872 [id=32] WARNING c.c.opscenter.utils.MapDbHelper#create: THE_DATABASE suspected corrupted
org.mapdb.DBException$WrongFormat: Wrong file header, not MapDB file
at org.mapdb.StoreDirectAbstract.fileHeaderCheck(StoreDirectAbstract.kt:99)
at org.mapdb.StoreDirect.<init>(StoreDirect.kt:114)
at org.mapdb.StoreDirect$Companion.make(StoreDirect.kt:57)
at org.mapdb.StoreDirect$Companion.make$default(StoreDirect.kt:56)
at org.mapdb.DBMaker$Maker.make(DBMaker.kt:450)
at com.example.product.utils.MapDbHelper.doCreateDb(MapDbHelper.java:112)
<snip>
32.872 [id=32] WARNING c.e.product.utils.MapDbHelper#create: Attempting to reset THE_DATABASE. Existing DB (C:\Users\bob\AppData\Local\Temp\uniqueDir\messaging) will be moved to .bak.x files
32.874 [id=32] SEVERE c.c.opscenter.utils.MapDbHelper#create: THE_DATABASE reset failed, please delete C:\Users\bob\AppData\Local\Temp\uniqueDir\messaging, C:\Users\bob\AppData\Local\Temp\uniqueDir\messaging.p and C:\Users\bob\AppData\Local\Temp\uniqueDir\messaging.t to continue.
java.nio.file.FileSystemException: C:\Users\bob\AppData\Local\Temp\uniqueDir\jenkins3035025070772083916test\messaging -> C:\Users\bob\AppData\Local\Temp\uniqueDir\jenkins3035025070772083916test\messaging.bak.1: The process cannot access the file because it is being used by another process.
if the files had been opened they should be closed when an exception occurs.
steps to reproduce,
create some garbage files and place them where MapDB expects to find them.
try and load them with
DBMaker.fileDB(new File(rootDir, name)).closeOnJvmShutdown().make();
catch the ensuing exception
try and delete the files in the catch block.
Note that the files are still open and you can not delete them (on windows, Unix symatics are a little different but on NFS you will see ~.nfs* files which shows the file is still locked and can not be deleted (although it will be cleaned up when the process closes the file handles)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DBMaker.Maker.make in DBMaker.kt and the file-header failure path through StoreDirect and StoreDirectAbstract.fileHeaderCheck. Reproduce the issue using garbage files and the fileDB example, then verify that deleting the database files succeeds after the exception is caught on Windows or that the handles are otherwise released.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100