mirror of https://github.com/ledisdb/ledisdb.git
add sync log config
This commit is contained in:
parent
761431cf5b
commit
848fbf34ad
|
@ -37,10 +37,11 @@ type LMDBConfig struct {
|
|||
|
||||
type ReplicationConfig struct {
|
||||
Path string `toml:"path"`
|
||||
ExpiredLogDays int `toml:"expired_log_days"`
|
||||
Sync bool `toml:"sync"`
|
||||
WaitSyncTime int `toml:"wait_sync_time"`
|
||||
WaitMaxSlaveAcks int `toml:"wait_max_slave_acks"`
|
||||
ExpiredLogDays int `toml:"expired_log_days"`
|
||||
SyncLog int `toml:"sync_log"`
|
||||
Compression bool `toml:"compression"`
|
||||
}
|
||||
|
||||
|
|
|
@ -50,9 +50,6 @@ nosync = true
|
|||
# if not set, use data_dir/rpl
|
||||
path = ""
|
||||
|
||||
# Expire write ahead logs after the given days
|
||||
expired_log_days = 7
|
||||
|
||||
# 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.
|
||||
sync = true
|
||||
|
@ -65,5 +62,14 @@ wait_sync_time = 1
|
|||
# If 0, wait (n + 1) / 2 acks.
|
||||
wait_max_slave_acks = 2
|
||||
|
||||
# Expire write ahead logs after the given days
|
||||
expired_log_days = 7
|
||||
|
||||
# Sync log to disk if possible
|
||||
# 0: no sync
|
||||
# 1: sync every second
|
||||
# 2: sync every commit
|
||||
sync_log = 0
|
||||
|
||||
# Compress the log or not
|
||||
compression = true
|
||||
|
|
|
@ -50,9 +50,6 @@ nosync = true
|
|||
# if not set, use data_dir/rpl
|
||||
path = ""
|
||||
|
||||
# Expire write ahead logs after the given days
|
||||
expired_log_days = 7
|
||||
|
||||
# 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.
|
||||
sync = true
|
||||
|
@ -65,5 +62,14 @@ wait_sync_time = 1
|
|||
# If 0, wait (n + 1) / 2 acks.
|
||||
wait_max_slave_acks = 2
|
||||
|
||||
# Expire write ahead logs after the given days
|
||||
expired_log_days = 7
|
||||
|
||||
# Sync log to disk if possible
|
||||
# 0: no sync
|
||||
# 1: sync every second
|
||||
# 2: sync every commit
|
||||
sync_log = 0
|
||||
|
||||
# Compress the log or not
|
||||
compression = true
|
||||
|
|
|
@ -21,6 +21,8 @@ type GoLevelDBStore struct {
|
|||
|
||||
first uint64
|
||||
last uint64
|
||||
|
||||
lastCommit time.Time
|
||||
}
|
||||
|
||||
func (s *GoLevelDBStore) FirstID() (uint64, error) {
|
||||
|
@ -132,7 +134,17 @@ func (s *GoLevelDBStore) StoreLogs(logs []*Log) error {
|
|||
w.Put(key, buf.Bytes())
|
||||
}
|
||||
|
||||
if err := w.Commit(); err != nil {
|
||||
n := time.Now()
|
||||
if s.cfg.Replication.SyncLog == 2 ||
|
||||
(s.cfg.Replication.SyncLog == 1 && n.Sub(s.lastCommit) > time.Second) {
|
||||
err = w.SyncCommit()
|
||||
} else {
|
||||
err = w.Commit()
|
||||
}
|
||||
|
||||
s.lastCommit = n
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue