Fix create database command

This commit is contained in:
Madhavan Sridharan 2024-10-03 20:55:49 -04:00 committed by Madhavan
parent a428b5d14b
commit abbb989b1d
4 changed files with 29 additions and 13 deletions

View File

@ -7,11 +7,11 @@
</extension>
<option name="JAR_PATH" value="$PROJECT_DIR$/nb5/target/nb5.jar" />
<option name="VM_PARAMETERS" value="--enable-preview" />
<option name="PROGRAM_PARAMETERS" value="create_database_ddl default.create_db_ddl project_id=stratperf instance_id=perftest-spanner database_id=baselines1 service_account_file=./stratperf-068083077315.json --progress console:1s -vv --add-labels=&quot;target:spanner,instance:vectors,vendor:gcp&quot; --report-prompush-to https://vector-perf.feat.apps.paas.datastax.com:8427/api/v1/import/prometheus/metrics/job/nosqlbench/instance/vectors --annotators &quot;[{'type':'log','level':'info'},{'type':'grafana','baseurl':'https://vector-perf.feat.apps.paas.datastax.com/'}]&quot; --report-interval 10 --show-stacktraces --logs-max 5" />
<option name="PROGRAM_PARAMETERS" value="create_database_ddl default.create_db_ddl project_id=stratperf instance_id=perftest-spanner database_id=baselines1 service_account_file=./stratperf-068083077315.json --progress console:1s -v --add-labels=&quot;target:spanner,instance:vectors,vendor:gcp&quot; --report-prompush-to https://vector-perf.feat.apps.paas.datastax.com:8427/api/v1/import/prometheus/metrics/job/nosqlbench/instance/vectors --annotators &quot;[{'type':'log','level':'info'},{'type':'grafana','baseurl':'https://vector-perf.feat.apps.paas.datastax.com/'}]&quot; --report-interval 10 --show-stacktraces --logs-max 5" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/local/google_spanner" />
<option name="ALTERNATIVE_JRE_PATH" value="jdk21" />
<envs>
<env name="GOOGLE_APPLICATION_CREDENTIALS" value="$ProjectFileDir$/local/google_spanner/stratperf-068083077315.json" />
<env name="GOOGLE_APPLICATION_CREDENTIALS" value="./stratperf-068083077315.json" />
</envs>
<method v="2" />
</configuration>

View File

@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spanner_schema_database_drop" type="JarApplication" folderName="Google Spanner">
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
<option name="credential" />
<option name="region" />
<option name="useCurrentConnection" value="false" />
</extension>
<option name="JAR_PATH" value="$PROJECT_DIR$/nb5/target/nb5.jar" />
<option name="VM_PARAMETERS" value="--enable-preview" />
<option name="PROGRAM_PARAMETERS" value="drop_database_ddl default.drop_db_ddl project_id=stratperf instance_id=perftest-spanner database_id=baselines1 service_account_file=./stratperf-068083077315.json --progress console:1s -v --add-labels=&quot;target:spanner,instance:vectors,vendor:gcp&quot; --report-prompush-to https://vector-perf.feat.apps.paas.datastax.com:8427/api/v1/import/prometheus/metrics/job/nosqlbench/instance/vectors --annotators &quot;[{'type':'log','level':'info'},{'type':'grafana','baseurl':'https://vector-perf.feat.apps.paas.datastax.com/'}]&quot; --report-interval 10 --show-stacktraces --logs-max 5" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/local/google_spanner" />
<option name="ALTERNATIVE_JRE_PATH" value="jdk21" />
<envs>
<env name="GOOGLE_APPLICATION_CREDENTIALS" value="./stratperf-068083077315.json" />
</envs>
<method v="2" />
</configuration>
</component>

View File

@ -22,12 +22,14 @@ import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.Spanner;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import java.util.Collections;
/**
* This class represents an operation to create the database DDL (Data Definition Language) in Google Cloud Spanner.
* It extends the {@link GCPSpannerBaseOp} class and provides the implementation for applying the DDL update operation.
*/
public class GCPSpannerCreateDatabaseDdlOp extends GCPSpannerBaseOp<Long> {
private final String createDatbaseStatement;
private final String databaseId;
private final DatabaseAdminClient dbAdminClient;
private final String instanceId;
@ -36,20 +38,20 @@ public class GCPSpannerCreateDatabaseDdlOp extends GCPSpannerBaseOp<Long> {
*
* @param searchIndexClient the {@link Spanner} client
* @param requestParam the request parameter
* @param createDatbaseStatement the SQL statement to create the table
* @param databaseId the SQL statement to create the table
* @param dbAdminClient the {@link DatabaseAdminClient} to execute the DDL update
* @param instanceId the instance ID string representing the target spanner instance
*/
public GCPSpannerCreateDatabaseDdlOp(Spanner searchIndexClient, Long requestParam, String createDatbaseStatement,
public GCPSpannerCreateDatabaseDdlOp(Spanner searchIndexClient, Long requestParam, String databaseId,
DatabaseAdminClient dbAdminClient, String instanceId) {
super(searchIndexClient, requestParam);
this.createDatbaseStatement = createDatbaseStatement;
this.databaseId = databaseId;
this.dbAdminClient = dbAdminClient;
this.instanceId = instanceId;
}
/**
* Applies the DDL create operation.
* Applies the DDL create database operation.
*
* @param value the value to be used in the operation
* @return the result of the operation
@ -58,10 +60,7 @@ public class GCPSpannerCreateDatabaseDdlOp extends GCPSpannerBaseOp<Long> {
@Override
public Object applyOp(long value) {
OperationFuture<Database, CreateDatabaseMetadata> operation = dbAdminClient.createDatabase(
instanceId,
createDatbaseStatement,
null,
null);
instanceId, databaseId, Collections.emptyList());
try {
return operation.get();
} catch (Exception e) {

View File

@ -7,5 +7,4 @@ blocks:
schema_db:
ops:
op1:
create_database_ddl: |
CREATE DATABASE TEMPLATE(database_id)
create_database_ddl: TEMPLATE(database_id)