MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / PutData

Function PutData

src/cmd/fedb.cc:293–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291#endif
292
293int PutData(
294 uint32_t tid,
295 const std::map<uint32_t, std::vector<std::pair<std::string, uint32_t>>>&
296 dimensions,
297 const std::vector<uint64_t>& ts_dimensions, uint64_t ts,
298 const std::string& value,
299 const google::protobuf::RepeatedPtrField<
300 ::fedb::nameserver::TablePartition>& table_partition,
301 uint32_t format_version) {
302 std::map<std::string, std::shared_ptr<::fedb::client::TabletClient>>
303 clients;
304 for (auto iter = dimensions.begin(); iter != dimensions.end(); iter++) {
305 uint32_t pid = iter->first;
306 std::string endpoint;
307 for (const auto& cur_table_partition : table_partition) {
308 if (cur_table_partition.pid() != pid) {
309 continue;
310 }
311 for (int inner_idx = 0;
312 inner_idx < cur_table_partition.partition_meta_size();
313 inner_idx++) {
314 if (cur_table_partition.partition_meta(inner_idx).is_leader() &&
315 cur_table_partition.partition_meta(inner_idx).is_alive()) {
316 endpoint = cur_table_partition.partition_meta(inner_idx)
317 .endpoint();
318 break;
319 }
320 }
321 break;
322 }
323 if (endpoint.empty()) {
324 printf("put error. cannot find healthy endpoint. pid is %u\n", pid);
325 return -1;
326 }
327 if (clients.find(endpoint) == clients.end()) {
328 std::string real_endpoint;
329 if (!real_ep_map.empty()) {
330 auto rit = real_ep_map.find(endpoint);
331 if (rit != real_ep_map.end()) {
332 real_endpoint = rit->second;
333 }
334 }
335 clients.insert(std::make_pair(endpoint,
336 std::make_shared<::fedb::client::TabletClient>(endpoint, real_endpoint)));
337 if (clients[endpoint]->Init() < 0) {
338 printf("tablet client init failed, endpoint is %s\n",
339 endpoint.c_str());
340 return -1;
341 }
342 }
343 if (ts_dimensions.empty()) {
344 if (!clients[endpoint]->Put(tid, pid, ts, value, iter->second,
345 format_version)) {
346 printf("put failed. tid %u pid %u endpoint %s ts %lu \n", tid,
347 pid, endpoint.c_str(), ts);
348 return -1;
349 }
350 } else {

Callers 1

PutSchemaDataFunction · 0.85

Calls 4

insertMethod · 0.80
emptyMethod · 0.45
InitMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected