MCPcopy Create free account
hub / github.com/baidu/braft / fetch_add

Method fetch_add

example/counter/server.cpp:102–136  ·  view source on GitHub ↗

Impelements Service methods

Source from the content-addressed store, hash-verified

100
101 // Impelements Service methods
102 void fetch_add(const FetchAddRequest* request,
103 CounterResponse* response,
104 google::protobuf::Closure* done) {
105 brpc::ClosureGuard done_guard(done);
106 // Serialize request to the replicated write-ahead-log so that all the
107 // peers in the group receive this request as well.
108 // Notice that _value can't be modified in this routine otherwise it
109 // will be inconsistent with others in this group.
110
111 // Serialize request to IOBuf
112 const int64_t term = _leader_term.load(butil::memory_order_relaxed);
113 if (term < 0) {
114 return redirect(response);
115 }
116 butil::IOBuf log;
117 butil::IOBufAsZeroCopyOutputStream wrapper(&log);
118 if (!request->SerializeToZeroCopyStream(&wrapper)) {
119 LOG(ERROR) << "Fail to serialize request";
120 response->set_success(false);
121 return;
122 }
123 // Apply this log as a braft::Task
124 braft::Task task;
125 task.data = &log;
126 // This callback would be iovoked when the task actually excuted or
127 // fail
128 task.done = new FetchAddClosure(this, request, response,
129 done_guard.release());
130 if (FLAGS_check_term) {
131 // ABA problem can be avoid if expected_term is set
132 task.expected_term = term;
133 }
134 // Now the task is applied to the group, waiting for the result.
135 return _node->apply(task);
136 }
137
138 void get(CounterResponse* response) {
139 // In consideration of consistency. GetRequest to follower should be

Callers 12

senderFunction · 0.45
on_applyMethod · 0.45
fetch_addMethod · 0.45
on_snapshot_loadMethod · 0.45
on_snapshot_saveMethod · 0.45
on_errorMethod · 0.45
set_snapshotMethod · 0.45
clear_bufferred_logsMethod · 0.45
appendMethod · 0.45
append_entriesMethod · 0.45
append_entryMethod · 0.45
append_entryMethod · 0.45

Calls 2

loadMethod · 0.45
applyMethod · 0.45

Tested by 5

on_snapshot_loadMethod · 0.36
on_snapshot_saveMethod · 0.36
on_errorMethod · 0.36
set_snapshotMethod · 0.36
clear_bufferred_logsMethod · 0.36