Skip to content

Commit

Permalink
Merge pull request #3 from soundvibe/unlimited-keys
Browse files Browse the repository at this point in the history
Unlimited keys
  • Loading branch information
soundvibe authored Nov 25, 2019
2 parents 79e7592 + c081257 commit ed8b1cf
Show file tree
Hide file tree
Showing 40 changed files with 1,189 additions and 932 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ PalDB is an embeddable persistent key-value store with very fast read performanc

PalDB's JAR is only 65K and has a single dependency (snappy, which isn't mandatory). It's also very easy to use with just a few configuration parameters.

**This is separate evolution of original PalDB.**

Improvements from PalDB 1.0.2
-------------------
- StoreReader is now fully thread-safe without any performance decrease.
- StoreReader and StoreWriter can be used with generics (StoreReader<K<V> and StoreWriter<K,V>)
- Typesafe ``PalDBConfigBuilder`` for easier configuration
- There are no limits on how many keys you can store
- Duplicates could be optionally allowed
- Bloom filters could be enabled for even better read performance in some cases

Performance
-----------

Expand Down Expand Up @@ -74,12 +85,12 @@ PalDB is available on Maven Central, hence just add the following dependency:
<dependency>
<groupId>net.soundvibe</groupId>
<artifactId>paldb</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</dependency>
```
Scala SBT
```
libraryDependencies += "net.soundvibe" % "paldb" % "2.0.1"
libraryDependencies += "net.soundvibe" % "paldb" % "2.0.2"
```


Expand All @@ -92,7 +103,7 @@ No, the final binary file is created when `StoreWriter.close()` is called.

**Are duplicate keys allowed?**

No, duplicate keys aren't allowed and an exception will be thrown.
Duplicates are not allowed by default. But it could be changed in writer configuration if needed.

**Do keys have an order when iterating?**

Expand Down Expand Up @@ -131,6 +142,7 @@ Write parameters:
+ `compression.enabled`, enable compression (boolean) [default: false]
+ `bloom.filter.enabled`, enable bloom filter (boolean) [default: false]
+ `bloom.filter.error.factor`, bloom filter error rate (double) [default: 0.01]
+ `duplicates.enabled`, allow duplicates (boolean) [default: false]

Read parameters:

Expand Down Expand Up @@ -204,7 +216,6 @@ Machine-learning applications often have complex binary model files created in t
Limitations
-----------
+ PalDB is optimal in replacing the usage of large in-memory data storage but still use memory (off-heap, yet much less) to do its job. Disabling memory mapping and relying on seeks is possible but is not what PalDB has been optimized for.
+ The size of the index is limited to 2GB. There's no limitation in the data size however.
+ PalDB reader is thread-safe but writer is not thread-safe at the moment so synchronization should be done externally if multi-threaded.

Contributions
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.soundvibe</groupId>
<artifactId>paldb</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<packaging>jar</packaging>
<name>paldb</name>
<description>Embeddable persistent write-once key-value store</description>
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
<version>4.0</version>
<version>6.2.2</version>
<scope>test</scope>
</dependency>

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/linkedin/paldb/api/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class Configuration {
public static final String BLOOM_FILTER_ENABLED = "bloom.filter.enabled";
//Bloom filter error rate
public static final String BLOOM_FILTER_ERROR_FACTOR = "bloom.filter.error.factor";
//Enable duplicates (keep last key)
public static final String ALLOW_DUPLICATES = "duplicates.enabled";

// Property map
private final Map<String, String> properties = new HashMap<>();
Expand All @@ -72,6 +74,7 @@ public Configuration() {
putWithSystemPropertyDefault(COMPRESSION_ENABLED, "false");
putWithSystemPropertyDefault(BLOOM_FILTER_ENABLED, "false");
putWithSystemPropertyDefault(BLOOM_FILTER_ERROR_FACTOR, "0.01");
putWithSystemPropertyDefault(ALLOW_DUPLICATES, "false");

//Serializers
serializers = new Serializers();
Expand Down Expand Up @@ -411,7 +414,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
int result = properties != null ? properties.hashCode() : 0;
int result = properties.hashCode();
result = 31 * result + (serializers != null ? serializers.hashCode() : 0);
return result;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/linkedin/paldb/api/PalDBConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public PalDBConfigBuilder withEnableCompression(boolean enabled) {
return this;
}

/**
* <i>PalDB configuration property.</i>
* <p>
* <code>duplicates.enabled</code> - allow duplicates [default: false]
* @param enabled flag
* @return this {@code CachemeerConfigBuilder} instance (for chaining)
*/
public PalDBConfigBuilder withEnableDuplicates(boolean enabled) {
palDbConfiguration.set(Configuration.ALLOW_DUPLICATES, String.valueOf(enabled));
return this;
}

/**
* <i>PalDB configuration property.</i>
* <p>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/linkedin/paldb/api/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
* configuration.registerSerializer(new PointSerializer());
* </pre>
*
* @param <K> class type
* @param <T> class type
*/
public interface Serializer<K> extends Serializable {
public interface Serializer<T> extends Serializable {

/**
* Writes the instance <code>input</code> to the data output.
* @param dataOutput data output
* @param input instance
* @throws IOException if an io error occurs
*/
void write(DataOutput dataOutput, K input) throws IOException;
void write(DataOutput dataOutput, T input) throws IOException;

/**
* Reads the data input and creates the instance.
Expand All @@ -48,7 +48,7 @@ public interface Serializer<K> extends Serializable {
* @return new instance of type <code>K</code>.
* @throws IOException if an io error occurs
*/
K read(DataInput dataInput) throws IOException;
T read(DataInput dataInput) throws IOException;

Class<K> serializedClass();
Class<T> serializedClass();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.linkedin.paldb.api.errors;

public class DuplicateKeyException extends RuntimeException {
public class DuplicateKeyException extends PalDBException {

public DuplicateKeyException(String message) {
super(message);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/linkedin/paldb/api/errors/MissingClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.linkedin.paldb.api.errors;

public class MissingClass extends PalDBException {
public MissingClass(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.linkedin.paldb.api.errors;

public class MissingSerializer extends PalDBException {
public MissingSerializer(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.linkedin.paldb.api.errors;

public class OutOfDiskSpace extends RuntimeException {
public class OutOfDiskSpace extends PalDBException {

public OutOfDiskSpace(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.linkedin.paldb.api.errors;

public abstract class PalDBException extends RuntimeException {

public PalDBException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @see StoreReader
*/
public class UnsupportedTypeException extends RuntimeException {
public class UnsupportedTypeException extends PalDBException {

public UnsupportedTypeException(Object obj) {
super("The type '" + obj.getClass() + "' isn't supported");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.linkedin.paldb.api.errors;

public class VersionMismatch extends PalDBException {

public VersionMismatch(String message) {
super(message);
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/linkedin/paldb/impl/ReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ public V get(K key, V defaultValue) {
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

Expand Down
Loading

0 comments on commit ed8b1cf

Please sign in to comment.