jankotek / mapdb

MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap-memory. It is a fast and easy to use embedded Java database engine.
https://mapdb.org
Apache License 2.0
4.89k stars 873 forks source link

MapDB treemap.clear() takes forever #919

Open stiv-yakovenko opened 5 years ago

stiv-yakovenko commented 5 years ago

I have treemap in mapdb with 150K entries. Calling treemap.clear() takes minutes. How can I do this quickly? Creating new one with

db.treeMap("pageCache").create();

gives crash org.mapdb.DBException$WrongConfiguration: Named record already exists: pageCache. How can I clear collection in a reasonable time?

Thanx.

stiv-yakovenko commented 5 years ago

I also tried alternative approach:

 db.close();
        try {
            Files.delete(Paths.get(DB_FILE_NAME));
        } catch (IOException e) {
            e.printStackTrace();
        }
        db = DBMaker
                .fileDB(DB_FILE_NAME).transactionEnable()
                .make();

but I get

Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.stivyakovenko.WebServer.main(WebServer.java:71)
Caused by: org.mapdb.DBException$FileLocked: File is already opened and is locked: ./db/simple
        at org.mapdb.volume.Volume.lockFile(Volume.java:502)
        at org.mapdb.volume.RandomAccessFileVol.<init>(RandomAccessFileVol.java:52)
        at org.mapdb.volume.RandomAccessFileVol$1.makeVolume(RandomAccessFileVol.java:26)
        at org.mapdb.StoreWAL$realVolume$1.invoke(StoreWAL.kt:75)
        at org.mapdb.StoreWAL$realVolume$1.invoke(StoreWAL.kt:18)
        at org.mapdb.StoreWAL.<init>(StoreWAL.kt:74)
        at org.mapdb.StoreWAL$Companion.make(StoreWAL.kt:56)
        at org.mapdb.StoreWAL$Companion.make$default(StoreWAL.kt:55)
        at org.mapdb.DBMaker$Maker.make(DBMaker.kt:464)
        at org.stivyakovenko.SimpleDB.<clinit>(SimpleDB.java:21)
        ... 1 more