This is an automated email from the ASF dual-hosted git repository.

blambov pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e9198d6a66 Fix incorrect value of preload flag for opening BTI 
partition indexes
e9198d6a66 is described below

commit e9198d6a660c96c21fe1c5bf0bbf19fbfc619189
Author: Branimir Lambov <[email protected]>
AuthorDate: Tue Jul 18 23:45:08 2023 +0300

    Fix incorrect value of preload flag for opening BTI partition indexes
    
    patch by Branimir Lambov; reviewed by Jacek Lewandowski for CASSANDRA-18677
---
 .../format/bti/BtiTableReaderLoadingBuilder.java   |  2 +-
 .../io/sstable/format/bti/LoadingBuilderTest.java  | 96 ++++++++++++++++++++++
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git 
a/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableReaderLoadingBuilder.java
 
b/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableReaderLoadingBuilder.java
index 0e4a74de5a..3128f06a24 100644
--- 
a/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableReaderLoadingBuilder.java
+++ 
b/src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableReaderLoadingBuilder.java
@@ -122,7 +122,7 @@ public class BtiTableReaderLoadingBuilder extends 
SortedTableReaderLoadingBuilde
 
             if (builder.getComponents().contains(Components.PARTITION_INDEX))
             {
-                
builder.setPartitionIndex(openPartitionIndex(builder.getFilter().isInformative()));
+                
builder.setPartitionIndex(openPartitionIndex(!builder.getFilter().isInformative()));
                 if (builder.getFirst() == null || builder.getLast() == null)
                 {
                     builder.setFirst(builder.getPartitionIndex().firstKey());
diff --git 
a/test/unit/org/apache/cassandra/io/sstable/format/bti/LoadingBuilderTest.java 
b/test/unit/org/apache/cassandra/io/sstable/format/bti/LoadingBuilderTest.java
new file mode 100644
index 0000000000..a56ca8e537
--- /dev/null
+++ 
b/test/unit/org/apache/cassandra/io/sstable/format/bti/LoadingBuilderTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.io.sstable.format.bti;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.junit.Assume;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.io.sstable.Descriptor;
+import org.apache.cassandra.io.sstable.format.SSTableReader;
+import org.apache.cassandra.io.util.File;
+import org.jboss.byteman.contrib.bmunit.BMRule;
+import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(BMUnitRunner.class)
+public class LoadingBuilderTest extends CQLTester
+{
+    public static Map<String, Boolean> preloadsMap = new ConcurrentHashMap<>();
+
+    @Test
+    @BMRule(name = "Save preload argument of PartitionIndex initialization",
+            targetClass = 
"org.apache.cassandra.io.sstable.format.bti.PartitionIndex",
+            targetMethod = "load(org.apache.cassandra.io.util.FileHandle, 
org.apache.cassandra.dht.IPartitioner, boolean)",
+            action = 
"org.apache.cassandra.io.sstable.format.bti.LoadingBuilderTest.preloadsMap.put($1.path(),
 $3)")
+    public void testPreloadFlag()
+    {
+        Assume.assumeTrue(BtiFormat.isSelected());
+        testPreloadFlag(false);
+        testPreloadFlag(true);
+    }
+
+    private void testPreloadFlag(boolean disableBloomFilter)
+    {
+        createTable("CREATE TABLE %s (k int PRIMARY KEY, v int) WITH 
bloom_filter_fp_chance = " +
+                    (disableBloomFilter ? "1" : "0.01"));
+        for (int i = 0; i < 100; ++i)
+            execute("INSERT INTO %s (k, v) VALUES (?, ?)", i, i);
+        flush();
+
+        ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
+        Set<SSTableReader> ssTables = cfs.getLiveSSTables();
+        assertTrue(!ssTables.isEmpty());
+
+        for (SSTableReader rdr : ssTables)
+        {
+            Descriptor descriptor = rdr.descriptor;
+            File partitionIndexFile = 
descriptor.fileFor(BtiFormat.Components.PARTITION_INDEX);
+            // When we flush we should never preload the index file
+            verifyPreloadMatches(false, partitionIndexFile);
+
+            // But when we reopen the file from disk, we should do it if there 
is no bloom filter
+            SSTableReader newReader = SSTableReader.open(cfs, descriptor);
+            try
+            {
+                verifyPreloadMatches(disableBloomFilter, partitionIndexFile);
+            }
+            finally
+            {
+                newReader.selfRef().release();
+            }
+        }
+    }
+
+    private static void verifyPreloadMatches(boolean disableBloomFilter, File 
partitionIndexFile)
+    {
+        Boolean preload = preloadsMap.get(partitionIndexFile.path());
+        assertNotNull(partitionIndexFile.toString(), preload);
+        assertEquals(disableBloomFilter, preload.booleanValue());
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to