mirror of https://github.com/ledisdb/ledisdb.git
Use latest (1.20+) LevelDB (#326)
This commit is contained in:
parent
2ff56553d9
commit
81f50c08aa
|
@ -35,6 +35,7 @@ type LevelDBConfig struct {
|
||||||
WriteBufferSize int `toml:"write_buffer_size"`
|
WriteBufferSize int `toml:"write_buffer_size"`
|
||||||
CacheSize int `toml:"cache_size"`
|
CacheSize int `toml:"cache_size"`
|
||||||
MaxOpenFiles int `toml:"max_open_files"`
|
MaxOpenFiles int `toml:"max_open_files"`
|
||||||
|
MaxFileSize int `toml:"max_file_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RocksDBConfig struct {
|
type RocksDBConfig struct {
|
||||||
|
@ -244,6 +245,7 @@ func (cfg *LevelDBConfig) adjust() {
|
||||||
cfg.BlockSize = getDefault(4*KB, cfg.BlockSize)
|
cfg.BlockSize = getDefault(4*KB, cfg.BlockSize)
|
||||||
cfg.WriteBufferSize = getDefault(4*MB, cfg.WriteBufferSize)
|
cfg.WriteBufferSize = getDefault(4*MB, cfg.WriteBufferSize)
|
||||||
cfg.MaxOpenFiles = getDefault(1024, cfg.MaxOpenFiles)
|
cfg.MaxOpenFiles = getDefault(1024, cfg.MaxOpenFiles)
|
||||||
|
cfg.MaxFileSize = getDefault(32*MB, cfg.MaxFileSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *RocksDBConfig) adjust() {
|
func (cfg *RocksDBConfig) adjust() {
|
||||||
|
|
|
@ -25,7 +25,7 @@ access_log = ""
|
||||||
# Any write operations except flushall and replication will be disabled in slave mode.
|
# Any write operations except flushall and replication will be disabled in slave mode.
|
||||||
slaveof = ""
|
slaveof = ""
|
||||||
|
|
||||||
# Readonly mode, slave server is always readonly even readonly = false
|
# Readonly mode, slave server is always readonly even readonly = false
|
||||||
# for readonly mode, only replication and flushall can write
|
# for readonly mode, only replication and flushall can write
|
||||||
readonly = false
|
readonly = false
|
||||||
|
|
||||||
|
@ -35,16 +35,16 @@ readonly = false
|
||||||
# rocksdb
|
# rocksdb
|
||||||
# goleveldb
|
# goleveldb
|
||||||
# memory
|
# memory
|
||||||
#
|
#
|
||||||
db_name = "leveldb"
|
db_name = "leveldb"
|
||||||
|
|
||||||
# If not set, use data_dir/"db_name"_data
|
# If not set, use data_dir/"db_name"_data
|
||||||
db_path = ""
|
db_path = ""
|
||||||
|
|
||||||
# Sync commit to disk if possible
|
# Sync commit to disk if possible
|
||||||
# 0: no sync
|
# 0: no sync
|
||||||
# 1: sync every second
|
# 1: sync every second
|
||||||
# 2: sync every commit
|
# 2: sync every commit
|
||||||
db_sync_commit = 0
|
db_sync_commit = 0
|
||||||
|
|
||||||
# enable replication or not
|
# enable replication or not
|
||||||
|
@ -55,8 +55,8 @@ use_replication = false
|
||||||
conn_read_buffer_size = 10240
|
conn_read_buffer_size = 10240
|
||||||
conn_write_buffer_size = 10240
|
conn_write_buffer_size = 10240
|
||||||
|
|
||||||
# if connection receives no data after n seconds, it may be dead, close
|
# if connection receives no data after n seconds, it may be dead, close
|
||||||
# 0 to disable and not check
|
# 0 to disable and not check
|
||||||
conn_keepalive_interval = 0
|
conn_keepalive_interval = 0
|
||||||
|
|
||||||
# checking TTL (time to live) data every n seconds
|
# checking TTL (time to live) data every n seconds
|
||||||
|
@ -70,13 +70,14 @@ block_size = 32768
|
||||||
write_buffer_size = 67108864
|
write_buffer_size = 67108864
|
||||||
cache_size = 524288000
|
cache_size = 524288000
|
||||||
max_open_files = 1024
|
max_open_files = 1024
|
||||||
|
max_file_size = 33554432
|
||||||
|
|
||||||
[rocksdb]
|
[rocksdb]
|
||||||
# rocksdb has many many configurations,
|
# rocksdb has many many configurations,
|
||||||
# we only list little now, but may add more later.
|
# we only list little now, but may add more later.
|
||||||
# good luck!
|
# good luck!
|
||||||
|
|
||||||
# 0:no, 1:snappy, 2:zlib, 3:bz2, 4:lz4, 5:lz4hc
|
# 0:no, 1:snappy, 2:zlib, 3:bz2, 4:lz4, 5:lz4hc
|
||||||
compression = 0
|
compression = 0
|
||||||
block_size = 65536
|
block_size = 65536
|
||||||
write_buffer_size = 134217728
|
write_buffer_size = 134217728
|
||||||
|
@ -92,9 +93,9 @@ target_file_size_base = 67108864
|
||||||
target_file_size_multiplier = 1
|
target_file_size_multiplier = 1
|
||||||
max_bytes_for_level_base = 536870912
|
max_bytes_for_level_base = 536870912
|
||||||
max_bytes_for_level_multiplier = 8
|
max_bytes_for_level_multiplier = 8
|
||||||
disable_auto_compactions = false
|
disable_auto_compactions = false
|
||||||
disable_data_sync = false
|
disable_data_sync = false
|
||||||
use_fsync = false
|
use_fsync = false
|
||||||
background_theads = 16
|
background_theads = 16
|
||||||
high_priority_background_threads = 1
|
high_priority_background_threads = 1
|
||||||
max_background_compactions = 15
|
max_background_compactions = 15
|
||||||
|
@ -114,11 +115,11 @@ nosync = true
|
||||||
|
|
||||||
[replication]
|
[replication]
|
||||||
# Path to store replication information(write ahead log, commit log, etc.)
|
# Path to store replication information(write ahead log, commit log, etc.)
|
||||||
# if not set, use data_dir/rpl
|
# if not set, use data_dir/rpl
|
||||||
path = ""
|
path = ""
|
||||||
|
|
||||||
# If sync is true, the new log must be sent to some slaves, and then commit.
|
# If sync is true, the new log must be sent to some slaves, and then commit.
|
||||||
# It will reduce performance but have better high availability.
|
# It will reduce performance but have better high availability.
|
||||||
sync = false
|
sync = false
|
||||||
|
|
||||||
# If sync is true, wait at last wait_sync_time milliseconds for slave syncing this log
|
# If sync is true, wait at last wait_sync_time milliseconds for slave syncing this log
|
||||||
|
@ -146,9 +147,9 @@ max_log_file_num = 0
|
||||||
use_mmap = true
|
use_mmap = true
|
||||||
|
|
||||||
# Sync log to disk if possible
|
# Sync log to disk if possible
|
||||||
# 0: no sync
|
# 0: no sync
|
||||||
# 1: sync every second
|
# 1: sync every second
|
||||||
# 2: sync every commit
|
# 2: sync every commit
|
||||||
sync_log = 0
|
sync_log = 0
|
||||||
|
|
||||||
# Compress the log or not
|
# Compress the log or not
|
||||||
|
|
|
@ -128,6 +128,8 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
||||||
|
|
||||||
opts.SetMaxOpenFiles(cfg.MaxOpenFiles)
|
opts.SetMaxOpenFiles(cfg.MaxOpenFiles)
|
||||||
|
|
||||||
|
opts.SetMaxFileSize(cfg.MaxFileSize)
|
||||||
|
|
||||||
db.opts = opts
|
db.opts = opts
|
||||||
|
|
||||||
db.readOpts = NewReadOptions()
|
db.readOpts = NewReadOptions()
|
||||||
|
|
|
@ -69,6 +69,10 @@ func (o *Options) SetMaxOpenFiles(n int) {
|
||||||
C.leveldb_options_set_max_open_files(o.Opt, C.int(n))
|
C.leveldb_options_set_max_open_files(o.Opt, C.int(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Options) SetMaxFileSize(n int) {
|
||||||
|
C.leveldb_options_set_max_file_size(o.Opt, C.size_t(n))
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Options) SetBlockSize(s int) {
|
func (o *Options) SetBlockSize(s int) {
|
||||||
C.leveldb_options_set_block_size(o.Opt, C.size_t(s))
|
C.leveldb_options_set_block_size(o.Opt, C.size_t(s))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ LEVELDB_DIR=/usr/local/leveldb
|
||||||
|
|
||||||
ROOT_DIR=$(pwd)
|
ROOT_DIR=$(pwd)
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
BUILD_DIR=/tmp/build_leveldb
|
BUILD_DIR=/tmp/build_leveldb
|
||||||
|
|
||||||
mkdir -p $BUILD_DIR
|
mkdir -p $BUILD_DIR
|
||||||
|
@ -26,12 +28,14 @@ fi
|
||||||
cd $BUILD_DIR
|
cd $BUILD_DIR
|
||||||
|
|
||||||
if [ ! -f $LEVELDB_DIR/lib/libleveldb.a ]; then
|
if [ ! -f $LEVELDB_DIR/lib/libleveldb.a ]; then
|
||||||
(git clone https://github.com/siddontang/leveldb.git ; \
|
(git clone git@github.com:google/leveldb.git ; \
|
||||||
cd ./leveldb && \
|
cd ./leveldb && \
|
||||||
|
git checkout 47cb9e2a211e1d7157078ba7bab536beb29e56dc && \
|
||||||
|
patch -p0 < $SCRIPT_DIR/leveldb.patch
|
||||||
echo "echo \"PLATFORM_CFLAGS+=-I$SNAPPY_DIR/include\" >> build_config.mk" >> build_detect_platform &&
|
echo "echo \"PLATFORM_CFLAGS+=-I$SNAPPY_DIR/include\" >> build_config.mk" >> build_detect_platform &&
|
||||||
echo "echo \"PLATFORM_CXXFLAGS+=-I$SNAPPY_DIR/include\" >> build_config.mk" >> build_detect_platform &&
|
echo "echo \"PLATFORM_CXXFLAGS+=-I$SNAPPY_DIR/include\" >> build_config.mk" >> build_detect_platform &&
|
||||||
echo "echo \"PLATFORM_LDFLAGS+=-L $SNAPPY_DIR/lib -lsnappy\" >> build_config.mk" >> build_detect_platform &&
|
echo "echo \"PLATFORM_LDFLAGS+=-L $SNAPPY_DIR/lib -lsnappy\" >> build_config.mk" >> build_detect_platform &&
|
||||||
make SNAPPY=1 && \
|
make HAVE_SNAPPY=1 && \
|
||||||
make && \
|
make && \
|
||||||
mkdir -p $LEVELDB_DIR/include/leveldb && \
|
mkdir -p $LEVELDB_DIR/include/leveldb && \
|
||||||
install include/leveldb/*.h $LEVELDB_DIR/include/leveldb && \
|
install include/leveldb/*.h $LEVELDB_DIR/include/leveldb && \
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
diff -Naur ./db/dbformat.h ../leveldb/db/dbformat.h
|
||||||
|
--- ./db/dbformat.h 2017-11-03 18:04:26.000000000 -0400
|
||||||
|
+++ ../leveldb/db/dbformat.h 2017-11-23 13:11:30.167396736 -0500
|
||||||
|
@@ -25,10 +25,10 @@
|
||||||
|
static const int kL0_CompactionTrigger = 4;
|
||||||
|
|
||||||
|
// Soft limit on number of level-0 files. We slow down writes at this point.
|
||||||
|
-static const int kL0_SlowdownWritesTrigger = 8;
|
||||||
|
+static const int kL0_SlowdownWritesTrigger = 16;
|
||||||
|
|
||||||
|
// Maximum number of level-0 files. We stop writes at this point.
|
||||||
|
-static const int kL0_StopWritesTrigger = 12;
|
||||||
|
+static const int kL0_StopWritesTrigger = 64;
|
||||||
|
|
||||||
|
// Maximum level to which a new compacted memtable is pushed if it
|
||||||
|
// does not create overlap. We try to push to level 2 to avoid the
|
||||||
|
diff -Naur ./db/version_set.cc ../leveldb/db/version_set.cc
|
||||||
|
--- ./db/version_set.cc 2017-11-03 18:04:26.000000000 -0400
|
||||||
|
+++ ../leveldb/db/version_set.cc 2017-11-23 13:12:12.700870777 -0500
|
||||||
|
@@ -27,7 +27,7 @@
|
||||||
|
// Maximum bytes of overlaps in grandparent (i.e., level+2) before we
|
||||||
|
// stop building a single file in a level->level+1 compaction.
|
||||||
|
static int64_t MaxGrandParentOverlapBytes(const Options* options) {
|
||||||
|
- return 10 * TargetFileSize(options);
|
||||||
|
+ return 20 * TargetFileSize(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maximum number of bytes in all compacted files. We avoid expanding
|
Loading…
Reference in New Issue