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

Shape plugin keeps stale references to deleted files #784

Open
artemp opened this issue Oct 11, 2011 · 11 comments
Open

Shape plugin keeps stale references to deleted files #784

artemp opened this issue Oct 11, 2011 · 11 comments

Comments

@artemp
Copy link
Member

artemp commented Oct 11, 2011

Mapnik (trunk) seems to keep shapefiles open once it finishes with them which causes stale data to be rendered if the file is deleted and replaced with another one with the same name in the meantime. lsof confirms it:

# After rendering isocronas.shp:
sigym@sigym-staging2:~$ md5sum /var/local/sigym/ctxs/propag_luis_k1c2dk/isocronas.shp
7649e466bc4a8ff01d370de569a1fa87  /var/local/sigym/ctxs/propag_luis_k1c2dk/isocronas.shp
# set ISOCRONAS_INODE to the inode of this file retrieved with stat
sigym@sigym-staging2:~$ lsof | grep $ISOCRONAS_INODE
apache2    6614    sigym  mem       REG      202,6     68204 3132969133 /var/local/sigym/ctxs/propag_luis_k1c2dk/isocronas.shp
# some process modifies isocronas.shp...
md5sum /var/local/sigym/ctxs/propag_luis_k1c2dk/isocronas.shp
285b592e4f0130750e99e8ba88057107  /var/local/sigym/ctxs/propag_luis_k1c2dk/isocronas.shp
sigym@sigym-staging2:~$ lsof | grep $ISOCRONAS_INODE
apache2    6614    sigym  DEL       REG      202,6           3132969133 /var/local/sigym/ctxs/propag_luis_k1c2dk/isocronas.shp
# notice how apache2 still refers to the old and deleted file

If apache is restarted then the correct shapefile is rendered. This regression was introduced somewhen after r2344 but I can't find the exact revision. Any clues?

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[albertov] I forgot to add that the Map, Datasource and every related instances are freshly created for every render by my app, they are not reused (which might have explained this behavior).

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[albertov] Configuring mapnik with {{{SHAPE_MEMORY_MAPPED_FILE=False}}} fixes (or works-around?) the issue. Perhaps the code-paths taken when setting this setting should take into account if the file's inode has changed? or perhaps make this a runtime configuration option instead of a compile-time option for shapefiles which are expected to be replaced?

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[artem] We need to check if mapping region is still valid when returning cached pointer. Couple ways to fix it, thanks for reporting this!

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[albertov] Can I help with closing this before 2.0.1? If no definite solution can be found perhaps {{{SHAPE_MEMORY_MAPPED_FILE}}} can be set to False by default before the release so packagers don't end up distributing versions with this bug.

Alberto

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] I've assumed that memory mapping being default on is pretty critical for performance, but have never actually tested. alberto, is this something you could do? See how much of a benefit the mapping gives for indexed shapefiles? If it does not have a big benefit then I might feel different about disabling this by default. Either way I figure it would be nice to have it as a runtime option eventually.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] see also https://github.com/mapbox/tilemill/issues/714 which may be related to the mapped regions being invalid - not sure...

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[springmeyer] alberto - also note that the issue may not be the memory mapping but that we cache the mapped regions. it would likely be pretty easy to add an option to the shapefile driver to be able to still use memory mapping, but just not to cache the regions.

@artemp
Copy link
Member Author

artemp commented Oct 11, 2011

[artem] Moving to 2.0.1

@springmeyer
Copy link
Member

@albertov - hey there, is this still problematic for you? Take a look at #1022 - would exposing the clear() method in python be enough for you?

@springmeyer
Copy link
Member

moving to 2.1

@pessimo
Copy link

pessimo commented Aug 2, 2018

sorry to be here. I just try to use clear_cache() in python to apply some tiny modify in shapefile. however it seems not working. Is it already a function in python? I'm using version 3.0.20

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

No branches or pull requests

3 participants