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

How to disconnect mapnik::Map from data sources? #2554

Open
kking009 opened this issue Oct 28, 2014 · 5 comments
Open

How to disconnect mapnik::Map from data sources? #2554

kking009 opened this issue Oct 28, 2014 · 5 comments
Labels

Comments

@kking009
Copy link

Between two map rendering sessions I want/must restart my PostGreSQL/PostGIS server. After the server start the next call to load_map ends in a Exception!
I miss a method to disconnect a Map from the Data-Sources. I could call it before I stop the server...

mapnik::Map myMap;
myMap = new mapnik::Map(4000, 3000);
load_map(myMap, stylesheet1);
// rendering, rendering...
// Now I would like to disconnect myMap from the data sources, but how? 
delete myMap;
Sleep(20000);
// Now I stop my PostGreSQL/PostGIS server
// Now I start my PostGreSQL/PostGIS server
myMap = new mapnik::Map(4000, 3000);
load_map(myMap, stylesheet2); // -> Exception!!! ### std::exception: no connection to the server
// rendering, rendering...

What I need is a kind of unload_map. The distructor of myMap is not doing the job!

My current work-around:
I deliberately run into the exception. The Mapnik now understands, that there is no connection to the data sources. The next call to load_map works again. I don't find it nice running deliberately into an exception only to disconnect from the data sources.

@artemp
Copy link
Member

artemp commented Oct 28, 2014

@kking009 - could you try iterating over layers and resetting datasources - something like (untested)

for (auto & layer : layers)
{
      layer.datasource()->reset();
}

@kking009
Copy link
Author

Just tried it out, it didn't resolve the problem! Its logical, as reset() is a method inherited from shared_ptr.hpp and therefor it can't disconnect from the PostGIS server or unlock a shape file.
If you are interested in the use-case, see TopoMapCreator.

@jchamberlain
Copy link

I'd love to have the ability to disconnect. In a multi-tenant app with lots of Postgres users and therefore lots of connections, stale connections are proving to be a big problem. In fact, it'd be wonderful if connection pooling could be disabled entirely, or given very short expirations. Then we just let pgBouncer handle it all.

Is there a possibility of these features being added?

@flippmoke
Copy link
Member

Is there a possibility of these features being added?

Most honest answer would be yes, we would love to have more features around postgis. However, more then likely we would need the help of someone else to do this due to time constraints.

@jchamberlain
Copy link

Understood. Well, if I ever pick up C++ for real, I'll get back to this. In the meantime, thanks for your work on Mapnik. It's a great piece of software.

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

No branches or pull requests

5 participants