Skip to content

Commit

Permalink
Modify readme and googledatastore.properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
cindy-peng committed Dec 5, 2024
1 parent 37350d9 commit 42c7655
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
5 changes: 3 additions & 2 deletions googledatastore/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2015 YCSB contributors.
Copyright (c) 2024 YCSB contributors.
All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down Expand Up @@ -49,7 +49,8 @@ authentication:

https://cloud.google.com/datastore/docs/activate#accessing_the_datastore_api_from_another_platform

After you setup your environment, you will have 3 pieces of information ready:
After you setup your environment, you will have 4 pieces of information ready:
- projectId,
- datasetId,
- service account email, and
- a private key file in P12 format.
Expand Down
17 changes: 15 additions & 2 deletions googledatastore/conf/googledatastore.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015 YCSB contributors. All rights reserved.
# Copyright (c) 2024 YCSB contributors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
Expand All @@ -20,6 +20,7 @@
#
# Your credentials to Google datastore. See README.md for details.
#
# googledatastore.projectId=<string id of your project>
# googledatastore.datasetId=<string id of your dataset>
# googledatastore.privateKeyFile=<full path to your private key file>
# googledatastore.serviceAccountEmail=<Your service account email>
Expand Down Expand Up @@ -56,4 +57,16 @@ readallfields = true
# googledatastore.debug = false

# Skip indexes, default is true.
# googledatastore.skipIndex = true
# googledatastore.skipIndex = true

# Enable/disable tracing, default is false.
# To enable publishing traces to Cloud Trace, googledatastore, tracingenabled must be set
# Tracing depends on the following external APIs/Services:
# 1. Java OpenTelemetry SDK
# 2. Cloud Trace Exporter
# 3. TraceServiceClient from Cloud Trace API v1.
# Permissions to enabled tracing (https://cloud.google.com/trace/docs/iam#trace-roles):
# 1. gcloud auth application-default login must be run with the test user.
# 2. To write traces, test user must have one of roles/cloudtrace.[admin|agent|user] roles.
# 3. To read traces, test user must have one of roles/cloudtrace.[admin|user] roles.
# googledatastore.tracingenabled = false
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,14 @@ private OpenTelemetrySdk getOtelSdk(String projectId) throws DBException {
@Override
public Status read(String table, String key, Set<String> fields,
Map<String, ByteIterator> result) {

KeyFactory keyFactory = datastore.newKeyFactory().setKind(table);
com.google.cloud.datastore.Key newKey = buildPrimaryKey(table).newKey(key);
Entity entity = null;
Span readSpan = tracer.spanBuilder("ycsb-read").startSpan();
try (Scope ignore = readSpan.makeCurrent()) {
if (isEventualConsistency) {
entity = datastore.get(keyFactory.newKey(key), ReadOption.eventualConsistency());
entity = datastore.get(newKey, ReadOption.eventualConsistency());
} else {
entity = datastore.get(keyFactory.newKey(key));
entity = datastore.get(newKey);
}
readSpan.addEvent("datastore.get returned");
} catch (com.google.cloud.datastore.DatastoreException exception) {
Expand Down Expand Up @@ -357,24 +356,21 @@ public Status delete(String table, String key) {
return doSingleItemMutation(table, key, null, MutationType.DELETE);
}

private Key.Builder buildPrimaryKey(String table, String key) {
Key.Builder result = Key.newBuilder();

private KeyFactory buildPrimaryKey(String table) {
KeyFactory keyFactory = datastore.newKeyFactory().setKind(table);
if (this.entityGroupingMode == EntityGroupingMode.MULTI_ENTITY_PER_GROUP) {
// All entities are in side the same group when we are in this mode.
result.addPath(Key.PathElement.newBuilder().setKind(table).
setName(rootEntityName));
keyFactory.addAncestor(PathElement.of(table, rootEntityName));
}

return result.addPath(Key.PathElement.newBuilder().setKind(table)
.setName(key));
return keyFactory;
}

private Status doSingleItemMutation(String table, String key,
@Nullable Map<String, ByteIterator> values,
MutationType mutationType) {
// First build the key.
com.google.cloud.datastore.Key datastoreKey = datastore.newKeyFactory().setKind(table).newKey(key);
com.google.cloud.datastore.Key datastoreKey = buildPrimaryKey(table).newKey(key);
Span singleItemSpan = tracer.spanBuilder("ycsb-update").startSpan();

if (mutationType == MutationType.DELETE) {
Expand Down

0 comments on commit 42c7655

Please sign in to comment.