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.87k stars 873 forks source link

Closing an HTreeMap instance also closes the associated DB instance #1020

Open galfordliu opened 1 year ago

galfordliu commented 1 year ago

I encountered an unexpected behavior when using MapDB 3.0.9 .

According to the documentation and design of MapDB, closing an HTreeMap instance should not affect the associated DB instance. The HTreeMap should no longer be usable after its close method is called, but the associated DB instance should remain open and usable.

However, I observed that when I close an HTreeMap, the DB instance also gets closed. Specifically, after closing an HTreeMap, calling DB.getAllNames throws an exception indicating that the DB was closed.

Here's a snippet of the code that reproduces the problem:

DB db = DBMaker.memoryDB().make();
HTreeMap<String, String> map = db.hashMap("map").createOrOpen();

// use the map...
map.put("key", "value");

// close the map
map.close();

// this throws an exception, saying that the DB was closed
db.getAllNames();

This behavior does not align with the design of MapDB, and I believe it's a bug. The DB should remain open even after the associated HTreeMap is closed. Please kindly look into this issue. Thank you.