You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by ad...@apache.org on 2024/05/10 13:45:20 UTC
(druid) branch 30.0.0 updated: Fix the bug in Immutable RTree object strategy (#16389) (#16426)
This is an automated email from the ASF dual-hosted git repository.
adarshsanjeev pushed a commit to branch 30.0.0
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/30.0.0 by this push:
new 34cb55423e7 Fix the bug in Immutable RTree object strategy (#16389) (#16426)
34cb55423e7 is described below
commit 34cb55423e7190ca4773042d5e6230d46faeefd7
Author: Adarsh Sanjeev <ad...@gmail.com>
AuthorDate: Fri May 10 19:15:13 2024 +0530
Fix the bug in Immutable RTree object strategy (#16389) (#16426)
* Fix the bug in Immutable Node object strategy
* Adding comments in code
Co-authored-by: Pranav <pr...@gmail.com>
---
.../segment/data/ImmutableRTreeObjectStrategy.java | 6 ++--
.../collections/spatial/ImmutableRTreeTest.java | 34 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/processing/src/main/java/org/apache/druid/segment/data/ImmutableRTreeObjectStrategy.java b/processing/src/main/java/org/apache/druid/segment/data/ImmutableRTreeObjectStrategy.java
index c97b69f25c0..8015f79202a 100644
--- a/processing/src/main/java/org/apache/druid/segment/data/ImmutableRTreeObjectStrategy.java
+++ b/processing/src/main/java/org/apache/druid/segment/data/ImmutableRTreeObjectStrategy.java
@@ -63,8 +63,10 @@ public class ImmutableRTreeObjectStrategy implements ObjectStrategy<ImmutableRTr
@Override
public ImmutableRTree fromByteBuffer(ByteBuffer buffer, int numBytes)
{
- buffer.limit(buffer.position() + numBytes);
- return new ImmutableRTree(buffer, bitmapFactory);
+ // always create the duplicate buffer for creating the objects as original buffer may have mutations somewhere else which can corrupt objects
+ ByteBuffer duplicateBuf = buffer.duplicate();
+ duplicateBuf.limit(duplicateBuf.position() + numBytes);
+ return new ImmutableRTree(duplicateBuf, bitmapFactory);
}
@Override
diff --git a/processing/src/test/java/org/apache/druid/collections/spatial/ImmutableRTreeTest.java b/processing/src/test/java/org/apache/druid/collections/spatial/ImmutableRTreeTest.java
index 94edd78275f..6a1228f7a0e 100644
--- a/processing/src/test/java/org/apache/druid/collections/spatial/ImmutableRTreeTest.java
+++ b/processing/src/test/java/org/apache/druid/collections/spatial/ImmutableRTreeTest.java
@@ -48,6 +48,7 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
/**
+ *
*/
@SuppressWarnings("CheckReturnValue")
public class ImmutableRTreeTest
@@ -702,4 +703,37 @@ public class ImmutableRTreeTest
ImmutableBitmap finalSet = bf.union(points);
Assert.assertTrue(finalSet.size() == 100);
}
+
+ @Test
+ public void testForImmutableRTreeImmutability()
+ {
+ BitmapFactory bf = new RoaringBitmapFactory();
+ RTree tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bf), bf);
+ float centerLat = 37.4133961f;
+ float centerLong = -122.1224665f;
+ float[][] insidePoints = SpatialUtils.generateGeoCoordinatesAroundCircle(centerLat, centerLong, 100, 100, true);
+ for (int i = 0; i < insidePoints.length; i++) {
+ tree.insert(insidePoints[i], i);
+ }
+ float[][] outsidePoints = SpatialUtils.generateGeoCoordinatesAroundCircle(centerLat, centerLong, 100, 100, false);
+ for (int i = 0; i < outsidePoints.length; i++) {
+ tree.insert(outsidePoints[i], i);
+ }
+ final ImmutableRTree searchTree = ImmutableRTree.newImmutableFromMutable(tree);
+ ByteBuffer buffer = ByteBuffer.wrap(searchTree.toBytes());
+ ImmutableRTreeObjectStrategy objectStrategy = new ImmutableRTreeObjectStrategy(bf);
+ ImmutableRTree builtTree = objectStrategy.fromByteBuffer(buffer, searchTree.toBytes().length);
+ buffer.position(10);
+ buffer.limit(100);
+
+ for (float[] insidePoint : insidePoints) {
+ Iterable<ImmutableBitmap> points = builtTree.search(new RadiusBound(
+ new float[]{insidePoint[0], insidePoint[1]},
+ 100,
+ 2,
+ RadiusBound.RadiusUnit.meters
+ ));
+ bf.union(points);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org