Phantom is an embedded key-value store, provides extreme high write throughput while maintains low latency data access.
Phantom was inspired by HaloDB, the name "Phantom" (belongs to the darkness) was derived from the name "Halo" (belongs to the light) from HaloDB.
The design principles of Phantom is old and simple. It uses log-structured data files and hash index (like HaloDB) to achieve the high write workload yet still maintain low latency access with the cost of no range scan support.
Add dependency to pom.xml (Maven)
<dependency>
<groupId>io.github.tuannh982</groupId>
<artifactId>phantom</artifactId>
</dependency>
or build.gralde (Gradle)
implementation 'io.github.tuannh982:phantom:+'
String path = "/path/to/your/db/dir";
DB db = new PhantomDB(
new File(path),
PhantomDBOptions.builder()
.numberOfIndexingThread(2 * Runtime.getRuntime().availableProcessors())
.compactionThreshold(0.5f)
.dataFlushThreshold(8 * 1024 * 1024)
.maxKeySize(8)
.maxFileSize(32 * 1024 * 1024)
.maxTombstoneFileSize(8 * 1024 * 1024)
.offHeapHashTable(true)
.estimatedMaxKeyCount(16)
.memoryChunkSize(4 * 1024 * 1024)
.build()
);
byte[] key = new byte[] {...};
GetResult result = db.get(key);
byte[] read = result.getValue();
byte[] key = new byte[] {...};
byte[] value = new byte[] {...};
ModifyResult result = db.put(key, value);
boolean success = result.isSuccess();
byte[] key = new byte[] {...};
byte[] value = new byte[] {...};
ModifyResult result = db.putIfAbsent(key, value);
boolean success = result.isSuccess();
byte[] key = new byte[] {...};
byte[] value = new byte[] {...};
ModifyResult result = db.replace(key, value);
boolean success = result.isSuccess();
byte[] key = new byte[] {...};
ModifyResult result = db.delete(key, value);
boolean success = result.isSuccess();
byte[] key = new byte[] {...};
WriteOps ops = WriteOps.PUT;
WritePolicy policy = WritePolicy.builder()
.sequenceNumberPolicy(WritePolicy.SequenceNumberPolicy.NONE)
.recordExistsAction(WritePolicy.RecordExistsAction.CREATE_ONLY)
.build();
ModifyResult result = db.write(ops, policy, key, value);
boolean success = result.isSuccess();
db.close();
This project still in development, so there are lots of bugs exist. Please don't use the pre-release version as they contain a lot of bugs, use directly from master branch since it's always up-to-date and maybe contains bug fixed.
- Testing
- Unit test
- Performance test
- Benchmark report
- Guide
- Tuning guide
- Development guide
- Support distributed mode
- WAL (in consideration)
- Replication manager