Skip to content

feat: enable experimental grpc support #1419

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

Merged
merged 43 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0f79a32
chore: Importing auto-generated code from googleapis-gen (#1235)
jainsahab Nov 16, 2023
a7c9beb
refactor: Swap usage of HttpDatastoreRpc with GrpcDatastoreRpc (#1240)
jainsahab Nov 27, 2023
7048bdd
feat!: Actionable Error (#1244)
jainsahab Nov 28, 2023
74941d8
feat!: Making Datastore implement Closeable (#1246)
jainsahab Dec 14, 2023
874829a
feat: enabling regapic by giving an option to user to use http (#1261)
jainsahab Dec 18, 2023
780c9f4
test: Creating multi db rule to run tests multiple times against diff…
jainsahab Dec 29, 2023
408bb21
feat: remove `@BetaApi` annotations from get/setDatabaseId methods (#…
kolea2 Jan 4, 2024
f077c04
feat!: mark interfaces as `@InternalExtensionOnly` (#1275)
kolea2 Jan 8, 2024
030f7fa
refactor: rename internal class QueryAndReadOptions to QueryConfig (#…
kolea2 Jan 8, 2024
c3038bf
deps: remove dependency on datastore-v1-proto-client module in google…
kolea2 Jan 9, 2024
4ee028e
feat: use existing transport options API to set transport (#1276)
kolea2 Jan 16, 2024
8fbade6
deps: bump com.google.truth:truth from 1.1.5 to 1.4.0 (#1323)
dependabot[bot] Feb 7, 2024
cdfbead
deps: bump com.google.cloud:google-cloud-shared-config from 1.6.1 to …
dependabot[bot] Feb 7, 2024
8b1d52e
deps: bump com.google.cloud:google-cloud-shared-dependencies from 3.1…
dependabot[bot] Feb 7, 2024
73db598
deps: bump org.apache.maven.plugins:maven-compiler-plugin from 3.11.0…
dependabot[bot] Feb 7, 2024
2b99ee2
test(deps): upgrade errorprone to 2.24.0 (#1271) (#1329)
kolea2 Feb 7, 2024
71f510d
deps: bump com.google.errorprone:error_prone_core from 2.23.0 to 2.24…
dependabot[bot] Feb 7, 2024
cca8963
feat: allow setting channel and credential providers in DatastoreOpti…
kolea2 Feb 8, 2024
8897a86
chore: Update CODEOWNERS (#1297) (#1331)
kolea2 Feb 12, 2024
fcff21b
chore: run owlbot (#1330)
kolea2 Feb 12, 2024
d78a453
deps: bump com.google.cloud:google-cloud-shared-dependencies from 3.2…
dependabot[bot] Feb 14, 2024
fc4ae89
deps: bump com.google.truth:truth from 1.4.0 to 1.4.1 (#1341)
dependabot[bot] Feb 20, 2024
ffcd012
deps: bump com.google.errorprone:error_prone_core from 2.24.1 to 2.25…
dependabot[bot] Feb 20, 2024
b30ee06
revert: "test: Creating multi db rule to run tests multiple times aga…
kolea2 Feb 23, 2024
508e150
deps: bump com.google.truth:truth from 1.4.1 to 1.4.2 (#1354)
dependabot[bot] Mar 6, 2024
59c2de7
deps: bump com.google.cloud:google-cloud-shared-dependencies from 3.2…
dependabot[bot] Mar 6, 2024
1123e16
deps: bump com.google.cloud:google-cloud-shared-config from 1.7.1 to …
dependabot[bot] Mar 6, 2024
45df7f5
deps: bump com.google.errorprone:error_prone_core from 2.25.0 to 2.26…
dependabot[bot] Mar 12, 2024
2bdadba
test: parameterize tests for http and grpc transports (#1360)
kolea2 Mar 13, 2024
1daca49
deps: bump com.google.errorprone:error_prone_core from 2.26.0 to 2.26…
dependabot[bot] Mar 13, 2024
8c43272
deps: bump com.google.guava:guava-testlib from 33.0.0-jre to 33.1.0-j…
dependabot[bot] Mar 14, 2024
2a87d08
deps: bump com.google.cloud:google-cloud-shared-config from 1.7.4 to …
dependabot[bot] Mar 14, 2024
7e86e88
deps: bump com.google.cloud:google-cloud-shared-config from 1.7.5 to …
dependabot[bot] Mar 15, 2024
48a54d5
deps: bump com.google.cloud:google-cloud-shared-dependencies from 3.2…
dependabot[bot] Mar 18, 2024
2fdc10b
deps: bump org.apache.maven.plugins:maven-compiler-plugin from 3.12.1…
dependabot[bot] Mar 20, 2024
f2c19c7
feat: allow opt-in for gRPC, have datastore-v1-proto-client as defaul…
kolea2 Apr 23, 2024
a35c9ee
deps: bump com.google.cloud:google-cloud-shared-dependencies from 3.2…
dependabot[bot] Apr 23, 2024
77d9c18
deps: bump com.google.cloud:google-cloud-shared-config from 1.7.6 to …
dependabot[bot] Apr 23, 2024
4c2d4ce
feat: have DatastoreException extend BaseHttpServiceException, conver…
kolea2 Apr 25, 2024
fdbc2dc
merge upstream
kolea2 Apr 30, 2024
ca0fc00
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] May 1, 2024
6db6188
update clirr
kolea2 May 1, 2024
b744e9a
revert version changes
kolea2 May 1, 2024
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
6 changes: 5 additions & 1 deletion .github/.OwlBot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ deep-copy-regex:
dest: "/owl-bot-staging/$1/proto-google-cloud-datastore-$1/src"
- source: "/google/datastore/admin/(v.*)/.*-java/proto-google-.*/src"
dest: "/owl-bot-staging/$1/proto-google-cloud-datastore-admin-$1/src"
- source: "/google/datastore/(v.*)/.*-java/grpc-google-.*/src"
dest: "/owl-bot-staging/$1/grpc-google-cloud-datastore-$1/src"
- source: "/google/datastore/admin/(v.*)/.*-java/grpc-google-.*/src"
dest: "/owl-bot-staging/$1/grpc-google-cloud-datastore-admin-$1/src"
# Admin & Data APIs share the same wrapper library.
- source: "/google/datastore/(v.*)/.*-java/gapic-google-.*/src"
dest: "/owl-bot-staging/$1/google-cloud-datastore/src"
- source: "/google/datastore/admin/(v.*)/.*-java/gapic-google-.*/src"
dest: "/owl-bot-staging/$1/google-cloud-datastore/src"
dest: "/owl-bot-staging/$1/google-cloud-datastore/src"
12 changes: 0 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 2

updates:
- package-ecosystem: "maven"
directory: "/"
Expand All @@ -18,14 +17,3 @@ updates:
# it via template in the synthtool repository.
ignore:
- dependency-name: "*"

# rules for the `V3-experimental` branch
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
commit-message:
# Prefix all commit messages with "deps: "
prefix: "deps"
open-pull-requests-limit: 10
target-branch: "V3-experimental"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ target/
*.iml
__pycache__/

.flattened-pom.xml
.flattened-pom.xml
59 changes: 45 additions & 14 deletions google-cloud-datastore/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- see http://mojo.codehaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
<differences>
<!-- added a default method to an interface-->
<!-- renaming internal only class-->
<difference>
<className>com/google/cloud/datastore/ReadOption$QueryAndReadOptions</className>
<method>*</method>
<differenceType>8001</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer</className>
<method>*QueryAndReadOptions*</method>
<to>*QueryConfig*</to>
<differenceType>7005</differenceType>
</difference>
<difference>
<!-- Added BaseGrpcServiceException as a superclass -->
<className>com/google/cloud/datastore/DatastoreException</className>
<differenceType>5000</differenceType>
<to>com/google/cloud/grpc/BaseGrpcServiceException</to>
</difference>
<difference>
<!-- Removed BaseHttpServiceException as a superclass -->
<className>com/google/cloud/datastore/DatastoreException</className>
<differenceType>5001</differenceType>
<to>com/google/cloud/http/BaseHttpServiceException</to>
</difference>
<difference>
<className>com/google/cloud/datastore/Datastore</className>
<method>void close()</method>
<differenceType>7012</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/spi/v1/DatastoreRpc</className>
<method>void close()</method>
<differenceType>7012</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/Datastore</className>
<method>boolean isClosed()</method>
<differenceType>7012</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/spi/v1/DatastoreRpc</className>
<method>boolean isClosed()</method>
<differenceType>7012</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/Datastore</className>
<method>com.google.cloud.datastore.QueryResults run(com.google.cloud.datastore.Query, com.google.cloud.datastore.models.ExplainOptions, com.google.cloud.datastore.ReadOption[])</method>
Expand All @@ -14,7 +57,7 @@
</difference>
<difference>
<className>com/google/cloud/datastore/DatastoreReader</className>
<method> com.google.cloud.datastore.AggregationResults runAggregation(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.models.ExplainOptions)</method>
<method>com.google.cloud.datastore.AggregationResults runAggregation(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.models.ExplainOptions)</method>
<differenceType>7012</differenceType>
</difference>
<difference>
Expand All @@ -28,18 +71,6 @@
<differenceType>7012</differenceType>
</difference>

<!-- changed parmeters on internal only class-->
<difference>
<className>com/google/cloud/datastore/ReadOption$QueryConfig</className>
<method>com.google.cloud.datastore.ReadOption$QueryConfig create(com.google.cloud.datastore.Query, java.util.List)</method>
<to>*com.google.datastore.v1.ExplainOptions*</to>
<differenceType>7005</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/ReadOption$QueryConfig</className>
<method>com.google.cloud.datastore.ReadOption$QueryConfig create(com.google.cloud.datastore.Query)</method>
<differenceType>7004</differenceType>
</difference>
<difference>
<className>com/google/cloud/datastore/execution/AggregationQueryExecutor</className>
<method>com.google.cloud.datastore.AggregationResults execute(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.ReadOption[])</method>
Expand Down
8 changes: 8 additions & 0 deletions google-cloud-datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<site.installationModule>google-cloud-datastore</site.installationModule>
</properties>
<dependencies>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-datastore-v1</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-datastore-admin-v1</artifactId>
Expand All @@ -26,6 +30,10 @@
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core-http</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core-grpc</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-datastore-v1</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.datastore;

import com.google.api.core.InternalExtensionOnly;
import java.util.List;
import javax.annotation.concurrent.NotThreadSafe;

Expand All @@ -42,6 +43,7 @@
* This class too should not be treated as a thread safe class. </b>
*/
@NotThreadSafe
@InternalExtensionOnly
public interface Batch extends DatastoreBatchWriter {

interface Response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package com.google.cloud.datastore;

import com.google.api.core.BetaApi;
import com.google.api.core.InternalExtensionOnly;
import com.google.cloud.Service;
import com.google.cloud.datastore.models.ExplainOptions;
import com.google.datastore.v1.TransactionOptions;
import java.util.Iterator;
import java.util.List;

/** An interface for Google Cloud Datastore. */
public interface Datastore extends Service<DatastoreOptions>, DatastoreReaderWriter {
@InternalExtensionOnly
public interface Datastore extends Service<DatastoreOptions>, DatastoreReaderWriter, AutoCloseable {

/**
* Returns a new Datastore transaction.
Expand All @@ -51,9 +53,9 @@ public interface Datastore extends Service<DatastoreOptions>, DatastoreReaderWri
* @param <T> the type of the return value
*/
interface TransactionCallable<T> {

T run(DatastoreReaderWriter readerWriter) throws Exception;
}

/**
* Invokes the callback's {@link Datastore.TransactionCallable#run} method with a {@link
* DatastoreReaderWriter} that is associated with a new transaction. The transaction will be
Expand Down Expand Up @@ -481,10 +483,7 @@ interface TransactionCallable<T> {
* @throws DatastoreException upon failure
*/
@BetaApi
default <T> QueryResults<T> run(
Query<T> query, ExplainOptions explainOptions, ReadOption... options) {
throw new UnsupportedOperationException("Not implemented.");
}
<T> QueryResults<T> run(Query<T> query, ExplainOptions explainOptions, ReadOption... options);

/**
* Submits a {@link AggregationQuery} and returns {@link AggregationResults}. {@link ReadOption}s
Expand Down Expand Up @@ -529,9 +528,7 @@ default <T> QueryResults<T> run(
* @throws DatastoreException upon failure
* @return {@link AggregationResults}
*/
default AggregationResults runAggregation(AggregationQuery query, ReadOption... options) {
throw new UnsupportedOperationException("Not implemented.");
}
AggregationResults runAggregation(AggregationQuery query, ReadOption... options);

/**
* Submits a {@link AggregationQuery} with specified {@link
Expand All @@ -557,8 +554,17 @@ default AggregationResults runAggregation(AggregationQuery query, ReadOption...
* @return {@link AggregationResults}
*/
@BetaApi
default AggregationResults runAggregation(
AggregationQuery query, ExplainOptions explainOptions, ReadOption... options) {
throw new UnsupportedOperationException("Not implemented.");
}
AggregationResults runAggregation(
AggregationQuery query, ExplainOptions explainOptions, ReadOption... options);

/**
* Closes the gRPC channels associated with this instance and frees up their resources. This
* method blocks until all channels are closed. Once this method is called, this Datastore client
* is no longer usable.
*/
@Override
void close() throws Exception;

/** Returns true if this background resource has been shut down. */
boolean isClosed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.datastore;

import com.google.api.core.InternalExtensionOnly;
import java.util.List;
import javax.annotation.concurrent.NotThreadSafe;

Expand All @@ -31,6 +32,7 @@
* This class too should not be treated as a thread safe class. </b>
*/
@NotThreadSafe
@InternalExtensionOnly
public interface DatastoreBatchWriter extends DatastoreWriter {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@

package com.google.cloud.datastore;

import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.StatusCode;
import com.google.cloud.BaseServiceException;
import com.google.cloud.RetryHelper.RetryHelperException;
import com.google.cloud.http.BaseHttpServiceException;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import io.grpc.StatusException;
import io.grpc.StatusRuntimeException;
import java.io.IOException;
import java.util.Set;

Expand All @@ -43,6 +49,10 @@ public DatastoreException(int code, String message, String reason) {
this(code, message, reason, true, null);
}

public DatastoreException(int code, String message, Throwable cause) {
super(code, message, null, true, RETRYABLE_ERRORS, cause);
}

public DatastoreException(int code, String message, String reason, Throwable cause) {
super(code, message, reason, true, RETRYABLE_ERRORS, cause);
}
Expand All @@ -64,7 +74,76 @@ public DatastoreException(IOException exception) {
*/
static DatastoreException translateAndThrow(RetryHelperException ex) {
BaseServiceException.translate(ex);
throw new DatastoreException(UNKNOWN_CODE, ex.getMessage(), null, ex.getCause());
throw transformThrowable(ex);
}

static BaseServiceException transformThrowable(Throwable t) {
if (t instanceof BaseServiceException) {
return (BaseServiceException) t;
}
if (t.getCause() instanceof BaseServiceException) {
return (BaseServiceException) t.getCause();
}
if (t instanceof ApiException) {
return asDatastoreException((ApiException) t);
}
if (t.getCause() instanceof ApiException) {
return asDatastoreException((ApiException) t.getCause());
}
return getDatastoreException(t);
}

private static DatastoreException getDatastoreException(Throwable t) {
// unwrap a RetryHelperException if that is what is being translated
if (t instanceof RetryHelperException) {
return new DatastoreException(UNKNOWN_CODE, t.getMessage(), null, t.getCause());
}
return new DatastoreException(UNKNOWN_CODE, t.getMessage(), t);
}

static DatastoreException asDatastoreException(ApiException apiEx) {
int datastoreStatusCode = 0;
StatusCode statusCode = apiEx.getStatusCode();
if (statusCode instanceof GrpcStatusCode) {
GrpcStatusCode gsc = (GrpcStatusCode) statusCode;
datastoreStatusCode =
GrpcToDatastoreCodeTranslation.grpcCodeToDatastoreStatusCode(gsc.getTransportCode());
}

// If there is a gRPC exception in our cause, pull its error message up to be our
// message otherwise, create a generic error message with the status code.
String statusCodeName = statusCode.getCode().name();
String statusExceptionMessage = getStatusExceptionMessage(apiEx);

String message;
if (statusExceptionMessage != null) {
message = statusCodeName + ": " + statusExceptionMessage;
} else {
message = "Error: " + statusCodeName;
}

String reason = "";
if (Strings.isNullOrEmpty(apiEx.getReason())) {
if (apiEx.getStatusCode() != null) {
reason = apiEx.getStatusCode().getCode().name();
}
}
// It'd be better to use ExceptionData and BaseServiceException#<init>(ExceptionData) but,
// BaseHttpServiceException does not pass that through so we're stuck using this for now.
// TODO: When we can break the coupling to BaseHttpServiceException replace this
return new DatastoreException(datastoreStatusCode, message, reason, apiEx);
}

private static String getStatusExceptionMessage(Exception apiEx) {
if (apiEx.getMessage() != null) {
return apiEx.getMessage();
} else {
Throwable cause = apiEx.getCause();
if (cause instanceof StatusRuntimeException || cause instanceof StatusException) {
return cause.getMessage();
}
return null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.google.cloud.datastore;

import com.google.api.core.InternalExtensionOnly;
import com.google.cloud.ServiceFactory;

/** An interface for Datastore factories. */
@InternalExtensionOnly
public interface DatastoreFactory extends ServiceFactory<Datastore, DatastoreOptions> {}
Loading
Loading