Skip to content

Commit

Permalink
introduced cassandra-4.1 module, update Cassandra versions
Browse files Browse the repository at this point in the history
  • Loading branch information
smiklosovic committed Dec 14, 2022
1 parent c992567 commit 2478e55
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 16 deletions.
63 changes: 62 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
jobs:
build:
machine:
image: ubuntu-1604:202104-01
image: ubuntu-2004:202104-01

working_directory: ~/cassandra-everywhere-strategy

Expand All @@ -22,6 +22,7 @@ jobs:
- ~/.m2
key: m2-{{ checksum "pom.xml" }}

- run: echo "2" | sudo update-alternatives --config java
- run: ./conf/setup.sh && mvn clean install && (cd test && ./run-tests.sh)

- persist_to_workspace:
Expand All @@ -31,6 +32,7 @@ jobs:
- "cassandra-3.0/target/everywhere-strategy-cassandra*.jar"
- "cassandra-3.11/target/everywhere-strategy-cassandra*.jar"
- "cassandra-4.0/target/everywhere-strategy-cassandra*.jar"
- "cassandra-4.1/target/everywhere-strategy-cassandra*.jar"

build-2-2:
docker:
Expand Down Expand Up @@ -160,6 +162,38 @@ jobs:
- "everywhere-strategy-cassandra-4.0*.deb"
- "everywhere-strategy-cassandra-4.0*.rpm"

build-4-1:
docker:
- image: circleci/openjdk:8-jdk-stretch

working_directory: ~/cassandra-everywhere-strategy

environment:
MAVEN_OPTS: -Xmx3200m

steps:

- checkout

- restore_cache:
keys:
- m2-{{ checksum "pom.xml" }}
- m2-

- run: mvn clean install -DoutputDirectory=/tmp/artifacts

- save_cache:
paths:
- ~/.m2
key: m2-{{ checksum "pom.xml" }}

- persist_to_workspace:
root: /tmp/artifacts
paths:
- "everywhere-strategy-cassandra-4.1*.jar"
- "everywhere-strategy-cassandra-4.1*.deb"
- "everywhere-strategy-cassandra-4.1*.rpm"

publish-github-release-2-2:
docker:
- image: circleci/golang
Expand Down Expand Up @@ -213,6 +247,19 @@ jobs:
go get github.com/tcnksm/ghr
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./artifacts/
publish-github-release-4-1:
docker:
- image: circleci/golang
steps:
- attach_workspace:
at: ./artifacts
- run:
name: "Publish 4.1 Release on GitHub"
command: |
set -xue
go get github.com/tcnksm/ghr
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./artifacts/
workflows:
version: 2
main:
Expand Down Expand Up @@ -245,6 +292,12 @@ workflows:
ignore: /.*/
tags:
only: /^v4.0.\d+-\d+\.\d+\.\d+$/
- build-4-1:
filters:
branches:
ignore: /.*/
tags:
only: /^v4.1.\d+-\d+\.\d+\.\d+$/
- publish-github-release-2-2:
requires:
- build-2-2
Expand Down Expand Up @@ -277,3 +330,11 @@ workflows:
ignore: /.*/
tags:
only: /^v4.0.\d+-\d+\.\d+\.\d+$/
- publish-github-release-4-1:
requires:
- build-4-1
filters:
branches:
ignore: /.*/
tags:
only: /^v4.1.\d+-\d+\.\d+\.\d+$/
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ So we resort to reflection to fix this. Yuck! But, it works…

| Cassandra Version | Status |
| --- | --- |
| 3.11.x | Supported |
| 4.x | Supported |
| 3.0.x | _Supported_ |
| 2.2.x | _Supported_ |
| 2.1.x | _Supported_ |
| 3.11.x | Supported |
| 3.0.x | Supported |
| 2.2.x | Supported |
| 2.1.x | Supported |
| 2.0.x | Supported |

For 2.1.x and 2.0.x versions, you can use version 2.2.x, it is compatible.
Expand All @@ -164,4 +164,4 @@ This project is licensed under the Apache License, version 2.0. See [LICENSE](LI

## Instaclustr Support

Please see our [Open Source Project Status](https://www.instaclustr.com/support/documentation/announcements/instaclustr-open-source-project-status/) page for details on Instaclustr's support status of this project.
Please see our [Open Source Project Status](https://www.instaclustr.com/support/documentation/announcements/instaclustr-open-source-project-status/) page for details on Instaclustr's support status of this project.
2 changes: 1 addition & 1 deletion cassandra-2.2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>2.2.18</version>
<version>2.2.19</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion cassandra-3.0/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>3.0.24</version>
<version>3.0.26</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion cassandra-3.11/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>3.11.8</version>
<version>3.11.14</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
69 changes: 69 additions & 0 deletions cassandra-4.1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.instaclustr</groupId>
<artifactId>everywhere-strategy-parent</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>everywhere-strategy-cassandra-4.1</artifactId>
<version>1.0.0</version>

<name>everywhere-strategy-cassandra-4.1</name>
<description>An EverywhereStrategy implementation for Apache Cassandra 4.1</description>

<dependencies>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>4.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>

<configuration>
<tagNameFormat>v4.1-@{project.version}</tagNameFormat>
</configuration>
</plugin>

<plugin>
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
</plugin>

<plugin>
<groupId>de.dentrassi.maven</groupId>
<artifactId>rpm</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<requires>
<require>
<name>cassandra</name>
<version>4.1</version>
<greaterOrEqual/>
</require>
</requires>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions cassandra-4.1/src/deb/control/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Package: [[name]]
Version: [[version]]
Section: misc
Priority: optional
Architecture: all
Depends: cassandra (>= 4.1)
Maintainer: [[maintainer]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.apache.cassandra.locator;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ImmutableMap;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
The strategy should be DC-aware, but DC-awareness is hardcoded to NTS throughout Cassandra.
(see for example org.apache.cassandra.db.ConsistencyLevel)
Hence why this implementation subclasses NTS.
*/
public class EverywhereStrategy extends NetworkTopologyStrategy {

private static final Logger logger = LoggerFactory.getLogger(EverywhereStrategy.class);

protected final Map<String, ReplicationFactor> datacenters;

public EverywhereStrategy(final String keyspaceName,
final TokenMetadata tokenMetadata,
final IEndpointSnitch snitch,
final Map<String, String> configOptions) throws NoSuchFieldException, IllegalAccessException {
super(keyspaceName, tokenMetadata, snitch, null);

if (configOptions != null && configOptions.size() != 0) {
throw new ConfigurationException("EverywhereStrategy doesn't accept any options.");
}

// yuck. but then again, why is this field private?
// also, sucks that its final *and* and an unmodifiable collection.
// lets fix that...
final Field field = NetworkTopologyStrategy.class.getDeclaredField("datacenters");
field.setAccessible(true);

this.datacenters = new HashMap<>();

field.set(this, this.datacenters);
}

// this gets called whenever the ring topology changes.
// redetermine the RF for each DC.
@Override
public EndpointsForRange calculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata) {
final Set<InetAddressAndPort> endpoints = tokenMetadata.getAllEndpoints();

final Map<String, ReplicationFactor> previousDataCenters = ImmutableMap.copyOf(this.datacenters);

this.datacenters.clear();

for (final InetAddressAndPort endpoint : endpoints) {
if (!tokenMetadata.isMember(endpoint))
continue;

final String datacenter = this.snitch.getDatacenter(endpoint);
this.datacenters.merge(datacenter, ReplicationFactor.fromString("1"), (rf1, rf2) -> ReplicationFactor.fullOnly(rf1.fullReplicas + rf2.fullReplicas));
}

if (!previousDataCenters.equals(this.datacenters)) {
logger.info("Data center replication factors for keyspace '{}' = {}", this.keyspaceName, this.datacenters);
}

return super.calculateNaturalReplicas(searchToken, tokenMetadata);
}

@Override
public Collection<String> recognizedOptions() {
return Collections.emptyList();
}

@Override
public void validateOptions() throws ConfigurationException {
super.validateOptions();
}

@Override
protected void validateExpectedOptions() throws ConfigurationException {
// do nothing, we are not excepting any options and method in super would throw as we have not provided any
}
}
2 changes: 1 addition & 1 deletion cassandra-4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>4.0.0</version>
<version>4.0.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion conf/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
sudo apt-get update
sudo apt-get --allow-downgrades --allow-remove-essential --allow-change-held-packages install libev4 libev-dev

pip3.9 install ccm && wget https://github.com/zegelin/ccm-extensions/archive/refs/heads/master.zip && unzip master.zip && cd ccm-extensions-master && python3.9 setup.py install
pip3.9 install ccm && wget https://github.com/smiklosovic/ccm-extensions/archive/refs/heads/master.zip && unzip master.zip && cd ccm-extensions-master && python3.9 setup.py install
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<module>cassandra-3.0</module>
<module>cassandra-3.11</module>
<module>cassandra-4</module>
<module>cassandra-4.1</module>
</modules>

<name>everywhere-strategy-parent</name>
Expand Down
9 changes: 7 additions & 2 deletions test/compare_dumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ def flush_dump_compare(nodes: Iterable[Node], dump_dir: Path):
dump_dir.mkdir(parents=True,exist_ok=True)
path = (dump_dir / f'{node.ip_addr}-{i}.json')
logger.info(f'Writing {node.ip_addr} dump to {path}')
with path.open('wb') as f:
f.write(result.stdout)
print(result.stdout)
try:
with path.open('w') as f:
f.write(result.stdout)
except:
with path.open('wb') as f:
f.write(result.stdout)

logger.info('Comparing dumps')
compare_sstable_dumps(dump_dir)
Expand Down
7 changes: 4 additions & 3 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# ssltabledump not available on 2.2.x
#python3 ccm-test.py -j ../cassandra-2.2/target/everywhere-strategy-cassandra-2.2-1.0.0.jar 2.2.18
python3 ccm-test.py -j ../cassandra-3.0/target/everywhere-strategy-cassandra-3.0-1.0.0.jar 3.0.24
python3 ccm-test.py -j ../cassandra-3.11/target/everywhere-strategy-cassandra-3.11-1.0.0.jar 3.11.10
python3 ccm-test.py -j ../cassandra-4/target/everywhere-strategy-cassandra-4.0-1.0.0.jar 4.0.0
python3 ccm-test.py -j ../cassandra-3.0/target/everywhere-strategy-cassandra-3.0-1.0.0.jar 3.0.26
python3 ccm-test.py -j ../cassandra-3.11/target/everywhere-strategy-cassandra-3.11-1.0.0.jar 3.11.14
python3 ccm-test.py -j ../cassandra-4/target/everywhere-strategy-cassandra-4.0-1.0.0.jar 4.0.7
python3 ccm-test.py -j ../cassandra-4.1/target/everywhere-strategy-cassandra-4.1-1.0.0.jar 4.1.0

0 comments on commit 2478e55

Please sign in to comment.