-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Cassandra Storage in v3 #3570
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f6c2a53
Support Cassandra Storage in v3
mrproliu ba35439
Merge branch 'zipkin-v3' into cassandra
mrproliu 48fe57e
Remote SelfSenderService
mrproliu 04b045d
Merge remote-tracking branch 'upstream/zipkin-v3' into cassandra
mrproliu 2ce3654
update configuration for test
mrproliu a797e32
Adding exception in the emptyDAO
mrproliu e4b59c9
Merge branch 'zipkin-v3' into cassandra
mrproliu 6da0976
Fix issues
mrproliu 0b5455f
fix test
mrproliu a04c190
Merge branch 'zipkin-v3' into cassandra
mrproliu 137ab8d
Add dependency module related table create and query
mrproliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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> | ||
<artifactId>zipkin-server-parent</artifactId> | ||
<groupId>io.zipkin</groupId> | ||
<version>2.24.4-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>storage-cassandra</artifactId> | ||
<name>Storage: Cassandra</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.zipkin</groupId> | ||
<artifactId>zipkin-server-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>storage-jdbc-hikaricp-plugin</artifactId> | ||
<version>${skywalking.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.zipkin</groupId> | ||
<artifactId>zipkin-server-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.auto.value</groupId> | ||
<artifactId>auto-value-annotations</artifactId> | ||
<version>${auto-value.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.auto.value</groupId> | ||
<artifactId>auto-value</artifactId> | ||
<version>${auto-value.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.datastax.oss</groupId> | ||
<artifactId>java-driver-core</artifactId> | ||
<version>${java-driver.version}</version> | ||
<!-- Exclude unused graph and geo dependencies --> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.esri.geometry</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.apache.tinkerpop</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
<!-- We retain reactivestreams even though we don't use it because | ||
Mockito dies trying to mock CqlSession without it. --> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.skywalking</groupId> | ||
<artifactId>cluster-standalone-plugin</artifactId> | ||
<version>${skywalking.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
76 changes: 76 additions & 0 deletions
76
...n-server/storage-cassandra/src/main/java/zipkin/server/storage/cassandra/CQLExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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 zipkin.server.storage.cassandra; | ||
|
||
import org.apache.skywalking.oap.server.core.storage.SessionCacheCallback; | ||
import org.apache.skywalking.oap.server.library.client.request.InsertRequest; | ||
import org.apache.skywalking.oap.server.library.client.request.UpdateRequest; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CQLExecutor implements InsertRequest, UpdateRequest { | ||
private final String cql; | ||
private final List<Object> params; | ||
private final SessionCacheCallback callback; | ||
private List<CQLExecutor> additionalCQLs; | ||
|
||
public CQLExecutor(String cql, List<Object> params, SessionCacheCallback callback, List<CQLExecutor> additionalCQLs) { | ||
this.cql = cql; | ||
this.params = params; | ||
this.callback = callback; | ||
this.additionalCQLs = additionalCQLs; | ||
} | ||
|
||
public void appendAdditionalCQLs(List<CQLExecutor> cqlExecutors) { | ||
if (additionalCQLs == null) { | ||
additionalCQLs = new ArrayList<>(); | ||
} | ||
additionalCQLs.addAll(cqlExecutors); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return cql; | ||
} | ||
|
||
@Override | ||
public void onInsertCompleted() { | ||
if (callback != null) | ||
callback.onInsertCompleted(); | ||
} | ||
|
||
@Override | ||
public void onUpdateFailure() { | ||
if (callback != null) | ||
callback.onUpdateFailure(); | ||
} | ||
|
||
public List<CQLExecutor> getAdditionalCQLs() { | ||
return additionalCQLs; | ||
} | ||
|
||
public String getCql() { | ||
return cql; | ||
} | ||
|
||
public List<Object> getParams() { | ||
return params; | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
...rver/storage-cassandra/src/main/java/zipkin/server/storage/cassandra/CassandraClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* Copyright 2015-2023 The OpenZipkin Authors | ||
* | ||
* Licensed 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 zipkin.server.storage.cassandra; | ||
|
||
import com.datastax.oss.driver.api.core.CqlSession; | ||
import com.datastax.oss.driver.api.core.auth.AuthProvider; | ||
import com.datastax.oss.driver.api.core.config.DriverOption; | ||
import com.datastax.oss.driver.api.core.cql.AsyncResultSet; | ||
import com.datastax.oss.driver.api.core.cql.BoundStatement; | ||
import com.datastax.oss.driver.api.core.cql.ResultSet; | ||
import com.datastax.oss.driver.api.core.cql.Row; | ||
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; | ||
import com.datastax.oss.driver.internal.core.auth.ProgrammaticPlainTextAuthProvider; | ||
import org.apache.skywalking.oap.server.library.client.Client; | ||
import org.apache.skywalking.oap.server.library.client.healthcheck.DelegatedHealthChecker; | ||
import org.apache.skywalking.oap.server.library.util.HealthChecker; | ||
import org.apache.skywalking.oap.server.library.util.StringUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import zipkin.server.storage.cassandra.internal.SessionBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_MAX_REQUESTS; | ||
import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE; | ||
|
||
public class CassandraClient implements Client { | ||
static final Logger LOG = LoggerFactory.getLogger(CassandraClient.class); | ||
|
||
public static final String RECORD_UNIQUE_UUID_COLUMN = "uuid_unique"; | ||
|
||
private final CassandraConfig config; | ||
private final DelegatedHealthChecker healthChecker; | ||
|
||
private volatile CqlSession cqlSession; | ||
|
||
public CassandraClient(CassandraConfig config) { | ||
this.config = config; | ||
this.healthChecker = new DelegatedHealthChecker(); | ||
} | ||
|
||
public KeyspaceMetadata getMetadata() { | ||
return cqlSession.getMetadata().getKeyspace(config.getKeyspace()).orElse(null); | ||
} | ||
|
||
public CqlSession getSession() { | ||
return cqlSession; | ||
} | ||
|
||
public <T> List<T> executeQuery(String cql, ResultHandler<T> resultHandler, Object... params) { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Executing CQL: {}", cql); | ||
LOG.debug("CQL parameters: {}", Arrays.toString(params)); | ||
} | ||
final BoundStatement stmt = cqlSession.prepare(cql).bind(params); | ||
final ResultSet resultSet = cqlSession.execute(stmt); | ||
healthChecker.health(); | ||
if (resultHandler != null) { | ||
return StreamSupport.stream(resultSet.spliterator(), false) | ||
.map(resultHandler::handle).collect(Collectors.toList()); | ||
} | ||
return null; | ||
} | ||
|
||
public <T> CompletionStage<List<T>> executeAsyncQuery(String cql, ResultHandler<T> resultHandler, Object... params) { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Executing CQL: {}", cql); | ||
LOG.debug("CQL parameters: {}", Arrays.toString(params)); | ||
} | ||
final BoundStatement stmt = cqlSession.prepare(cql).bind(params); | ||
final CompletionStage<AsyncResultSet> resultSet = cqlSession.executeAsync(stmt); | ||
healthChecker.health(); | ||
if (resultHandler != null) { | ||
return resultSet.thenApply(s -> StreamSupport.stream(s.currentPage().spliterator(), false) | ||
.map(resultHandler::handle).collect(Collectors.toList())); | ||
} | ||
return null; | ||
} | ||
|
||
public void execute(String cql) { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Executing CQL: {}", cql); | ||
} | ||
cqlSession.execute(cql); | ||
healthChecker.health(); | ||
} | ||
|
||
public void registerChecker(HealthChecker healthChecker) { | ||
this.healthChecker.register(healthChecker); | ||
} | ||
|
||
@Override | ||
public void connect() throws Exception { | ||
AuthProvider authProvider = null; | ||
if (StringUtil.isNotEmpty(config.getUsername())) { | ||
authProvider = new ProgrammaticPlainTextAuthProvider(config.getUsername(), config.getPassword()); | ||
} | ||
this.cqlSession = SessionBuilder.buildSession(config.getContactPoints(), | ||
config.getLocalDc(), | ||
poolingOptions(), | ||
authProvider, | ||
config.getUseSsl()); | ||
|
||
// create keyspace if needs | ||
final String keyspace = config.getKeyspace(); | ||
KeyspaceMetadata keyspaceMetadata = this.cqlSession.getMetadata().getKeyspace(keyspace).orElse(null); | ||
if (keyspaceMetadata == null) { | ||
String createKeyspaceCql = String.format( | ||
"CREATE KEYSPACE IF NOT EXISTS %s " + | ||
"WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} " + | ||
"AND durable_writes = false;", | ||
keyspace); | ||
this.cqlSession.execute(createKeyspaceCql); | ||
} | ||
|
||
this.cqlSession.execute("USE " + keyspace); | ||
} | ||
|
||
@Override | ||
public void shutdown() throws IOException { | ||
} | ||
|
||
private Map<DriverOption, Integer> poolingOptions() { | ||
Map<DriverOption, Integer> result = new LinkedHashMap<>(); | ||
result.put(CONNECTION_POOL_LOCAL_SIZE, config.getMaxConnections()); | ||
result.put(CONNECTION_MAX_REQUESTS, 40960 / config.getMaxConnections()); | ||
return result; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ResultHandler<T> { | ||
T handle(Row resultSet); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neither SimpleStrategy nor rf=1 is appropriate for any production system. NetworkTopologyStrategy and rf=3 is the minimum for production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the default settings in the Zipkin CQL file, should I updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are appropriate for first-time / dev usage. but not appropriate for production usage.
it needs to be configurable.
and ideally the application should log a warning when rf<3 saying it's not appropriate for production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if rf<3 would be got a warning log. What do you mean configurable?