crdb draft

This commit is contained in:
Madhavan Sridharan 2022-12-21 13:59:28 -05:00
parent 9f3cae5915
commit 0f4263f46c
7 changed files with 223 additions and 0 deletions

View File

@ -0,0 +1,62 @@
<!--
~ Copyright (c) 2022 nosqlbench
~
~ 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.
-->
<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>io.nosqlbench</groupId>
<artifactId>mvn-defaults</artifactId>
<version>4.17.32-SNAPSHOT</version>
<relativePath>../mvn-defaults</relativePath>
</parent>
<artifactId>adapter-cockroachdb</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
A DriverAdapter driver for CockroachDB
</description>
<dependencies>
<!-- core dependencies -->
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>adapters-api</artifactId>
<version>4.17.32-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.postgresql</groupId>-->
<!-- <artifactId>postgresql</artifactId>-->
<!-- <version>42.3.3</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 nosqlbench
*
* 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 io.nosqlbench.adapter.cockroachdb;
/**
* Op templates which are supported by the NoSQLBench CockroachDB driver are
* enumerated below. These command names should mirror those in the official
* CockroachDB API exactly.
*/
public class CockroachDBCmdType {
}

View File

@ -0,0 +1,121 @@
/*
* Copyright (c) 2023 nosqlbench
*
* 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 io.nosqlbench.adapter.cockroachdb;
import io.nosqlbench.api.config.standard.NBConfiguration;
import io.nosqlbench.api.errors.OpConfigError;
import org.postgresql.ds.PGSimpleDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Optional;
public class CockroachDBSpace {
private final String name;
private final DataSource ds = null;
// private final HikariConfig hikariConfig = null;
// private final HikariDataSource hikariDataSource = null;
private Connection connection;
public CockroachDBSpace(String name, NBConfiguration cfg) {
this.name = name;
PGSimpleDataSource client = createClient(cfg);
// dynamoDB= new DynamoDB(client);
}
private PGSimpleDataSource createClient(NBConfiguration cfg) {
PGSimpleDataSource ds = new PGSimpleDataSource();
Optional<String> url = cfg.getOptional("url");
if(url.isEmpty()) {
throw new OpConfigError("url option is required.");
} else {
ds.setURL(url.get());
}
Optional<String> serverNames = cfg.getOptional("serverName");
if(serverNames.isPresent()) {
ds.setServerNames(new String[]{serverNames.get()});
} else {
throw new OpConfigError("Server name option is required.");
}
Optional<String> databaseName = cfg.getOptional("databaseName");
if(databaseName.isPresent()) {
ds.setDatabaseName(databaseName.get());
} else {
throw new OpConfigError("Database name option is required.");
}
Optional<Integer> portNumber = cfg.getOptional(Integer.class, "portNumber");
ds.setPortNumbers(new int[] { portNumber.orElse(26257) });
Optional<String> user = cfg.getOptional("user");
if(user.isPresent()) {
ds.setUser(user.get());
}
Optional<String> password = cfg.getOptional("password");
if(password.isPresent()) {
if(user.isEmpty()) {
throw new OpConfigError("Both user and password options are required. Only password is supplied in this case.");
}
ds.setPassword(password.get());
} else {
if(user.isPresent()) {
throw new OpConfigError("Both user and password options are required. Only user is supplied in this case.");
}
}
Optional<String> sslMode = cfg.getOptional("sslMode");
if(sslMode.isPresent()) {
ds.setSslMode(sslMode.get());
} else {
ds.setSslMode("verify-full");
}
Optional<String> applicationName = cfg.getOptional("applicationName");
if(applicationName.isPresent()) {
ds.setApplicationName(applicationName.get());
} else {
ds.setApplicationName("NoSQLBench");
}
Optional<Boolean> rewriteBatchedInserts = cfg.getOptional(Boolean.class, "rewriteBatchedInserts");
ds.setReWriteBatchedInserts(rewriteBatchedInserts.orElse(false));
return ds;
}
public static NBConfigModel getConfigModel() {
return ConfigModel.of(CockroachDBSpace.class)
.add(Param.optional("url"))
.add(Param.optional("serverName"))
.add(Param.optional("databaseName"))
//TODO remove these below
.add(Param.optional("client_socket_timeout"))
.add(Param.optional("client_execution_timeout"))
.add(Param.optional("client_max_connections"))
.add(Param.optional("client_max_error_retry"))
.add(Param.optional("client_user_agent_prefix"))
.add(Param.optional("client_consecutive_retries_before_throttling"))
.add(Param.optional("client_gzip"))
.add(Param.optional("client_tcp_keepalive"))
.add(Param.optional("client_disable_socket_proxy"))
.add(Param.optional("client_so_send_size_hint"))
.add(Param.optional("client_so_recv_size_hint"))
.asReadOnly();
}
}

View File

@ -0,0 +1 @@
# cockroachdb driver

View File

@ -61,6 +61,12 @@
<version>4.17.22-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>adapter-cockroachdb</artifactId>
<version>4.17.22-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>adapter-cqld4</artifactId>

View File

@ -106,6 +106,12 @@
<version>4.17.32-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>adapter-cockroachdb</artifactId>
<version>4.17.32-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

View File

@ -64,6 +64,7 @@
<module>adapter-pulsar</module>
<module>adapter-s4j</module>
<module>adapter-kafka</module>
<module>adapter-cockroachdb</module>
<!-- VIRTDATA MODULES -->