Skip to content

Commit ae887a0

Browse files
authored
Merge pull request #437 from lhsoft/sync_conf_log
sync log immediately when there is configuration
2 parents 080689b + bd2387a commit ae887a0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/braft/log.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ int Segment::append(const LogEntry* entry) {
436436
return 0;
437437
}
438438

439-
int Segment::sync(bool will_sync) {
439+
int Segment::sync(bool will_sync, bool has_conf) {
440440
if (_last_index < _first_index) {
441441
return 0;
442442
}
@@ -446,7 +446,8 @@ int Segment::sync(bool will_sync) {
446446
return 0;
447447
}
448448
if (FLAGS_raft_sync_policy == RaftSyncPolicy::RAFT_SYNC_BY_BYTES
449-
&& FLAGS_raft_sync_per_bytes > _unsynced_bytes) {
449+
&& FLAGS_raft_sync_per_bytes > _unsynced_bytes
450+
&& !has_conf) {
450451
return 0;
451452
}
452453
_unsynced_bytes = 0;
@@ -737,6 +738,7 @@ int SegmentLogStorage::append_entries(const std::vector<LogEntry*>& entries, IOM
737738
scoped_refptr<Segment> last_segment = NULL;
738739
int64_t now = 0;
739740
int64_t delta_time_us = 0;
741+
bool has_conf = false;
740742
for (size_t i = 0; i < entries.size(); i++) {
741743
now = butil::cpuwide_time_us();
742744
LogEntry* entry = entries[i];
@@ -754,6 +756,9 @@ int SegmentLogStorage::append_entries(const std::vector<LogEntry*>& entries, IOM
754756
if (0 != ret) {
755757
return i;
756758
}
759+
if (entry->type == ENTRY_TYPE_CONFIGURATION) {
760+
has_conf = true;
761+
}
757762
if (FLAGS_raft_trace_append_entry_latency && metric) {
758763
delta_time_us = butil::cpuwide_time_us() - now;
759764
metric->append_entry_time_us += delta_time_us;
@@ -763,7 +768,7 @@ int SegmentLogStorage::append_entries(const std::vector<LogEntry*>& entries, IOM
763768
last_segment = segment;
764769
}
765770
now = butil::cpuwide_time_us();
766-
last_segment->sync(_enable_sync);
771+
last_segment->sync(_enable_sync, has_conf);
767772
if (FLAGS_raft_trace_append_entry_latency && metric) {
768773
delta_time_us = butil::cpuwide_time_us() - now;
769774
metric->sync_segment_time_us += delta_time_us;

src/braft/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class BAIDU_CACHELINE_ALIGNMENT Segment
7070
int close(bool will_sync = true);
7171

7272
// sync open segment
73-
int sync(bool will_sync);
73+
int sync(bool will_sync, bool has_conf = false);
7474

7575
// unlink segment
7676
int unlink();

0 commit comments

Comments
 (0)