Skip to content

Commit 0103b44

Browse files
author
Ankit Gupta
committed
Merge branch 'master' of ssh://github.com/ankgup87/rocksdb
2 parents 1dfb7bb + 7a1bd05 commit 0103b44

10 files changed

+144
-3
lines changed

build_tools/build_detect_platform

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ PLATFORM_CXXFLAGS="-std=c++11"
4646
COMMON_FLAGS="-DROCKSDB_PLATFORM_POSIX"
4747

4848
# Default to fbcode gcc on internal fb machines
49-
if [ -d /mnt/gvfs/third-party -a -z "$CXX" ]; then
49+
if [ -z "$ROCKSDB_NO_FBCODE" -a -d /mnt/gvfs/third-party ]; then
5050
FBCODE_BUILD="true"
5151
if [ -z "$USE_CLANG" ]; then
5252
CENTOS_VERSION=`rpm -q --qf "%{VERSION}" \

java/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.RocksIterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.BlockBasedTableConfig org.rocksdb.ReadOptions org.rocksdb.Filter org.rocksdb.BloomFilter org.rocksdb.RestoreOptions org.rocksdb.RestoreBackupableDB org.rocksdb.RocksEnv
1+
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.RocksIterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.BlockBasedTableConfig org.rocksdb.ReadOptions org.rocksdb.Filter org.rocksdb.BloomFilter org.rocksdb.RestoreOptions org.rocksdb.RestoreBackupableDB org.rocksdb.RocksEnv org.rocksdb.GenericRateLimiterConfig
22

33
NATIVE_INCLUDE = ./include
44
ROCKSDB_JAR = rocksdbjni.jar

java/RocksDBSample.java

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public static void main(String[] args) {
7575
// Plain-Table requires mmap read
7676
options.setAllowMmapReads(true);
7777
assert(options.tableFactoryName().equals("PlainTable"));
78+
79+
options.setRateLimiterConfig(new GenericRateLimiterConfig(10000000,
80+
10000, 10));
81+
options.setRateLimiterConfig(new GenericRateLimiterConfig(10000000));
7882

7983
BlockBasedTableConfig table_options = new BlockBasedTableConfig();
8084
table_options.setBlockCacheSize(64 * SizeUnit.KB)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
package org.rocksdb;
6+
7+
/**
8+
* Config for rate limiter, which is used to control write rate of flush and
9+
* compaction.
10+
*/
11+
public class GenericRateLimiterConfig extends RateLimiterConfig {
12+
private static final long DEFAULT_REFILL_PERIOD_MICROS = (100 * 1000);
13+
private static final int DEFAULT_FAIRNESS = 10;
14+
15+
public GenericRateLimiterConfig(long rateBytesPerSecond,
16+
long refillPeriodMicros, int fairness) {
17+
rateBytesPerSecond_ = rateBytesPerSecond;
18+
refillPeriodMicros_ = refillPeriodMicros;
19+
fairness_ = fairness;
20+
}
21+
22+
public GenericRateLimiterConfig(long rateBytesPerSecond) {
23+
this(rateBytesPerSecond, DEFAULT_REFILL_PERIOD_MICROS, DEFAULT_FAIRNESS);
24+
}
25+
26+
@Override protected long newRateLimiterHandle() {
27+
return newRateLimiterHandle(rateBytesPerSecond_, refillPeriodMicros_,
28+
fairness_);
29+
}
30+
31+
private native long newRateLimiterHandle(long rateBytesPerSecond,
32+
long refillPeriodMicros, int fairness);
33+
private final long rateBytesPerSecond_;
34+
private final long refillPeriodMicros_;
35+
private final int fairness_;
36+
}

java/org/rocksdb/Options.java

+15
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,19 @@ public Options setMemTableConfig(MemTableConfig config) {
11041104
setMemTableFactory(nativeHandle_, config.newMemTableFactoryHandle());
11051105
return this;
11061106
}
1107+
1108+
/**
1109+
* Use to control write rate of flush and compaction. Flush has higher
1110+
* priority than compaction. Rate limiting is disabled if nullptr.
1111+
* Default: nullptr
1112+
*
1113+
* @param config rate limiter config.
1114+
* @return the instance of the current Options.
1115+
*/
1116+
public Options setRateLimiterConfig(RateLimiterConfig config) {
1117+
setRateLimiter(nativeHandle_, config.newRateLimiterHandle());
1118+
return this;
1119+
}
11071120

11081121
/**
11091122
* Returns the name of the current mem table representation.
@@ -2192,6 +2205,8 @@ private native void setMaxBackgroundCompactions(
21922205
private native long statisticsPtr(long optHandle);
21932206

21942207
private native void setMemTableFactory(long handle, long factoryHandle);
2208+
private native void setRateLimiter(long handle,
2209+
long rateLimiterHandle);
21952210
private native String memTableFactoryName(long handle);
21962211

21972212
private native void setTableFactory(long handle, long factoryHandle);
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
package org.rocksdb;
6+
7+
/**
8+
* Config for rate limiter, which is used to control write rate of flush and
9+
* compaction.
10+
*/
11+
public abstract class RateLimiterConfig {
12+
/**
13+
* This function should only be called by Options.setRateLimiter(),
14+
* which will create a c++ shared-pointer to the c++ RateLimiter
15+
* that is associated with the Java RateLimtierConifg.
16+
*
17+
* @see Options.setRateLimiter()
18+
*/
19+
abstract protected long newRateLimiterHandle();
20+
}

java/rocksjni/options.cc

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "rocksdb/memtablerep.h"
2222
#include "rocksdb/table.h"
2323
#include "rocksdb/slice_transform.h"
24+
#include "rocksdb/rate_limiter.h"
2425

2526
/*
2627
* Class: org_rocksdb_Options
@@ -459,6 +460,17 @@ void Java_org_rocksdb_Options_setMemTableFactory(
459460
reinterpret_cast<rocksdb::MemTableRepFactory*>(jfactory_handle));
460461
}
461462

463+
/*
464+
* Class: org_rocksdb_Options
465+
* Method: setRateLimiter
466+
* Signature: (JJ)V
467+
*/
468+
void Java_org_rocksdb_Options_setRateLimiter(
469+
JNIEnv* env, jobject jobj, jlong jhandle, jlong jrate_limiter_handle) {
470+
reinterpret_cast<rocksdb::Options*>(jhandle)->rate_limiter.reset(
471+
reinterpret_cast<rocksdb::RateLimiter*>(jrate_limiter_handle));
472+
}
473+
462474
/*
463475
* Class: org_rocksdb_Options
464476
* Method: tableCacheNumshardbits

java/rocksjni/ratelimiterjni.cc

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under the BSD-style license found in the
3+
// LICENSE file in the root directory of this source tree. An additional grant
4+
// of patent rights can be found in the PATENTS file in the same directory.
5+
//
6+
// This file implements the "bridge" between Java and C++ for RateLimiter.
7+
8+
#include "rocksjni/portal.h"
9+
#include "include/org_rocksdb_GenericRateLimiterConfig.h"
10+
#include "rocksdb/rate_limiter.h"
11+
12+
/*
13+
* Class: org_rocksdb_GenericRateLimiterConfig
14+
* Method: newRateLimiterHandle
15+
* Signature: (JJI)J
16+
*/
17+
jlong Java_org_rocksdb_GenericRateLimiterConfig_newRateLimiterHandle(
18+
JNIEnv* env, jobject jobj, jlong jrate_bytes_per_second,
19+
jlong jrefill_period_micros, jint jfairness) {
20+
return reinterpret_cast<jlong>(rocksdb::NewGenericRateLimiter(
21+
rocksdb::jlong_to_size_t(jrate_bytes_per_second),
22+
rocksdb::jlong_to_size_t(jrefill_period_micros),
23+
static_cast<int32_t>(jfairness)));
24+
}

util/env_test.cc

+30
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#include <unistd.h>
1818
#endif
1919

20+
#ifdef ROCKSDB_FALLOCATE_PRESENT
21+
#include <errno.h>
22+
#include <fcntl.h>
23+
#endif
24+
2025
#include "rocksdb/env.h"
2126
#include "port/port.h"
2227
#include "util/coding.h"
@@ -478,6 +483,31 @@ TEST(EnvPosixTest, RandomAccessUniqueID) {
478483
#ifdef ROCKSDB_FALLOCATE_PRESENT
479484
TEST(EnvPosixTest, AllocateTest) {
480485
std::string fname = GetOnDiskTestDir() + "/preallocate_testfile";
486+
487+
// Try fallocate in a file to see whether the target file system supports it.
488+
// Skip the test if fallocate is not supported.
489+
std::string fname_test_fallocate =
490+
GetOnDiskTestDir() + "/preallocate_testfile_2";
491+
int fd = -1;
492+
do {
493+
fd = open(fname_test_fallocate.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644);
494+
} while (fd < 0 && errno == EINTR);
495+
ASSERT_GT(fd, 0);
496+
497+
int alloc_status = fallocate(fd, 0, 0, 1);
498+
499+
int err_number = 0;
500+
if (alloc_status != 0) {
501+
err_number = errno;
502+
fprintf(stderr, "Warning: fallocate() fails, %s\n", strerror(err_number));
503+
}
504+
close(fd);
505+
ASSERT_OK(env_->DeleteFile(fname_test_fallocate));
506+
if (alloc_status != 0 && err_number == EOPNOTSUPP) {
507+
// The filesystem containing the file does not support fallocate
508+
return;
509+
}
510+
481511
EnvOptions soptions;
482512
soptions.use_mmap_writes = false;
483513
unique_ptr<WritableFile> wfile;

util/options.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ void ColumnFamilyOptions::Dump(Logger* log) const {
419419
"max_size_amplification_percent: %u",
420420
compaction_options_universal.max_size_amplification_percent);
421421
Log(log,
422-
"Options.compaction_options_universal.compression_size_percent: %u",
422+
"Options.compaction_options_universal.compression_size_percent: %d",
423423
compaction_options_universal.compression_size_percent);
424424
Log(log, "Options.compaction_options_fifo.max_table_files_size: %" PRIu64,
425425
compaction_options_fifo.max_table_files_size);

0 commit comments

Comments
 (0)