nhachicha/SnappyDB

com.snappydb.SnappydbException: Your database is still open, please close it before

Opened this issue · 9 comments

I have closed the database, verified that the database the close method is still being called and yet, I am still facing this issue.

if (snappydb != null && snappydb.isOpen()) {
    snappydb.close();
}

this is how I am opening the database

if(name.equals(Constant.DB_DEFAULT))
    snappydb = DBFactory.open(App.getInstance());
else
    snappydb = DBFactory.open(App.getInstance(), name);

I have investigated this issue further and concluded.
I can only even have one open database connection ever per process. Even if I am opening based with another name.
The database closes, but because one is already open, I am stuck.
Also, I cannot open the database in only read mode.

These are real show stoppers for me. Even though I rewrote my app to use this library, I guess I will need to change my storage again. I really liked it but....

Hi.
SnappyDB is a singleton in Java here AND a singleton in JNI here.

Now you are not using the singleton in JAVA but you cannot not use the singleton in JNI.

Feel free to propose a pull request correcting that ;)

I am using a singleton. But I faced issues using it across processes because I simply kept the connection open. I decided then to open split the database so that the second process could use that, and instead open a close it in demand in the main process.
However, snappy does not treat named databases as separate from what I can tell and I therefore need to close any previous open database before opening a new one.
So if I open the default, I can't open another one using a name.

Lets just say I found a solution to the problem.

In the application class, I'm keeping a ref to snappydb. However, to get an instance, I pass the name of the db. If it is not the currently held instance, I close it and open the new one.
Whenever I open the named database in the main process, I close it immediately after. Therefore, the app can get am instance of the main db when it needs it and I hardly open the other in the main.
So far, it works and I haven't encountered any race conditions yet though it is bound to happen at some point. Though I am assuming very very rarely. So it's fine for me.
I just like the library too much because it works perfectly for my json data and the serialising is smooth and works.

I just wish you would allow open modes. Eg. Read write, read only etc. That would really be great.
Also treat named databases as separate. That will solve a lot of issues.

Hi @frostymarvelous thanks for sharing your feedback. I included this as an enhancement.

Thanks a bunch.

That was annoying me too.
At the beginning I use two database and then I found it cannot be open at the same time
So I changed to use unique database to store all data.

This is a big limitation. I am using snappydb to write logs. This means while logging is going on I can't use the db for other (primary) purposes, which breaks everything.

Would like to add to the above comment that snappydb is a really cool lib. Thanks a ton!