Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.apache.cassandra.bridge;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -50,7 +49,7 @@ public enum CassandraVersion
this.number = number;
this.name = name;
this.jarBaseName = jarBaseName;
this.sstableFormats = new HashSet<>(Arrays.asList(sstableFormats));
this.sstableFormats = Set.copyOf(Arrays.asList(sstableFormats));
}

public int versionNumber()
Expand All @@ -68,6 +67,11 @@ public String jarBaseName()
return jarBaseName;
}

public Set<String> supportedSSTableFormats()
{
return sstableFormats;
}

private static final String sstableFormat;
private static final CassandraVersion[] implementedVersions;
private static final String[] supportedVersions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class TestUtils
* read repairs.
*/
public static final String CREATE_TEST_TABLE_STATEMENT =
"CREATE TABLE IF NOT EXISTS %s (id int, course text, marks int, PRIMARY KEY (id)) WITH read_repair='NONE';";
"CREATE TABLE IF NOT EXISTS %s (id int, course text, marks int, PRIMARY KEY (id, course)) WITH read_repair='NONE';";

private TestUtils()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.analytics;

import java.util.HashMap;
import java.util.Map;

import org.apache.cassandra.bridge.CassandraVersion;
import org.apache.cassandra.testing.ClusterBuilderConfiguration;
import org.apache.cassandra.testing.TestUtils;

import static org.assertj.core.api.Assumptions.assumeThat;


/**
* A simple test that runs a sample read/write Cassandra Analytics job using BTI format SSTable.
*/
class CassandraAnalyticsSimpleBtiTest extends CassandraAnalyticsSimpleTest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please read sstables after bulk write and verify files have bti da format in file name? I have a draft of this


    /**
     * Verifies that all SSTable data files across all nodes in the cluster use the BTI format (bti-da).
     * BTI format data files follow the naming pattern: {@code da-<generation>-bti-Data.db}
     */
    private void verifySSTableFormat()
    {
        boolean foundDataFiles = false;
        for (int i = 1; i <= cluster.size(); i++)
        {
            if (cluster.get(i).isShutdown())
            {
                continue;
            }
            Set<String> dataFileNames = findSSTableDataFiles(i);
            for (String fileName : dataFileNames)
            {
                foundDataFiles = true;
                assertThat(fileName)
                    .as("SSTable data file should be in BTI format (bti-da) on node %d: %s", i, fileName)
                    .contains("-bti-");
                // Verify the version component is 'da' for Cassandra 5.0 BTI format
                assertThat(fileName)
                    .as("SSTable data file should have version 'da' for Cassandra 5.0 BTI format on node %d: %s",
                        i, fileName)
                    .matches("da-\\d+-bti-Data\\.db");
            }
        }
        assertThat(foundDataFiles)
            .as("Expected to find SSTable data files on at least one node")
            .isTrue();
    }

    /**
     * Finds all SSTable data files for the test table on the given cluster node.
     *
     * @param nodeIndex the 1-based node index in the cluster
     * @return set of data file names found
     */
    private Set<String> findSSTableDataFiles(int nodeIndex)
    {
        String[] dataDirs = (String[]) cluster.get(nodeIndex)
                                              .config()
                                              .getParams()
                                              .get("data_file_directories");
        String dataDir = dataDirs[0];
        Path keyspacePath = Paths.get(dataDir, TEST_KEYSPACE);

        if (!Files.exists(keyspacePath))
        {
            return Collections.emptySet();
        }

        try (Stream<Path> walkStream = Files.walk(keyspacePath))
        {
            return walkStream
                .filter(Files::isRegularFile)
                .map(path -> path.getFileName().toString())
                .filter(name -> name.endsWith("-Data.db"))
                .collect(Collectors.toSet());
        }
        catch (IOException e)
        {
            throw new RuntimeException("Failed to list SSTable data files on node " + nodeIndex, e);
        }
    }

{
static
{
System.setProperty("cassandra.analytics.bridges.sstable_format", "bti");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we limit the test to C* 5+?

Suggested change
}
}
@Override
protected void beforeClusterProvisioning()
{
assumeThat(SimpleCassandraVersion.create(testVersion.version()).major)
.as("BTI is only supported in Cassandra 5+")
.isGreaterThanOrEqualTo(MIN_VERSION_FOR_BTI);
}

Copy link
Copy Markdown
Member

@lukasz-antoniak lukasz-antoniak Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively:

static
{
    System.setProperty("cassandra.analytics.bridges.sstable_format", "bti");
}

@Override
protected void beforeClusterProvisioning()
{
    assumeThat(CassandraVersion.fromVersion(TestUtils.getDTestClusterVersion().getValue())
                               .orElseThrow()
                               .supportedSstableFormats())
    .as("BTI sstable format is not supported")
    .contains("bti");
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you both. I liked the check on the feature name (bti) better.


@Override
protected void beforeClusterProvisioning()
{
String version = TestUtils.getDTestClusterVersion().getValue();
assumeThat(CassandraVersion.fromVersion(version)
.orElseThrow()
.supportedSSTableFormats())
.as("BTI SSTable format is not supported in %s", version)
.contains("bti");
}

@Override
protected ClusterBuilderConfiguration testClusterConfiguration()
{
ClusterBuilderConfiguration conf = super.testClusterConfiguration();
Map<String, Object> additionalConf = new HashMap<>(conf.additionalInstanceConfig);
additionalConf.put("sstable", Map.of("selected_format", "bti"));
conf.additionalInstanceConfig(additionalConf);
return conf;
}
}
Loading