Skip to content

Commit

Permalink
Merge pull request brianfrankcooper#280 from allanbank/ycsb_277
Browse files Browse the repository at this point in the history
[mongodb] Fix brianfrankcooper#277 - Switch from updateOne to replaceOne.
  • Loading branch information
busbey committed Jun 6, 2015
2 parents 2e81e38 + b88aea2 commit 87c4a53
Show file tree
Hide file tree
Showing 6 changed files with 548 additions and 87 deletions.
171 changes: 89 additions & 82 deletions mongodb/pom.xml
@@ -1,87 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>root</artifactId>
<version>0.2.0-SNAPSHOT</version>
</parent>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>root</artifactId>
<version>0.2.0-SNAPSHOT</version>
</parent>

<artifactId>mongodb-binding</artifactId>
<name>MongoDB Binding</name>
<packaging>jar</packaging>
<artifactId>mongodb-binding</artifactId>
<name>MongoDB Binding</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongodb.version}</version>
</dependency>
<dependency>
<groupId>com.allanbank</groupId>
<artifactId>mongodb-async-driver</artifactId>
<version>${mongodb.async.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongodb.version}</version>
</dependency>
<dependency>
<groupId>com.allanbank</groupId>
<artifactId>mongodb-async-driver</artifactId>
<version>${mongodb.async.version}</version>
</dependency>
<dependency>
<groupId>com.yahoo.ycsb</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>1.47.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>allanbank</id>
<name>Allanbank Releases</name>
<url>http://www.allanbank.com/repo/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>allanbank</id>
<name>Allanbank Releases</name>
<url>http://www.allanbank.com/repo/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
10 changes: 6 additions & 4 deletions mongodb/src/main/java/com/yahoo/ycsb/db/MongoDbClient.java
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.bson.Document;
import org.bson.types.Binary;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
Expand Down Expand Up @@ -251,9 +252,10 @@ public int insert(String table, String key,
// Do a single upsert.
if (batchSize <= 1) {
UpdateResult result = collection.withWriteConcern(writeConcern)
.updateOne(criteria, toInsert, UPSERT);
.replaceOne(criteria, toInsert, UPSERT);
if (result.getMatchedCount() > 0
|| result.getModifiedCount() > 0) {
|| result.getModifiedCount() > 0
|| result.getUpsertedId() != null) {
return 0;
}
System.err.println("Nothing inserted for key " + key);
Expand Down Expand Up @@ -465,9 +467,9 @@ public int update(String table, String key,
*/
protected void fillMap(HashMap<String, ByteIterator> resultMap, Document obj) {
for (Map.Entry<String, Object> entry : obj.entrySet()) {
if (entry.getValue() instanceof byte[]) {
if (entry.getValue() instanceof Binary) {
resultMap.put(entry.getKey(), new ByteArrayByteIterator(
(byte[]) entry.getValue()));
((Binary) entry.getValue()).getData()));
}
}
}
Expand Down

0 comments on commit 87c4a53

Please sign in to comment.