Introduce allowStall option for write buffer manager constructor (#9076)

Summary:
https://github.com/facebook/rocksdb/pull/7898 enable write buffer manager to stall write when memory_usage exceeds buffer_size, this is really useful for container running case to limit the memory usage. However, this feature is not visiable for rocksJava yet.

This PR targets to introduce this feature for rocksJava.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9076

Reviewed By: akankshamahajan15

Differential Revision: D31931092

Pulled By: anand1976

fbshipit-source-id: 5531c16a87598663a02368c07b5e13a503164578
This commit is contained in:
myasuka 2021-10-26 12:08:54 -07:00 committed by Facebook GitHub Bot
parent e970248602
commit dc00e4b120
3 changed files with 34 additions and 6 deletions

View File

@ -16,14 +16,15 @@
* Signature: (JJ)J * Signature: (JJ)J
*/ */
jlong Java_org_rocksdb_WriteBufferManager_newWriteBufferManager( jlong Java_org_rocksdb_WriteBufferManager_newWriteBufferManager(
JNIEnv* /*env*/, jclass /*jclazz*/, jlong jbuffer_size, jlong jcache_handle) { JNIEnv* /*env*/, jclass /*jclazz*/, jlong jbuffer_size, jlong jcache_handle,
jboolean allow_stall) {
auto* cache_ptr = auto* cache_ptr =
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Cache>*>( reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Cache>*>(
jcache_handle); jcache_handle);
auto* write_buffer_manager = auto* write_buffer_manager =
new std::shared_ptr<ROCKSDB_NAMESPACE::WriteBufferManager>( new std::shared_ptr<ROCKSDB_NAMESPACE::WriteBufferManager>(
std::make_shared<ROCKSDB_NAMESPACE::WriteBufferManager>(jbuffer_size, std::make_shared<ROCKSDB_NAMESPACE::WriteBufferManager>(
*cache_ptr)); jbuffer_size, *cache_ptr, allow_stall));
return reinterpret_cast<jlong>(write_buffer_manager); return reinterpret_cast<jlong>(write_buffer_manager);
} }

View File

@ -22,12 +22,29 @@ public class WriteBufferManager extends RocksObject {
* *
* @param bufferSizeBytes buffer size(in bytes) to use for native write_buffer_manager * @param bufferSizeBytes buffer size(in bytes) to use for native write_buffer_manager
* @param cache cache whose memory should be bounded by this write buffer manager * @param cache cache whose memory should be bounded by this write buffer manager
* @param allowStall if set true, it will enable stalling of writes when memory_usage() exceeds
* buffer_size.
* It will wait for flush to complete and memory usage to drop down.
*/ */
public WriteBufferManager(final long bufferSizeBytes, final Cache cache){ public WriteBufferManager(
super(newWriteBufferManager(bufferSizeBytes, cache.nativeHandle_)); final long bufferSizeBytes, final Cache cache, final boolean allowStall) {
super(newWriteBufferManager(bufferSizeBytes, cache.nativeHandle_, allowStall));
this.allowStall_ = allowStall;
} }
private native static long newWriteBufferManager(final long bufferSizeBytes, final long cacheHandle); public WriteBufferManager(final long bufferSizeBytes, final Cache cache){
this(bufferSizeBytes, cache, false);
}
public boolean allowStall() {
return allowStall_;
}
private native static long newWriteBufferManager(
final long bufferSizeBytes, final long cacheHandle, final boolean allowStall);
@Override @Override
protected native void disposeInternal(final long handle); protected native void disposeInternal(final long handle);
private boolean allowStall_;
} }

View File

@ -686,6 +686,16 @@ public class OptionsTest {
} }
} }
@Test
public void setWriteBufferManagerWithAllowStall() throws RocksDBException {
try (final Options opt = new Options(); final Cache cache = new LRUCache(1 * 1024 * 1024);
final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache, true)) {
opt.setWriteBufferManager(writeBufferManager);
assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager);
assertThat(opt.writeBufferManager().allowStall()).isEqualTo(true);
}
}
@Test @Test
public void accessHintOnCompactionStart() { public void accessHintOnCompactionStart() {
try (final Options opt = new Options()) { try (final Options opt = new Options()) {