adelapena commented on code in PR #2487:
URL: https://github.com/apache/cassandra/pull/2487#discussion_r1263640840
##########
test/unit/org/apache/cassandra/index/sai/disk/v1/bbtree/BlockBalancedTreeReaderTest.java:
##########
@@ -162,66 +166,118 @@ public void testSameValuesInLeaf() throws Exception
final BlockBalancedTreeRamBuffer buffer = new
BlockBalancedTreeRamBuffer(Integer.BYTES);
byte[] scratch = new byte[4];
- for (int docID = 0; docID < 10; docID++)
+ for (int rowID = 0; rowID < 10; rowID++)
{
- NumericUtils.intToSortableBytes(docID, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
}
- for (int docID = 10; docID < 20; docID++)
+ for (int rowID = 10; rowID < 20; rowID++)
{
NumericUtils.intToSortableBytes(10, scratch, 0);
- buffer.add(docID, scratch);
+ buffer.add(rowID, scratch);
}
- for (int docID = 20; docID < 30; docID++)
+ for (int rowID = 20; rowID < 30; rowID++)
{
- NumericUtils.intToSortableBytes(docID, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
}
- final BlockBalancedTreeReader reader = finishAndOpenReader(5, buffer);
-
- PostingList postingList = performIntersection(reader, buildQuery(8,
15));
-
- assertEquals(8, postingList.nextPosting());
- assertEquals(9, postingList.nextPosting());
- assertEquals(10, postingList.nextPosting());
- assertEquals(11, postingList.nextPosting());
- assertEquals(12, postingList.nextPosting());
- assertEquals(13, postingList.nextPosting());
- assertEquals(14, postingList.nextPosting());
- assertEquals(15, postingList.nextPosting());
- assertEquals(16, postingList.nextPosting());
- assertEquals(17, postingList.nextPosting());
- assertEquals(18, postingList.nextPosting());
- assertEquals(19, postingList.nextPosting());
- assertEquals(PostingList.END_OF_STREAM, postingList.nextPosting());
+ try (BlockBalancedTreeReader reader = finishAndOpenReader(5, buffer))
+ {
+ PostingList postingList = performIntersection(reader,
buildQuery(8, 15));
+
+ assertEquals(8, postingList.nextPosting());
+ assertEquals(9, postingList.nextPosting());
+ assertEquals(10, postingList.nextPosting());
+ assertEquals(11, postingList.nextPosting());
+ assertEquals(12, postingList.nextPosting());
+ assertEquals(13, postingList.nextPosting());
+ assertEquals(14, postingList.nextPosting());
+ assertEquals(15, postingList.nextPosting());
+ assertEquals(16, postingList.nextPosting());
+ assertEquals(17, postingList.nextPosting());
+ assertEquals(18, postingList.nextPosting());
+ assertEquals(19, postingList.nextPosting());
+ assertEquals(PostingList.END_OF_STREAM, postingList.nextPosting());
+ }
}
@Test
public void testResourcesReleaseWhenQueryDoesntMatchAnything() throws
Exception
{
final BlockBalancedTreeRamBuffer buffer = new
BlockBalancedTreeRamBuffer(Integer.BYTES);
byte[] scratch = new byte[4];
- for (int docID = 0; docID < 1000; docID++)
+ for (int rowID = 0; rowID < 1000; rowID++)
{
- NumericUtils.intToSortableBytes(docID, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
}
// add a gap between 1000 and 1100
- for (int docID = 1000; docID < 2000; docID++)
+ for (int rowID = 1000; rowID < 2000; rowID++)
{
- NumericUtils.intToSortableBytes(docID + 100, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID + 100, scratch, 0);
+ buffer.add(rowID, scratch);
}
- final BlockBalancedTreeReader reader = finishAndOpenReader(50, buffer);
+ try (BlockBalancedTreeReader reader = finishAndOpenReader(50, buffer))
+ {
+ final PostingList intersection = performIntersection(reader,
buildQuery(1017, 1096));
+ assertNull(intersection);
+ }
+ }
- final PostingList intersection = performIntersection(reader,
buildQuery(1017, 1096));
- assertNull(intersection);
+ @Test
+ public void testConcurrentIntersectionsOnSameReader() throws Exception
+ {
+ int numRows = 1000;
+
+ final BlockBalancedTreeRamBuffer buffer = new
BlockBalancedTreeRamBuffer(Integer.BYTES);
+
+ byte[] scratch = new byte[4];
+ for (int rowID = 0; rowID < numRows; rowID++)
+ {
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
+ }
+
+ try (BlockBalancedTreeReader reader = finishAndOpenReader(4, buffer))
+ {
+ int concurrency = 100;
+
+ ExecutorService executor =
Executors.newFixedThreadPool(concurrency);
+ List<Future<?>> results = new ArrayList<>();
+ for (int thread = 0; thread < concurrency; thread++)
+ {
+ results.add(executor.submit(() -> assertRange(reader, 445,
555)));
+ }
+ FBUtilities.waitOnFutures(results);
+ executor.shutdown();
+ }
+ }
+
+ private void assertRange(BlockBalancedTreeReader reader, long lowerBound,
long upperBound)
+ {
+ Expression expression = new Expression(indexContext);
+ expression.add(Operator.GT, Int32Type.instance.decompose(444));
+ expression.add(Operator.LT, Int32Type.instance.decompose(555));
+
+ try
+ {
+ PostingList intersection = performIntersection(reader,
BlockBalancedTreeQueries.balancedTreeQueryFrom(expression, 4));
+ assertNotNull(intersection);
+ assertEquals(110, intersection.size());
+ for (long posting = lowerBound; posting < upperBound; posting++)
+ assertEquals(posting, intersection.nextPosting());
+ }
+ catch (IOException e)
+ {
+ throw Throwables.unchecked(e);
+ }
}
+
Review Comment:
Nit: unneeded blank line
##########
test/unit/org/apache/cassandra/index/sai/disk/v1/bbtree/BlockBalancedTreeReaderTest.java:
##########
@@ -162,66 +166,118 @@ public void testSameValuesInLeaf() throws Exception
final BlockBalancedTreeRamBuffer buffer = new
BlockBalancedTreeRamBuffer(Integer.BYTES);
byte[] scratch = new byte[4];
- for (int docID = 0; docID < 10; docID++)
+ for (int rowID = 0; rowID < 10; rowID++)
{
- NumericUtils.intToSortableBytes(docID, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
}
- for (int docID = 10; docID < 20; docID++)
+ for (int rowID = 10; rowID < 20; rowID++)
{
NumericUtils.intToSortableBytes(10, scratch, 0);
- buffer.add(docID, scratch);
+ buffer.add(rowID, scratch);
}
- for (int docID = 20; docID < 30; docID++)
+ for (int rowID = 20; rowID < 30; rowID++)
{
- NumericUtils.intToSortableBytes(docID, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
}
- final BlockBalancedTreeReader reader = finishAndOpenReader(5, buffer);
-
- PostingList postingList = performIntersection(reader, buildQuery(8,
15));
-
- assertEquals(8, postingList.nextPosting());
- assertEquals(9, postingList.nextPosting());
- assertEquals(10, postingList.nextPosting());
- assertEquals(11, postingList.nextPosting());
- assertEquals(12, postingList.nextPosting());
- assertEquals(13, postingList.nextPosting());
- assertEquals(14, postingList.nextPosting());
- assertEquals(15, postingList.nextPosting());
- assertEquals(16, postingList.nextPosting());
- assertEquals(17, postingList.nextPosting());
- assertEquals(18, postingList.nextPosting());
- assertEquals(19, postingList.nextPosting());
- assertEquals(PostingList.END_OF_STREAM, postingList.nextPosting());
+ try (BlockBalancedTreeReader reader = finishAndOpenReader(5, buffer))
+ {
+ PostingList postingList = performIntersection(reader,
buildQuery(8, 15));
+
+ assertEquals(8, postingList.nextPosting());
+ assertEquals(9, postingList.nextPosting());
+ assertEquals(10, postingList.nextPosting());
+ assertEquals(11, postingList.nextPosting());
+ assertEquals(12, postingList.nextPosting());
+ assertEquals(13, postingList.nextPosting());
+ assertEquals(14, postingList.nextPosting());
+ assertEquals(15, postingList.nextPosting());
+ assertEquals(16, postingList.nextPosting());
+ assertEquals(17, postingList.nextPosting());
+ assertEquals(18, postingList.nextPosting());
+ assertEquals(19, postingList.nextPosting());
+ assertEquals(PostingList.END_OF_STREAM, postingList.nextPosting());
+ }
}
@Test
public void testResourcesReleaseWhenQueryDoesntMatchAnything() throws
Exception
{
final BlockBalancedTreeRamBuffer buffer = new
BlockBalancedTreeRamBuffer(Integer.BYTES);
byte[] scratch = new byte[4];
- for (int docID = 0; docID < 1000; docID++)
+ for (int rowID = 0; rowID < 1000; rowID++)
{
- NumericUtils.intToSortableBytes(docID, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
}
// add a gap between 1000 and 1100
- for (int docID = 1000; docID < 2000; docID++)
+ for (int rowID = 1000; rowID < 2000; rowID++)
{
- NumericUtils.intToSortableBytes(docID + 100, scratch, 0);
- buffer.add(docID, scratch);
+ NumericUtils.intToSortableBytes(rowID + 100, scratch, 0);
+ buffer.add(rowID, scratch);
}
- final BlockBalancedTreeReader reader = finishAndOpenReader(50, buffer);
+ try (BlockBalancedTreeReader reader = finishAndOpenReader(50, buffer))
+ {
+ final PostingList intersection = performIntersection(reader,
buildQuery(1017, 1096));
+ assertNull(intersection);
+ }
+ }
- final PostingList intersection = performIntersection(reader,
buildQuery(1017, 1096));
- assertNull(intersection);
+ @Test
+ public void testConcurrentIntersectionsOnSameReader() throws Exception
+ {
+ int numRows = 1000;
+
+ final BlockBalancedTreeRamBuffer buffer = new
BlockBalancedTreeRamBuffer(Integer.BYTES);
+
+ byte[] scratch = new byte[4];
+ for (int rowID = 0; rowID < numRows; rowID++)
+ {
+ NumericUtils.intToSortableBytes(rowID, scratch, 0);
+ buffer.add(rowID, scratch);
+ }
+
+ try (BlockBalancedTreeReader reader = finishAndOpenReader(4, buffer))
+ {
+ int concurrency = 100;
+
+ ExecutorService executor =
Executors.newFixedThreadPool(concurrency);
+ List<Future<?>> results = new ArrayList<>();
+ for (int thread = 0; thread < concurrency; thread++)
+ {
+ results.add(executor.submit(() -> assertRange(reader, 445,
555)));
+ }
+ FBUtilities.waitOnFutures(results);
+ executor.shutdown();
+ }
+ }
+
+ private void assertRange(BlockBalancedTreeReader reader, long lowerBound,
long upperBound)
Review Comment:
Nit: add `@SuppressWarnings("SameParameterValue")
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]