Skip to content
Permalink
Browse files
initial commit
Co-authored-by: Bhaskar Muppana <mbhaskar@apple.com>
Co-authored-by: Jeff Jirsa <jjirsa@apple.com>
Co-authored-by: Marcus Eriksson <marcuse@apache.org>
Co-authored-by: Michael Kjellman <kjellman@apple.com>
Co-authored-by: Nate McCall <zznate.m@gmail.com>
Co-authored-by: Sam Tunnicliffe <sam@beobal.com>
  • Loading branch information
6 people committed Aug 22, 2019
0 parents commit c95404e6de080d33af0c7ea3a7d9a1aed13e0383
Showing 42 changed files with 6,442 additions and 0 deletions.
@@ -0,0 +1,86 @@
# Cassandra diff

## Configuration
See `spark-job/localconfig.yaml` for an example config.

## Custom cluster providers
To make it easy to run in any environment the cluster providers are pluggable - there are two interfaces to implement.
First, the `ClusterProvider` interface is used to create a connection to the clusters, and it is configured using
`JobConfiguration#clusterConfig` (see below).
### cluster_config
This section has 3 parts - `source`, `target` and `metadata` where source and target describes the clusters that should
be compared and metadata describes where we store information about any mismatches and the progress the job has done.
Metadata can be stored in one of the source/target clusters or in a separate cluster.

The fields under source/target/metadata are passed in to the `ClusterProvider` (described by `impl`) as a map, so any
custom cluster providers can be configured here.

## Setting up clusters for diff
One way of setting up clusters for diff is to restore a snapshot to two different clusters and then modifying one
of the clusters to be able to make sure that the queries still return the same results. This could include
upgrades/replacements/bounces/decommission/expansion.

## Environment variables
Currently usernames and passwords are set as environment variables when running the diff tool and the api server:

* `diff.cluster.<identifier>.cql_user` - the user name to use
* `diff.cluster.<identifier>.cql_password` - password

where `<identifier>` should be `source`, `target` and `metadata` for the username/password combinations for the
matching clusters in the configuration.

## Example
This example starts two cassandra single-node clusters in docker, runs stress to populate them and then runs diff
to make sure the data matches;

You need to have docker and spark setup.

```shell script
$ git clone <wherever>/cassandra-diff.git
$ cd cassandra-diff
$ mvn package
$ docker run --name cas-src -d -p 9042:9042 cassandra:3.0.18
$ docker run --name cas-tgt -d -p 9043:9042 cassandra:latest
$ docker exec cas-src cassandra-stress write n=1k
$ docker exec cas-tgt cassandra-stress write n=1k
$ spark-submit --verbose --files ./spark-job/localconfig.yaml --class org.apache.cassandra.diff.DiffJob spark-job/target/spark-job-0.1-SNAPSHOT.jar localconfig.yaml
# ... logs
INFO DiffJob:124 - FINISHED: {standard1=Matched Partitions - 1000, Mismatched Partitions - 0, Partition Errors - 0, Partitions Only In Source - 0, Partitions Only In Target - 0, Skipped Partitions - 0, Matched Rows - 1000, Matched Values - 6000, Mismatched Values - 0 }
## start api-server:
$ mvn install
$ cd api-server
$ mvn exec:java
$ curl -s localhost:8089/jobs/recent | python -mjson.tool
[
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"buckets": 100,
"keyspace": "keyspace1",
"tables": [
"standard1"
],
"sourceClusterName": "local_test_1",
"sourceClusterDesc": "ContactPoints Cluster: name=name, dc=datacenter1, contact points= [127.0.0.1]",
"targetClusterName": "local_test_2",
"targetClusterDesc": "ContactPoints Cluster: name=name, dc=datacenter1, contact points= [127.0.0.1]",
"tasks": 10000,
"start": "2019-08-16T11:47:36.123Z"
}
]
$ curl -s localhost:8089/jobs/99b8d556-07ed-4bfd-b978-7d9b7b2cc21a/results | python -mjson.tool
[
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"table": "standard1",
"matchedPartitions": 1000,
"mismatchedPartitions": 0,
"matchedRows": 1000,
"matchedValues": 6000,
"mismatchedValues": 0,
"onlyInSource": 0,
"onlyInTarget": 0,
"skippedPartitions": 0
}
]
```
@@ -0,0 +1,117 @@
# Diff API Server
## Configuration
See main project README - the api server reads the `metadata_options` and `cluster_config.metadata` to connect

## Running locally
`mvn exec:java`

## Endpoints
### `/jobs/running/id`
Returns the ids of currently running jobs

### `/jobs/running`
Summaries of all currently running jobs

### `/jobs/recent`
Summaries of recently run jobs
Example:
```shell script
$ curl -s localhost:8089/jobs/recent | python -mjson.tool
[
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"buckets": 100,
"keyspace": "keyspace1",
"tables": [
"standard1"
],
"sourceClusterName": "local_test_1",
"sourceClusterDesc": "ContactPoints Cluster: name=name, dc=datacenter1, contact points= [127.0.0.1]",
"targetClusterName": "local_test_2",
"targetClusterDesc": "ContactPoints Cluster: name=name, dc=datacenter1, contact points= [127.0.0.1]",
"tasks": 10000,
"start": "2019-08-16T11:47:36.123Z"
}
]
```

### `/jobs/{jobid}`
Summary about a single job
Example:
```shell script
$ curl -s localhost:8089/jobs/99b8d556-07ed-4bfd-b978-7d9b7b2cc21a | python -mjson.tool
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"buckets": 100,
"keyspace": "keyspace1",
"tables": [
"standard1"
],
"sourceClusterName": "local_test_1",
"sourceClusterDesc": "ContactPoints Cluster: name=name, dc=datacenter1, contact points= [127.0.0.1]",
"targetClusterName": "local_test_2",
"targetClusterDesc": "ContactPoints Cluster: name=name, dc=datacenter1, contact points= [127.0.0.1]",
"tasks": 10000,
"start": "2019-08-16T11:47:36.123Z"
}
```

### `/jobs/{jobid}/results`
The results for the given job.
Example:
```shell script
$ curl -s localhost:8089/jobs/99b8d556-07ed-4bfd-b978-7d9b7b2cc21a/results | python -mjson.tool
[
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"table": "standard1",
"matchedPartitions": 1000,
"mismatchedPartitions": 0,
"matchedRows": 1000,
"matchedValues": 6000,
"mismatchedValues": 0,
"onlyInSource": 0,
"onlyInTarget": 0,
"skippedPartitions": 0
}
]
```

### `/jobs/{jobid}/status`
Current status for a job, shows how many splits have been finished.
Example:
```shell script
$ curl -s localhost:8089/jobs/99b8d556-07ed-4bfd-b978-7d9b7b2cc21a/status | python -mjson.tool
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"completedByTable": {
"standard1": 10000
}
}
```

### `/jobs/{jobid}/mismatches`
Number of mismatches for the job.
```shell script
$ curl -s localhost:8089/jobs/99b8d556-07ed-4bfd-b978-7d9b7b2cc21a/mismatches | python -mjson.tool
{
"jobId": "99b8d556-07ed-4bfd-b978-7d9b7b2cc21a",
"mismatchesByTable": {}
}
```

### `/jobs/{jobid}/errors/summary`
Summary of the number errors for the job.

### `/jobs/{jobid}/errors/ranges`
Lists failed ranges for the job.

### `/jobs/{jobid}/errors`
Details about the job errors.

### `/jobs/by-start-date/{started-after}`
### `/jobs/by-start-date/{started-after}/{started-before}`
### `/jobs/by-source-cluster/{source}`
### `/jobs/by-target-cluster/{target}`
### `/jobs/by-keyspace/{keyspace}`
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<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">
<parent>
<groupId>org.apache.cassandra.diff</groupId>
<artifactId>diff</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>api-server</artifactId>
<packaging>jar</packaging>

<dependencies>

<!-- compile dependencies -->
<dependency>
<groupId>org.apache.cassandra.diff</groupId>
<artifactId>common</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.7</version>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.1.7</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9.2</version>
</dependency>

<!-- provided dependencies -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>

<!-- runtime dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.4.1</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.apache.cassandra.diff.api.DiffAPIServer</mainClass>
<arguments>
<argument>
../spark-job/localconfig.yaml
</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,57 @@
/*
* 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.diff.api;

import java.io.IOException;

import com.google.common.collect.Lists;

import org.apache.cassandra.diff.YamlJobConfiguration;
import org.apache.cassandra.diff.api.resources.DiffJobsResource;
import org.apache.cassandra.diff.api.resources.HealthResource;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;

public class DiffAPIServer {
public static void main(String[] args) throws IOException {
String filename = args[0];
JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();

DiffJobsResource diffResource = new DiffJobsResource(YamlJobConfiguration.load(filename));
factoryBean.setResourceProviders(Lists.newArrayList(new SingletonResourceProvider(diffResource),
new SingletonResourceProvider(new HealthResource())));
factoryBean.setAddress("http://localhost:8089/");
Server server = factoryBean.create();

try {
server.start();
System.in.read();
} catch (Throwable t) {
t.printStackTrace(System.out);
throw t;
} finally {
diffResource.close();
if (server.isStarted())
server.stop();
System.exit(0);
}
}
}

0 comments on commit c95404e

Please sign in to comment.