Skip to content

Commit

Permalink
Merge pull request #437 from lhsoft/sync_conf_log
Browse files Browse the repository at this point in the history
sync log immediately when there is configuration
  • Loading branch information
PFZheng committed Feb 21, 2024
2 parents 080689b + bd2387a commit ae887a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/braft/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ int Segment::append(const LogEntry* entry) {
return 0;
}

int Segment::sync(bool will_sync) {
int Segment::sync(bool will_sync, bool has_conf) {
if (_last_index < _first_index) {
return 0;
}
Expand All @@ -446,7 +446,8 @@ int Segment::sync(bool will_sync) {
return 0;
}
if (FLAGS_raft_sync_policy == RaftSyncPolicy::RAFT_SYNC_BY_BYTES
&& FLAGS_raft_sync_per_bytes > _unsynced_bytes) {
&& FLAGS_raft_sync_per_bytes > _unsynced_bytes
&& !has_conf) {
return 0;
}
_unsynced_bytes = 0;
Expand Down Expand Up @@ -737,6 +738,7 @@ int SegmentLogStorage::append_entries(const std::vector<LogEntry*>& entries, IOM
scoped_refptr<Segment> last_segment = NULL;
int64_t now = 0;
int64_t delta_time_us = 0;
bool has_conf = false;
for (size_t i = 0; i < entries.size(); i++) {
now = butil::cpuwide_time_us();
LogEntry* entry = entries[i];
Expand All @@ -754,6 +756,9 @@ int SegmentLogStorage::append_entries(const std::vector<LogEntry*>& entries, IOM
if (0 != ret) {
return i;
}
if (entry->type == ENTRY_TYPE_CONFIGURATION) {
has_conf = true;
}
if (FLAGS_raft_trace_append_entry_latency && metric) {
delta_time_us = butil::cpuwide_time_us() - now;
metric->append_entry_time_us += delta_time_us;
Expand All @@ -763,7 +768,7 @@ int SegmentLogStorage::append_entries(const std::vector<LogEntry*>& entries, IOM
last_segment = segment;
}
now = butil::cpuwide_time_us();
last_segment->sync(_enable_sync);
last_segment->sync(_enable_sync, has_conf);
if (FLAGS_raft_trace_append_entry_latency && metric) {
delta_time_us = butil::cpuwide_time_us() - now;
metric->sync_segment_time_us += delta_time_us;
Expand Down
2 changes: 1 addition & 1 deletion src/braft/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BAIDU_CACHELINE_ALIGNMENT Segment
int close(bool will_sync = true);

// sync open segment
int sync(bool will_sync);
int sync(bool will_sync, bool has_conf = false);

// unlink segment
int unlink();
Expand Down

0 comments on commit ae887a0

Please sign in to comment.