[gdal-dev] Corrupted .shp error when reading shapefile from multiple threads

kedardeshpande87 kedardeshpande87 at gmail.com
Wed Aug 1 17:05:10 PDT 2012


Hi,

I am writing an application in Java with gdal's java bindings that reads a
zipcode layer shapefile.
I set a spatial filter of a point on the layer and get the zipcode by
reading from the layer.
...
DataSource ds = ogr.Open("path/to/shapefile");
Layer layer = ds.GetLayer(0);
...
public void getZipCode(double lat, double lon) {
  Geometry g = new Geometry(1); // Passing the geometry type. 1 for point.
  g.AddPoint(lon, lat);
  layer.SetSpatialFilter(g);
  Feature f = null;
  while((f = layer.GetNextFeature()) != null) {
     String zipcode = f.GetFieldAsString(0);   // 0th field is zipcode
  }
}

Above is a snippet of the code I am writing. Now, when call this
getZipCode() function for multiple times (like in a loop), it works fine.
But when I call this function from multiple parallel threads, I am getting
an error saying corrupted .shp file. This error is showing up only when I
make simultaneous reads on the shapefile from many threads.  The error is as
follows:

ERROR 1: Corrupted .shp file : shape 6, nPoints=677, nParts=1,
nEntitySize=5256.

Sometimes I get an error like this :

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000000379fa72faf, pid=26152, tid=1120618816
#
# JRE version: 6.0_32-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.7-b02 mixed mode
linux-amd64 compressed oops)
# Problematic frame:
# C  [libc.so.6+0x72faf]  _dl_tls_get_addr_soft@@GLIBC_PRIVATE+0x72faf
#
# An error report file with more information is saved as:
# /rhel5pdi/home/kdeshpan/workspace/GDAL_Java_Cpp/hs_err_pid26152.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

I really want this to work in a multithreaded environment.

I am not modifying the shapefile, I am only reading the zip code information
from the shapefile. So I am getting why is the shapefile corrupted.
Moreover, if I use the same shapefile after getting this error and make
synchronous requests, it works. So I am guessing the shapefile is not
actually corrupted and it is showing the error because of something else.
Is this the expected bahavior from OGR library? Does it not support
multithreaded env ?
Or is it that there is some problem with the Java bindings ?
Can someone please suggest me how I can resolve this or get around this
issue ?

Thanks!
Kedar



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Corrupted-shp-error-when-reading-shapefile-from-multiple-threads-tp4992566.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list