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

GeoTiffRasterSource should be thread-safe #2954

Closed
echeipesh opened this issue May 30, 2019 · 1 comment · Fixed by geotrellis/geotrellis-contrib#206
Closed

GeoTiffRasterSource should be thread-safe #2954

echeipesh opened this issue May 30, 2019 · 1 comment · Fixed by geotrellis/geotrellis-contrib#206
Assignees
Labels
Milestone

Comments

@echeipesh
Copy link
Contributor

When using GeoTiffRasterSource instance in multi-threaded context, either in spark multi-partition per executor or as part of async http4s application the following error is possible:

[info] java.lang.IllegalArgumentException
[info] at java.nio.Buffer.position(Buffer.java:244)
[info] at geotrellis.util.StreamingByteReader.ensureChunk(StreamingByteReader.scala:114)
[info] at geotrellis.util.StreamingByteReader.getBytes(StreamingByteReader.scala:118)
[info] at geotrellis.raster.io.geotiff.LazySegmentBytes.getBytes(LazySegmentBytes.scala:120)
[info] at geotrellis.raster.io.geotiff.LazySegmentBytes$$anonfun$readChunk$1.apply(LazySegmentBytes.scala:99)
[info] at geotrellis.raster.io.geotiff.LazySegmentBytes$$anonfun$readChunk$1.apply(LazySegmentBytes.scala:97)
[info] at scala.collection.immutable.List.map(List.scala:284)
[info] at geotrellis.raster.io.geotiff.LazySegmentBytes.readChunk(LazySegmentBytes.scala:97)
[info] at geotrellis.raster.io.geotiff.LazySegmentBytes$$anonfun$getSegments$1.apply(LazySegmentBytes.scala:115)
[info] at geotrellis.raster.io.geotiff.LazySegmentBytes$$anonfun$getSegments$1.apply(LazySegmentBytes.scala:115)
[info] at scala.collection.Iterator$$anon$12.nextCur(Iterator.scala:435)
[info] at scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:441)
[info] at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:462)
[info] at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)
[info] at scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:440)
[info] at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)
[info] at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)
[info] at geotrellis.contrib.vlm.geotiff.GeoTiffRasterSource.read(GeoTiffRasterSource.scala:58)
[info] at geotrellis.contrib.vlm.RasterSource$class.read(RasterSource.scala:163)
[info] at geotrellis.contrib.vlm.geotiff.GeoTiffRasterSource.read(GeoTiffRasterSource.scala:28)

This happens because underlying geotrellis.raster.io.geotiff.LazySegmentBytes nor GeoTiffTile which uses it is not thread safe. GeoTiffReader does not make promises about being thread safe, but RasterSource makes an implicit promise to be thread safe and thats a useful expectation.

For this issue I suggest:

  • Use synchronize on GeoTiff[MultibandTile] contained by GeoTiffRasterSource to make all read methods thread-safe
  • Update the documentation on RasterSource interface to state that thread-safe behavior is expected
@echeipesh echeipesh added the bug label May 30, 2019
@pomadchin
Copy link
Member

pomadchin commented May 30, 2019

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

Successfully merging a pull request may close this issue.

3 participants