Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .close() method #51

Closed
danielfdsilva opened this issue Apr 12, 2017 · 6 comments
Closed

Add .close() method #51

danielfdsilva opened this issue Apr 12, 2017 · 6 comments

Comments

@danielfdsilva
Copy link

We have a very specific use case for the osm-p2p-db. The main process that runs the server creates a database. Subsequently, when we try to connect to the database from a different node process, we get a Resource temporarily unavailable because of the LOCK.

Looking through the documentation I wasn't able to find any way to close the db connection. What would be the best way to go about this?

Cc @olafveerman @gmaclennan

@gmaclennan
Copy link
Member

Hi @danielfdsilva,

If you're using osm-p2p-db (as opposed to osm-p2p - a simple wrapper) then you have control of the db instances you pass to the constructor, namely the hyperlog, the leveldb for join indexes, and the abstract-chunk-store (used for the kdb spatial index).

Each of these stores has a close() method usually, that takes a callback. You basically need to close each one yourself. It would result in problems trying to do this in osm-p2p-db because you control the data stores that are passed to osm-p2p-db and they could vary with their methods for closing.

This should be documented better somewhere, and I don't know if their is a better solution.

@hackergrrl
Copy link
Contributor

This makes me realize that osm-p2p really ought to have a close() method.

@gmaclennan gmaclennan changed the title Close connection to database Add .close() method Apr 14, 2017
@danielfdsilva
Copy link
Author

@gmaclennan
I'm actually using osm-p2p, since it prepares all the databases needed to work with osm-p2p-server.

I tried to access the different databases from the instance returned by osm-p2p, but I still get the LOCK error. I'm pretty sure I'm missing some.

I've tried:

db.db.close()
db.log.db.close()
db.kdb.db.close()

Any pointers at which I should be targeting?

@hackergrrl
Copy link
Contributor

hackergrrl commented Apr 18, 2017

Run .close() on:

  • db.db
  • db.log.db
  • db.kdb.kdb.store

(Fun caveat: db.kdb.kdb doesn't exist at creation time; you need to wait a few ticks for it to silently set itself up async in the background.)


Looking at how much source code digging was necessary in order for me to figure that out, it seems a bit unreasonable that osm-p2p and osm-p2p-db don't expose close() methods.

@danielfdsilva
Copy link
Author

@noffle That seems to have done it! thanks :)

@hackergrrl
Copy link
Contributor

Fixed in 4.2.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants