зеркало из https://github.com/Azure/YCSB.git
[googledatastore] Update googledatastore API version to v1beta3.
This commit is contained in:
Родитель
d4e3f60c29
Коммит
445c895947
|
@ -26,7 +26,7 @@
|
|||
|
||||
# Google Cloud Datastore's read and update APIs do not support
|
||||
# reading or updating a select subset of properties for an entity.
|
||||
# (as of version v1beta2-rev1-3.0.2)
|
||||
# (as of version v1beta3)
|
||||
# Therefore, it's recommended that you set writeallfields and readallfields
|
||||
# to true to get stable and comparable performance numbers.
|
||||
writeallfields = true
|
||||
|
|
|
@ -29,11 +29,26 @@ LICENSE file.
|
|||
<name>Google Cloud Datastore Binding</name>
|
||||
<url>https://github.com/GoogleCloudPlatform/google-cloud-datastore</url>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<name>sonatype-snapshots</name>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-datastore-protobuf</artifactId>
|
||||
<version>v1beta2-rev1-3.0.2</version>
|
||||
<groupId>com.google.cloud.datastore</groupId>
|
||||
<artifactId>datastore-v1beta3-proto-client</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud.datastore</groupId>
|
||||
<artifactId>datastore-v1beta3-protos</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
|
@ -47,4 +62,28 @@ LICENSE file.
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.15</version>
|
||||
<configuration>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<configLocation>../checkstyle.xml</configLocation>
|
||||
<failOnViolation>true</failOnViolation>
|
||||
<failsOnError>false</failsOnError>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>checkstyle</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
package com.yahoo.ycsb.db;
|
||||
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.services.datastore.DatastoreV1.*;
|
||||
import com.google.api.services.datastore.DatastoreV1.CommitRequest.Mode;
|
||||
import com.google.api.services.datastore.DatastoreV1.ReadOptions
|
||||
.ReadConsistency;
|
||||
import com.google.api.services.datastore.client.Datastore;
|
||||
import com.google.api.services.datastore.client.DatastoreException;
|
||||
import com.google.api.services.datastore.client.DatastoreFactory;
|
||||
import com.google.api.services.datastore.client.DatastoreHelper;
|
||||
import com.google.api.services.datastore.client.DatastoreOptions;
|
||||
import com.google.datastore.v1beta3.*;
|
||||
import com.google.datastore.v1beta3.CommitRequest.Mode;
|
||||
import com.google.datastore.v1beta3.ReadOptions.ReadConsistency;
|
||||
import com.google.datastore.v1beta3.client.Datastore;
|
||||
import com.google.datastore.v1beta3.client.DatastoreException;
|
||||
import com.google.datastore.v1beta3.client.DatastoreFactory;
|
||||
import com.google.datastore.v1beta3.client.DatastoreHelper;
|
||||
import com.google.datastore.v1beta3.client.DatastoreOptions;
|
||||
|
||||
import com.yahoo.ycsb.ByteIterator;
|
||||
import com.yahoo.ycsb.DB;
|
||||
|
@ -165,7 +164,7 @@ public class GoogleDatastoreClient extends DB {
|
|||
serviceAccountEmail + ", Private Key File Path: " + privateKeyFile);
|
||||
|
||||
datastore = DatastoreFactory.get().create(
|
||||
options.credential(credential).dataset(datasetId).build());
|
||||
options.credential(credential).projectId(datasetId).build());
|
||||
|
||||
} catch (GeneralSecurityException exception) {
|
||||
throw new DBException("Security error connecting to the datastore: " +
|
||||
|
@ -184,7 +183,7 @@ public class GoogleDatastoreClient extends DB {
|
|||
public Status read(String table, String key, Set<String> fields,
|
||||
HashMap<String, ByteIterator> result) {
|
||||
LookupRequest.Builder lookupRequest = LookupRequest.newBuilder();
|
||||
lookupRequest.addKey(buildPrimaryKey(table, key));
|
||||
lookupRequest.addKeys(buildPrimaryKey(table, key));
|
||||
lookupRequest.getReadOptionsBuilder().setReadConsistency(
|
||||
this.readConsistency);
|
||||
// Note above, datastore lookupRequest always reads the entire entity, it
|
||||
|
@ -219,7 +218,7 @@ public class GoogleDatastoreClient extends DB {
|
|||
Entity entity = response.getFound(0).getEntity();
|
||||
logger.debug("Read entity: " + entity.toString());
|
||||
|
||||
Map<String, Value> properties = DatastoreHelper.getPropertyMap(entity);
|
||||
Map<String, Value> properties = entity.getProperties();
|
||||
Set<String> propertiesToReturn =
|
||||
(fields == null ? properties.keySet() : fields);
|
||||
|
||||
|
@ -243,7 +242,6 @@ public class GoogleDatastoreClient extends DB {
|
|||
@Override
|
||||
public Status update(String table, String key,
|
||||
HashMap<String, ByteIterator> values) {
|
||||
|
||||
return doSingleItemMutation(table, key, values, MutationType.UPDATE);
|
||||
}
|
||||
|
||||
|
@ -267,11 +265,11 @@ public class GoogleDatastoreClient extends DB {
|
|||
|
||||
if (this.entityGroupingMode == EntityGroupingMode.MULTI_ENTITY_PER_GROUP) {
|
||||
// All entities are in side the same group when we are in this mode.
|
||||
result.addPathElement(Key.PathElement.newBuilder().setKind(table).
|
||||
result.addPath(Key.PathElement.newBuilder().setKind(table).
|
||||
setName(rootEntityName));
|
||||
}
|
||||
|
||||
return result.addPathElement(Key.PathElement.newBuilder().setKind(table)
|
||||
return result.addPath(Key.PathElement.newBuilder().setKind(table)
|
||||
.setName(key));
|
||||
}
|
||||
|
||||
|
@ -287,27 +285,25 @@ public class GoogleDatastoreClient extends DB {
|
|||
// for multi-item mutation, or Read-modify-write operation.
|
||||
CommitRequest.Builder commitRequest = CommitRequest.newBuilder();
|
||||
commitRequest.setMode(Mode.NON_TRANSACTIONAL);
|
||||
|
||||
if (mutationType == MutationType.DELETE) {
|
||||
commitRequest.getMutationBuilder().addDelete(datastoreKey);
|
||||
|
||||
commitRequest.addMutationsBuilder().setDelete(datastoreKey);
|
||||
} else {
|
||||
// If this is not for delete, build the entity.
|
||||
Entity.Builder entityBuilder = Entity.newBuilder();
|
||||
entityBuilder.setKey(datastoreKey);
|
||||
for (Entry<String, ByteIterator> val : values.entrySet()) {
|
||||
entityBuilder.addProperty(Property.newBuilder()
|
||||
.setName(val.getKey())
|
||||
.setValue(Value.newBuilder()
|
||||
.setStringValue(val.getValue().toString())));
|
||||
entityBuilder.getMutableProperties()
|
||||
.put(val.getKey(),
|
||||
Value.newBuilder()
|
||||
.setStringValue(val.getValue().toString()).build());
|
||||
}
|
||||
Entity entity = entityBuilder.build();
|
||||
logger.debug("entity built as: " + entity.toString());
|
||||
|
||||
if (mutationType == MutationType.UPSERT) {
|
||||
commitRequest.getMutationBuilder().addUpsert(entity);
|
||||
commitRequest.addMutationsBuilder().setUpsert(entity);
|
||||
} else if (mutationType == MutationType.UPDATE){
|
||||
commitRequest.getMutationBuilder().addUpdate(entity);
|
||||
commitRequest.addMutationsBuilder().setUpdate(entity);
|
||||
} else {
|
||||
throw new RuntimeException("Impossible MutationType, code bug.");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче