-
Notifications
You must be signed in to change notification settings - Fork 448
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
Fix SortedPackedIntervalRtree to be thread-safe #746
Fix SortedPackedIntervalRtree to be thread-safe #746
Conversation
Signed-off-by: veselovs <[email protected]>
Can you describe the core changes which allow concurrency? |
|
||
private void printNode(IntervalRTreeNode node) | ||
{ | ||
System.out.println(WKTWriter.toLineString(new Coordinate(node.min, level), new Coordinate(node.max, level))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is a dead code, method never invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just comment it out then. It may be used for debugging in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@@ -102,15 +102,13 @@ public int locate(Coordinate p) | |||
private synchronized void createIndex() { | |||
if (index == null) { | |||
index = new IntervalIndexedGeometry(geom); | |||
// no need to hold onto geom | |||
geom = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason the geometry can't be freed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that final geom
field looks clearer, and the performance effect of nulling it is likely negligible.
However, it can be safely nulled, fixed in this way.
@@ -68,7 +66,7 @@ public void insert(double min, double max, Object item) | |||
leaves.add(new IntervalRTreeLeafNode(min, max, item)); | |||
} | |||
|
|||
private void init() | |||
private synchronized void init() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is the key change for concurrency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. From practical viewpoint only this change is enough to fix the problem.
Other changes make the code formally correct from concurrency viewpoint , + add some cleanup .
@@ -0,0 +1,67 @@ | |||
package org.locationtech.jts.geom.prep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go into the test.jts.perf.geom.prep
package, because:
- it requires custom VM settings
- it is not guaranteed to reveal the issue on every run
- it may require significant execution time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Critical change is synchronizing method org.locationtech.jts.index.intervalrtree.SortedPackedIntervalRTree#init . Other changes make the code more correct and reliable from the concurrency viewpoint, e.g "double-checked locking" in method org.locationtech.jts.algorithm.locate.IndexedPointInAreaLocator#createIndex can only work correctly if |
SortedPackedIntervalRtree
is not thread-safe, because theinit
method is not synchronized. This ensures thatPreparedPolygon
is thread-safe.This also contains some cleanup for
IndexedPointInAreaLocator
.Fixes #747.
Signed-off-by: veselovs [email protected]