Skip to content

Commit

Permalink
548: Support Spdb memtable in Java
Browse files Browse the repository at this point in the history
  • Loading branch information
ayulas committed Aug 14, 2023
1 parent 2075487 commit 6ebadaf
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 844 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ set(SOURCES
memory/memory_allocator.cc
memtable/alloc_tracker.cc
memtable/hash_linklist_rep.cc
memtable/hash_spdb_rep.cc
memtable/hash_skiplist_rep.cc
memtable/skiplistrep.cc
memtable/vectorrep.cc
Expand Down
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Also switch to waiting a sec on the CV each time. This is required since a bg er
* db_bench: Create a WBM once for all db-s regardless of their use in different groups (#550)
* Tompstone unit test faiure (#560)
* build: Remove unused variables in unit tests (#581)

* support hash_spdb in java (#548)
### Miscellaneous
* disable failing unit tests and paired bloom filter stress testing
* version: update Speedb patch version to 2.4.1 (#503)
Expand Down
3 changes: 3 additions & 0 deletions include/rocksdb/memtablerep.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,7 @@ extern MemTableRepFactory* NewHashLinkListRepFactory(
bool if_log_bucket_dist_when_flash = true,
uint32_t threshold_use_skiplist = 256);

// The factory is to create memtables based on a sorted hash table - spdb hash:
extern MemTableRepFactory* NewHashSpdbRepFactory(size_t bucket_count = 1000000);

} // namespace ROCKSDB_NAMESPACE
2 changes: 2 additions & 0 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ set(JAVA_MAIN_CLASSES
src/main/java/org/rocksdb/FlushOptions.java
src/main/java/org/rocksdb/HashLinkedListMemTableConfig.java
src/main/java/org/rocksdb/HashSkipListMemTableConfig.java
src/main/java/org/rocksdb/HashSpdbMemTableConfig.java
src/main/java/org/rocksdb/HistogramData.java
src/main/java/org/rocksdb/HistogramType.java
src/main/java/org/rocksdb/Holder.java
Expand Down Expand Up @@ -455,6 +456,7 @@ if(${CMAKE_VERSION} VERSION_LESS "3.11.4")
org.rocksdb.FlushOptions
org.rocksdb.HashLinkedListMemTableConfig
org.rocksdb.HashSkipListMemTableConfig
org.rocksdb.HashSpdbMemTableConfig
org.rocksdb.IngestExternalFileOptions
org.rocksdb.Logger
org.rocksdb.LRUCache
Expand Down
1 change: 1 addition & 0 deletions java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ NATIVE_JAVA_CLASSES = \
org.rocksdb.IngestExternalFileOptions\
org.rocksdb.HashLinkedListMemTableConfig\
org.rocksdb.HashSkipListMemTableConfig\
org.rocksdb.HashSpdbMemTableConfig\
org.rocksdb.ConcurrentTaskLimiter\
org.rocksdb.ConcurrentTaskLimiterImpl\
org.rocksdb.KeyMayExist\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ private void prepareOptions(Options options) throws RocksDBException {
.setBucketCount(hashBucketCount_));
options.useFixedLengthPrefixExtractor(prefixSize_);
break;
case "hash_spdb":
options.setMemTableConfig(new HashSpdbMemTableConfig().setBucketCount(hashBucketCount_));
break;
default:
System.err.format(
"unable to detect the specified memtable, " +
Expand Down
18 changes: 18 additions & 0 deletions java/rocksjni/memtablejni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "include/org_rocksdb_HashLinkedListMemTableConfig.h"
#include "include/org_rocksdb_HashSkipListMemTableConfig.h"
#include "include/org_rocksdb_HashSpdbMemTableConfig.h"
#include "include/org_rocksdb_SkipListMemTableConfig.h"
#include "include/org_rocksdb_VectorMemTableConfig.h"
#include "rocksdb/memtablerep.h"
Expand All @@ -32,6 +33,23 @@ jlong Java_org_rocksdb_HashSkipListMemTableConfig_newMemTableFactoryHandle(
return 0;
}

/*
* Class: org_rocksdb_HashSpdbMemTableConfig
* Method: newMemTableFactoryHandle
* Signature: (JII)J
*/
jlong Java_org_rocksdb_HashSpdbMemTableConfig_newMemTableFactoryHandle(
JNIEnv* env, jobject /*jobj*/, jlong jbucket_count) {
ROCKSDB_NAMESPACE::Status s =
ROCKSDB_NAMESPACE::JniUtil::check_if_jlong_fits_size_t(jbucket_count);
if (s.ok()) {
return GET_CPLUSPLUS_POINTER(ROCKSDB_NAMESPACE::NewHashSpdbRepFactory(
static_cast<size_t>(jbucket_count)));
}
ROCKSDB_NAMESPACE::IllegalArgumentExceptionJni::ThrowNew(env, s);
return 0;
}

/*
* Class: org_rocksdb_HashLinkedListMemTableConfig
* Method: newMemTableFactoryHandle
Expand Down
3 changes: 3 additions & 0 deletions java/samples/src/main/java/RocksDBSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static void main(final String[] args) {
options.setMemTableConfig(new SkipListMemTableConfig());
assert (options.memTableFactoryName().equals("SkipListFactory"));

options.setMemTableConfig(new HashSpdbMemTableConfig().setBucketCount(1000000));
assert (options.memTableFactoryName().equals("HashSpdbMemTableConfig"));

options.setTableFormatConfig(new PlainTableConfig());
// Plain-Table requires mmap read
options.setAllowMmapReads(true);
Expand Down
38 changes: 38 additions & 0 deletions java/src/main/java/org/rocksdb/HashSpdbMemTableConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
package org.rocksdb;

/**
* The config for hash spdbd memtable representation.
*/
public class HashSpdbMemTableConfig extends MemTableConfig {
public static final int DEFAULT_BUCKET_COUNT = 1000000;

/**
* HashSpdbMemTableConfig constructor
*/
public HashSpdbMemTableConfig() {
bucketCount_ = DEFAULT_BUCKET_COUNT;
}

/**
* Set the number of hash buckets used in the hash spdb memtable.
* Default = 1000000.
*
* @param count the number of hash buckets used in the hash
* spdb memtable.
* @return the reference to the current HashSpdbMemTableConfig.
*/
public HashSpdbMemTableConfig setBucketCount(final long count) {
bucketCount_ = count;
return this;
}

@Override
protected long newMemTableFactoryHandle() {
return newMemTableFactoryHandle(bucketCount_);
}

private native long newMemTableFactoryHandle(long bucketCount) throws IllegalArgumentException;

private long bucketCount_;
}
18 changes: 18 additions & 0 deletions java/src/test/java/org/rocksdb/MemTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ public void hashSkipListMemTable() throws RocksDBException {
}
}

@Test
public void hashSpdbMemTable() throws RocksDBException {
try (final Options options = new Options()) {
// Test HashSpdbMemTableConfig
HashSpdbMemTableConfig memTableConfig = new HashSpdbMemTableConfig();
assertThat(memTableConfig.bucketCount()).isEqualTo(1000000);
memTableConfig.setBucketCount(2000000);
assertThat(memTableConfig.bucketCount()).isEqualTo(2000000);
assertThat(memTableConfig.height()).isEqualTo(4);
memTableConfig.setHeight(5);
assertThat(memTableConfig.height()).isEqualTo(5);
assertThat(memTableConfig.branchingFactor()).isEqualTo(4);
memTableConfig.setBranchingFactor(6);
assertThat(memTableConfig.branchingFactor()).isEqualTo(6);
options.setMemTableConfig(memTableConfig);
}
}

@Test
public void skipListMemTable() throws RocksDBException {
try(final Options options = new Options()) {
Expand Down
Loading

0 comments on commit 6ebadaf

Please sign in to comment.