Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions cloudspanner/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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">
<parent>
<artifactId>binding-parent</artifactId>
<groupId>site.ycsb</groupId>
<version>0.18.0-SNAPSHOT</version>
<relativePath>../binding-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloudspanner-binding</artifactId>
<name>Cloud Spanner DB Binding</name>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer>
<mainClass>org.example.Main</mainClass>
</transformer>
<transformer />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>site.ycsb</groupId>
<artifactId>core</artifactId>
<version>0.18.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Binary file added mapdb/file.db
Binary file not shown.
42 changes: 42 additions & 0 deletions mapdb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>site.ycsb</groupId>
<artifactId>root</artifactId>
<version>0.18.0-SNAPSHOT</version>
</parent>

<artifactId>mapdb-binding</artifactId>
<name>MapDB Binding</name>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>site.ycsb</groupId>
<artifactId>core</artifactId>
<version>0.18.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
132 changes: 132 additions & 0 deletions mapdb/src/main/java/site/ycsb/MapDBClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package site.ycsb;

import org.mapdb.*;
import org.mapdb.DB;

import java.util.*;

/**
* MapDB client for YCSB framework.
*
*/
public class MapDBClient extends site.ycsb.DB {

private DB mapDB;
private HTreeMap<String, TreeMap<String, HashMap<String, byte[]>>> db;

@Override
public void init() throws DBException {
this.mapDB = DBMaker
.fileDB("file.db")
.closeOnJvmShutdown()
.make();

db = mapDB.hashMap("db")
.keySerializer(Serializer.STRING)
.valueSerializer(Serializer.JAVA)
.createOrOpen();
}

public void cleanup() throws DBException {
db.clear();
db.close();
mapDB.close();
}

@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
Map<String, HashMap<String, byte[]>> collection = db.getOrDefault(table, new TreeMap<>());

Map<String, byte[]> map = collection.get(key);

if (map == null) {
return Status.NOT_FOUND;
}

for (String field : fields) {
result.put(field, new ByteArrayByteIterator(map.get(field)));
}

return Status.OK;
}

@Override
public Status scan(String table,
String startkey,
int recordcount,
Set<String> fields,
Vector<HashMap<String, ByteIterator>> result) {
TreeMap<String, HashMap<String, byte[]>> collection = db.getOrDefault(table, new TreeMap<>());
SortedMap<String, HashMap<String, byte[]>> map = collection.tailMap(startkey);

int counter = 0;
for (Map.Entry<String, HashMap<String, byte[]>> entry : map.entrySet()) {
HashMap<String, ByteIterator> filteredMap = new HashMap<>();
if (fields == null) {
for (Map.Entry<String, byte[]> entry1 : entry.getValue().entrySet()) {
filteredMap.put(entry1.getKey(), new ByteArrayByteIterator(entry1.getValue()));
}
} else {
for (Map.Entry<String, byte[]> entry1 : entry.getValue().entrySet()) {
if (fields.contains(entry1.getKey())) {
filteredMap.put(entry1.getKey(), new ByteArrayByteIterator(entry1.getValue()));
}
}
}
result.add(filteredMap);

counter += 1;
if (counter == recordcount) {
break;
}
}

return Status.OK;
}

@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
TreeMap<String, HashMap<String, byte[]>> collection = db.getOrDefault(table, new TreeMap<>());

HashMap<String, byte[]> map = collection.get(key);

if (map == null) {
return Status.NOT_FOUND;
}

for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
map.put(entry.getKey(), entry.getValue().toArray());
}
collection.put(key, map);
db.put(table, collection);

return Status.OK;
}

@Override
public Status insert(String table, String key, Map<String, ByteIterator> values) {
TreeMap<String, HashMap<String, byte[]>> collection = db.getOrDefault(table, new TreeMap<>());

HashMap<String, byte[]> map = collection.getOrDefault(key, new HashMap<>());

for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
map.put(entry.getKey(), entry.getValue().toArray());
}
collection.put(key, map);
db.put(table, collection);

return Status.OK;
}

@Override
public Status delete(String table, String key) {
Map<String, HashMap<String, byte[]>> collection = db.getOrDefault(table, new TreeMap<>());

Map<String, byte[]> removed = collection.remove(key);

if (removed == null) {
return Status.NOT_FOUND;
}
return Status.OK;
}
}
22 changes: 22 additions & 0 deletions mapdb/src/main/java/site/ycsb/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2017, Yahoo!, Inc. 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
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/

/**
* The YCSB binding for MapDB.
*/
package site.ycsb;

Loading