Skip to content
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

Native cql changes #606

Merged
merged 85 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
ad94017
Query Executor interface for CQL
kathirsvn Oct 23, 2023
54ee2ec
[Native Protocol] Create and delete collection command changes (#581)
maheshrajamani Oct 24, 2023
02055dd
Cache changes (#582)
kathirsvn Oct 24, 2023
f74b0e8
[Native Protocol]Changes for InsertOperation (#586)
maheshrajamani Oct 24, 2023
40bc367
[Native Protocol] Read and count operation (#589)
maheshrajamani Oct 24, 2023
3a858f5
ReadAndUpdateOperation changes for native driver (#588)
kathirsvn Oct 24, 2023
136fa76
Fix for empty filter
maheshrajamani Oct 24, 2023
67ccba4
Changes for delete command
maheshrajamani Oct 25, 2023
f9836a9
Changes for keyspace commands
maheshrajamani Oct 25, 2023
44a19c7
CQL Session changes
kathirsvn Oct 25, 2023
849e55c
Fix for filter clauses
maheshrajamani Oct 25, 2023
d5bc2a0
Merge branch 'native_cql_changes' of https://github.com/stargate/json…
maheshrajamani Oct 25, 2023
4c49fa8
Logging added
kathirsvn Oct 25, 2023
83694ad
Fixed code for boolean sort
maheshrajamani Oct 25, 2023
82a6c2d
Merge branch 'native_cql_changes' of https://github.com/stargate/json…
maheshrajamani Oct 25, 2023
bea0649
CQL session fix
kathirsvn Oct 25, 2023
2f46109
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Oct 25, 2023
0832de8
CQL session fix
kathirsvn Oct 25, 2023
a1abb8a
Set default value to null so no need to serialize the key
maheshrajamani Oct 25, 2023
d39c199
Merge branch 'native_cql_changes' of https://github.com/stargate/json…
maheshrajamani Oct 25, 2023
94d98f6
CQL session cache key fix
kathirsvn Oct 26, 2023
0575802
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Oct 26, 2023
92e0e85
CQL session cache key fix
kathirsvn Oct 26, 2023
b874e52
IT bug fixes
maheshrajamani Oct 27, 2023
983420c
Avoid creating bridge Values
maheshrajamani Oct 27, 2023
70944a2
Moved cache configurations to quarkus properties
kathirsvn Oct 30, 2023
bdbe639
CqlSessionCache key changes
kathirsvn Oct 30, 2023
d806343
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Oct 30, 2023
e6090b5
CQL session cache eviction listener added
kathirsvn Oct 30, 2023
873193c
getSessionCacheKey method improvement
kathirsvn Oct 30, 2023
a7c8763
CQL session config file based driver changes and metrics changes
kathirsvn Oct 30, 2023
4d0ee75
Fix running it (#601)
maheshrajamani Oct 30, 2023
d640c0a
Changes to use token as cache key for OSS cassandra when present in t…
kathirsvn Oct 30, 2023
d1ab1cd
Metrics changes
kathirsvn Oct 31, 2023
6f44428
Fixed Auth token changes for IT
kathirsvn Oct 31, 2023
90ffc3f
Fixed driver metrics conf
kathirsvn Nov 1, 2023
9dda913
Added histogram metrics
maheshrajamani Nov 1, 2023
873e04f
Removed run on subscription
maheshrajamani Nov 1, 2023
57d465a
Added http request histogram
maheshrajamani Nov 1, 2023
13d83a7
JAVA_OPTIONS change
kathirsvn Nov 1, 2023
77f47af
cql branch, Error mapping, IT fix (#610)
Yuqi-Du Nov 1, 2023
89d8024
JAVA_OPTIONS change reverted
kathirsvn Nov 1, 2023
b87a21f
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Nov 1, 2023
470bf43
Session metrics id generator changes
kathirsvn Nov 2, 2023
898042b
Fixed the unit test for metrics to ignore histogram metrics
maheshrajamani Nov 3, 2023
ad7260e
Merge branch 'native_cql_changes' of https://github.com/stargate/json…
maheshrajamani Nov 3, 2023
54f9c34
Merge changes from `main` to `native_cql_changes` (#615)
tatu-at-datastax Nov 3, 2023
44ad4c5
Merge branch 'main' into native_cql_changes (resolve conflicts)
tatu-at-datastax Nov 3, 2023
6f073d4
restore DeleteOneCommandResolverTest.java
Yuqi-Du Nov 3, 2023
7c66e93
merge main to native_cql_branch (#616)
Yuqi-Du Nov 6, 2023
69f16c3
Fix #617: increase Java driver local connection pool size to 8
tatu-at-datastax Nov 6, 2023
43f4af3
Merge branch 'main' into native_cql_changes
tatu-at-datastax Nov 7, 2023
8fc63fc
Merge branch 'main' into native_cql_changes
tatu-at-datastax Nov 8, 2023
a512a5f
fix pagination (#629)
Yuqi-Du Nov 9, 2023
ac60b87
Merge remote-tracking branch 'origin/main' into native_cql_changes
Yuqi-Du Nov 9, 2023
2e47383
Merge branch 'main' into native_cql_changes
tatu-at-datastax Nov 9, 2023
6600ccd
Added few tests for cql session cache
kathirsvn Nov 10, 2023
a386cd2
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Nov 10, 2023
8170287
Added cache info to the log in the startup
kathirsvn Nov 10, 2023
575f2b1
advanced.session-leak.threshold set to 0 to disable logging warning w…
kathirsvn Nov 10, 2023
ee34e60
Schema cache refactor based on Session.metadata (#594)
Hazel-Datastax Nov 10, 2023
edcc68e
Dead code removal from test
tatu-at-datastax Nov 10, 2023
1a78d1c
Merge remote-tracking branch 'origin/main' into native_cql_changes
Yuqi-Du Nov 10, 2023
ef53c35
Fixed tests
kathirsvn Nov 13, 2023
fe04774
Fix for running IT in containerized mode. Will remove the StargateTes…
maheshrajamani Nov 13, 2023
f5b7215
Merge branch 'main' into native_cql_changes
tatu-at-datastax Nov 13, 2023
b55644e
Merge branch 'main' into native_cql_changes
tatu-at-datastax Nov 13, 2023
d13d3bc
Fix native-cql branch: $in with multiple same values (#638)
Yuqi-Du Nov 14, 2023
c055b33
IT passes. Finally!
Yuqi-Du Nov 14, 2023
32be0e8
fix some unit tests
Yuqi-Du Nov 14, 2023
ac5cd48
Native image fix related to Reflection
kathirsvn Nov 14, 2023
61ae37a
Code refactored
maheshrajamani Nov 14, 2023
3d50b7b
Removed CI to run against push for native_cql_changes branch
maheshrajamani Nov 15, 2023
2c09a54
Fixed executeRead consistency level
kathirsvn Nov 15, 2023
a657ef9
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Nov 15, 2023
c911532
SessionCache ttl session increased to 300.
kathirsvn Nov 15, 2023
63e3a1e
Cleaned up TODO marks and removed secure connect bundle config
kathirsvn Nov 15, 2023
9a6b2ef
Changed debug to trace logs in CQLSessionCache
kathirsvn Nov 15, 2023
bb4b4cd
Merge branch 'main' into native_cql_changes
tatu-at-datastax Nov 15, 2023
0f5b017
Fixed tests
kathirsvn Nov 15, 2023
62d3fbe
Merge branch 'native_cql_changes' of github.com:stargate/jsonapi into…
kathirsvn Nov 15, 2023
10c3669
Added JavaDoc to TenantAwareCqlSessionBuilder
kathirsvn Nov 15, 2023
a0ca6e0
Changes to avoid consistency level conversions
kathirsvn Nov 15, 2023
aa24af8
bridge package moved to cqldriver
kathirsvn Nov 15, 2023
e6d238d
Formatting fix
kathirsvn Nov 15, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Continuous Integration
# * manual trigger
on:
push:
branches: [ "main" ]
branches: [ "main"]

pull_request:
branches: [ "main" ]
Expand Down
25 changes: 20 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>${driver.version}</version>
<exclusions>
<exclusion>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-metrics-micrometer</artifactId>
<version>${driver.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand All @@ -103,11 +123,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.stargate</groupId>
<artifactId>sgv2-quarkus-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.benmanes.caffeine.cache;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection(targets = {com.github.benmanes.caffeine.cache.PSAMS.class})
public class ReflectionRegistration {
// This class is used only for annotation processing during build
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import io.stargate.sgv2.jsonapi.api.model.command.clause.sort.SortClause;
import io.stargate.sgv2.jsonapi.api.model.command.clause.update.UpdateClause;
import io.stargate.sgv2.jsonapi.service.bridge.executor.CollectionSettings;
import io.stargate.sgv2.jsonapi.service.cqldriver.executor.CollectionSettings;
import io.stargate.sgv2.jsonapi.service.embedding.DataVectorizer;
import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingService;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.stargate.sgv2.jsonapi.config.constants.OpenApiConstants;
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
import io.stargate.sgv2.jsonapi.exception.mappers.ThrowableCommandResultSupplier;
import io.stargate.sgv2.jsonapi.service.bridge.executor.SchemaCache;
import io.stargate.sgv2.jsonapi.service.cqldriver.executor.SchemaCache;
import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingService;
import io.stargate.sgv2.jsonapi.service.embedding.operation.EmbeddingServiceCache;
import io.stargate.sgv2.jsonapi.service.processor.MeteredCommandProcessor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.stargate.sgv2.jsonapi.config;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
import org.eclipse.microprofile.config.spi.Converter;

/**
* Converts a string to a {@link ConsistencyLevel}, used in {@link OperationsConfig.QueriesConfig}.
*/
public class ConsistencyLevelConverter implements Converter<ConsistencyLevel> {
/**
* @param value the string representation of a property value
* @return the converted ConsistencyLevel
*/
@Override
public ConsistencyLevel convert(String value)
throws IllegalArgumentException, NullPointerException {
return DefaultConsistencyLevel.valueOf(value.toUpperCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@

package io.stargate.sgv2.jsonapi.config;

import static io.stargate.sgv2.jsonapi.service.cqldriver.CQLSessionCache.CASSANDRA;

import com.datastax.oss.driver.api.core.ConsistencyLevel;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithConverter;
import io.smallrye.config.WithDefault;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import java.util.List;
import javax.annotation.Nullable;

/** Configuration for the operation execution. */
@ConfigMapping(prefix = "stargate.jsonapi.operations")
Expand Down Expand Up @@ -109,4 +115,93 @@ interface LwtConfig {
@WithDefault("3")
int retries();
}

/** Cassandra/AstraDB related configurations. */
@NotNull
@Valid
DatabaseConfig databaseConfig();

interface DatabaseConfig {

/** Database type can be <code>cassandra</code> or <code>astra</code>. */
@WithDefault(CASSANDRA)
String type();

/** Username when connecting to cassandra database (when type is <code>cassandra</code>) */
@Nullable
@WithDefault("cassandra")
String userName();

/** Password when connecting to cassandra database (when type is <code>cassandra</code>) */
@Nullable
@WithDefault("cassandra")
String password();

/** Fixed Token used for Integration Test authentication */
@Nullable
@WithDefault("not in tests")
String fixedToken();

/** Cassandra contact points (when type is <code>cassandra</code>) */
@Nullable
@WithDefault("127.0.0.1")
List<String> cassandraEndPoints();

/** Cassandra contact points (when type is <code>cassandra</code>) */
@Nullable
@WithDefault("9042")
int cassandraPort();

/** Local datacenter that the driver must be configured with */
@NotNull
@WithDefault("datacenter1")
String localDatacenter();

/** Time to live for CQLSession in cache in seconds. */
@WithDefault("300")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure we really want 5 minutes over 1 -- this is not time-to-live for connection (AFAIK) but time unused connection remains for reuse after last call. That is, idle wait.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When session is evicted from cache, the session will be closed. Changed to 300 as per yesterday's conversation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also these values can be override using environment value in the chart.

long sessionCacheTtlSeconds();

/** Maximum number of CQLSessions in cache. */
@WithDefault("100")
long sessionCacheMaxSize();
}

/** Query consistency related configs. */
@NotNull
@Valid
QueriesConfig queriesConfig();

interface QueriesConfig {

/** @return Settings for the consistency level. */
@Valid
ConsistencyConfig consistency();

/** @return Serial Consistency for queries. */
@WithDefault("SERIAL")
@WithConverter(ConsistencyLevelConverter.class)
ConsistencyLevel serialConsistency();

/** @return Settings for the consistency level. */
interface ConsistencyConfig {

/** @return Consistency for queries making schema changes. */
@WithDefault("LOCAL_QUORUM")
@NotNull
@WithConverter(ConsistencyLevelConverter.class)
ConsistencyLevel schemaChanges();

/** @return Consistency for queries writing the data. */
@WithDefault("LOCAL_QUORUM")
@NotNull
@WithConverter(ConsistencyLevelConverter.class)
ConsistencyLevel writes();

/** @return Consistency for queries reading the data. */
@WithDefault("LOCAL_QUORUM")
@NotNull
@WithConverter(ConsistencyLevelConverter.class)
ConsistencyLevel reads();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,15 @@ public CommandResult get() {
public CommandResult.Error getCommandResultError(String message) {
Map<String, Object> fieldsForMetricsTag =
Map.of("errorCode", errorCode.name(), "exceptionClass", this.getClass().getSimpleName());
Map<String, Object> fields = null;
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
// enable debug mode for unit tests, since it can not be injected
DebugModeConfig debugModeConfig = config.getConfigMapping(DebugModeConfig.class);
final boolean debugEnabled = debugModeConfig.enabled();
if (debugEnabled) {
fields =
Map.of("errorCode", errorCode.name(), "exceptionClass", this.getClass().getSimpleName());
} else {
fields = Map.of("errorCode", errorCode.name());
}
final Map<String, Object> fields =
debugEnabled
? Map.of(
"errorCode", errorCode.name(), "exceptionClass", this.getClass().getSimpleName())
: Map.of("errorCode", errorCode.name());
return new CommandResult.Error(message, fieldsForMetricsTag, fields, Response.Status.OK);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package io.stargate.sgv2.jsonapi.exception.mappers;

import com.datastax.oss.driver.api.core.AllNodesFailedException;
import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.driver.api.core.DriverTimeoutException;
import com.datastax.oss.driver.api.core.NoNodeAvailableException;
import com.datastax.oss.driver.api.core.NodeUnavailableException;
import com.datastax.oss.driver.api.core.servererrors.QueryValidationException;
import com.datastax.oss.driver.api.core.servererrors.WriteTimeoutException;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.quarkus.security.UnauthorizedException;
import io.smallrye.config.SmallRyeConfig;
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
import io.stargate.sgv2.jsonapi.config.DebugModeConfig;
Expand All @@ -17,7 +25,6 @@
* implementation.
*/
public final class ThrowableToErrorMapper {

private static final BiFunction<Throwable, String, CommandResult.Error> MAPPER_WITH_MESSAGE =
(throwable, message) -> {
// if our own exception, shortcut
Expand All @@ -28,14 +35,17 @@ public final class ThrowableToErrorMapper {
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
DebugModeConfig debugModeConfig = config.getConfigMapping(DebugModeConfig.class);
final boolean debugEnabled = debugModeConfig.enabled();
final Map<String, Object> fields =
debugEnabled ? Map.of("exceptionClass", throwable.getClass().getSimpleName()) : null;
final Map<String, Object> fieldsForMetricsTag =
Map.of("exceptionClass", throwable.getClass().getSimpleName());
if (throwable instanceof StatusRuntimeException sre) {
Map<String, Object> fields =
debugEnabled ? Map.of("exceptionClass", throwable.getClass().getSimpleName()) : null;
Map<String, Object> fieldsForMetricsTag =
Map.of("exceptionClass", throwable.getClass().getSimpleName());
if (sre.getStatus().getCode() == Status.Code.UNAUTHENTICATED) {
return new CommandResult.Error(
message, fieldsForMetricsTag, fields, Response.Status.UNAUTHORIZED);
"UNAUTHENTICATED: Invalid token",
fieldsForMetricsTag,
fields,
Response.Status.UNAUTHORIZED);
} else if (sre.getStatus().getCode() == Status.Code.INTERNAL) {
return new CommandResult.Error(
message, fieldsForMetricsTag, fields, Response.Status.INTERNAL_SERVER_ERROR);
Expand All @@ -47,11 +57,30 @@ public final class ThrowableToErrorMapper {
message, fieldsForMetricsTag, fields, Response.Status.GATEWAY_TIMEOUT);
}
}
// add error code as error field
Map<String, Object> fields =
debugEnabled ? Map.of("exceptionClass", throwable.getClass().getSimpleName()) : null;
Map<String, Object> fieldsForMetricsTag =
Map.of("exceptionClass", throwable.getClass().getSimpleName());
if (throwable instanceof UnauthorizedException
|| throwable
instanceof com.datastax.oss.driver.api.core.servererrors.UnauthorizedException) {
return new CommandResult.Error(
"UNAUTHENTICATED: Invalid token",
fieldsForMetricsTag,
fields,
Response.Status.UNAUTHORIZED);
} else if (throwable instanceof QueryValidationException) {
if (message.contains("vector<float,")) { // TODO is there a better way?
jeffreyscarpenter marked this conversation as resolved.
Show resolved Hide resolved
message = "Mismatched vector dimension";
}
return new CommandResult.Error(message, fieldsForMetricsTag, fields, Response.Status.OK);
} else if (throwable instanceof NodeUnavailableException
|| throwable instanceof DriverException
|| throwable instanceof AllNodesFailedException
|| throwable instanceof NoNodeAvailableException) {
return new CommandResult.Error(
message, fieldsForMetricsTag, fields, Response.Status.INTERNAL_SERVER_ERROR);
} else if (throwable instanceof DriverTimeoutException
|| throwable instanceof WriteTimeoutException) {
return new CommandResult.Error(
message, fieldsForMetricsTag, fields, Response.Status.GATEWAY_TIMEOUT);
}
return new CommandResult.Error(message, fieldsForMetricsTag, fields, Response.Status.OK);
};

Expand All @@ -61,7 +90,6 @@ public final class ThrowableToErrorMapper {
if (message == null) {
message = "Unexpected exception occurred.";
}

return MAPPER_WITH_MESSAGE.apply(throwable, message);
};

Expand Down
Loading