MCPcopy Create free account
hub / github.com/Tencent/phxsql / PraseCommand

Method PraseCommand

phxbinlogsvr/core/repl/replication_slave.cpp:295–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295int ReplicationSlave::PraseCommand(char *buffer, const size_t &size) {
296 if (IsQuerryEnd(buffer, size)) {
297 return 0;
298 }
299
300 vector < pair<char *, uint8_t> > fields;
301
302 char *pos = buffer;
303 const char *end = buffer + size;
304 while (pos < end) {
305 uint8_t len = *(uint8_t *) pos;
306 pos++;
307 if (pos + len > end)
308 break;
309 string get_buffer = string(pos, len);
310 fields.push_back(make_pair(pos, len));
311 pos += len;
312 }
313
314 for (size_t i = 0; i < fields.size(); ++i) {
315 LogVerbose("%s get field len %d value %s", __func__, fields[i].second,
316 string(fields[i].first, fields[i].second).c_str());
317 if (i == 1) {
318 string old_value;
319 if (ReWriteCommand(fields[i - 1].first, fields[i - 1].second, fields[i].first, fields[i].second,
320 "server_id", &old_value)) {
321 uint32_t my_svrid = ctx_->GetOption()->GetBinLogSvrConfig()->GetEngineSvrID();
322
323 uint32_t pkg_svrid = 0;
324 for (uint8_t j = 0; j < old_value.size(); ++j) {
325 pkg_svrid = pkg_svrid * 10 + old_value[j] - '0';
326 }
327 if (pkg_svrid != my_svrid) {
328 ColorLogWarning("svr id conflit, mysql svr %d, agent svr id %d", pkg_svrid, my_svrid);
329 return SVR_ID_CONFIT;
330 }
331
332 string new_value = string(fields[i].first, fields[i].second);
333 LogVerbose("%s old value %s new value %s", __func__, old_value.c_str(), new_value.c_str());
334 } else
335 ReWriteCommand(fields[i - 1].first, fields[i - 1].second, fields[i].first, fields[i].second,
336 "server_uuid", &old_value);
337 }
338 }
339
340 return 0;
341}
342
343int ReplicationSlave::DealWithEvent(vector<string> &send_buffer) {
344 string recv_buff;

Callers

nothing calls this directly

Calls 6

LogVerboseFunction · 0.85
ReWriteCommandFunction · 0.85
ColorLogWarningFunction · 0.85
GetEngineSvrIDMethod · 0.80
GetBinLogSvrConfigMethod · 0.80
GetOptionMethod · 0.45

Tested by

no test coverage detected