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

Method MatchTermOffset

src/nameserver/name_server_impl.cc:6778–6829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6776}
6777
6778int NameServerImpl::MatchTermOffset(const std::string& name, const std::string& db, uint32_t pid, bool has_table,
6779 uint64_t term, uint64_t offset) {
6780 if (!has_table && offset == 0) {
6781 PDLOG(INFO, "has not table, offset is zero. name[%s] pid[%u]", name.c_str(), pid);
6782 return 1;
6783 }
6784 std::map<uint64_t, uint64_t> term_map;
6785 {
6786 std::lock_guard<std::mutex> lock(mu_);
6787 std::shared_ptr<::fedb::nameserver::TableInfo> table_info;
6788 if (!GetTableInfoUnlock(name, db, &table_info)) {
6789 PDLOG(WARNING, "not found table[%s] in table_info map", name.c_str());
6790 return -1;
6791 }
6792 for (int idx = 0; idx < table_info->table_partition_size(); idx++) {
6793 if (table_info->table_partition(idx).pid() != pid) {
6794 continue;
6795 }
6796 for (int term_idx = 0; term_idx < table_info->table_partition(idx).term_offset_size(); term_idx++) {
6797 term_map.insert(std::make_pair(table_info->table_partition(idx).term_offset(term_idx).term(),
6798 table_info->table_partition(idx).term_offset(term_idx).offset()));
6799 }
6800 break;
6801 }
6802 }
6803 auto iter = term_map.find(term);
6804 if (iter == term_map.end()) {
6805 PDLOG(WARNING, "not found term[%lu] in table_info. name[%s] pid[%u]", term, name.c_str(), pid);
6806 return 1;
6807 } else if (iter->second > offset) {
6808 if (term_map.rbegin()->second == offset + 1) {
6809 PDLOG(INFO, "term[%lu] offset[%lu] has matched. name[%s] pid[%u]", term, offset, name.c_str(), pid);
6810 return 0;
6811 }
6812 PDLOG(INFO,
6813 "offset is not matched. name[%s] pid[%u] term[%lu] term start "
6814 "offset[%lu] cur offset[%lu]",
6815 name.c_str(), pid, term, iter->second, offset);
6816 return 1;
6817 }
6818 iter++;
6819 if (iter == term_map.end()) {
6820 PDLOG(INFO, "cur term[%lu] is the last one. name[%s] pid[%u]", term, name.c_str(), pid);
6821 return 0;
6822 }
6823 if (iter->second <= offset) {
6824 PDLOG(INFO, "term[%lu] offset not matched. name[%s] pid[%u] offset[%lu]", term, name.c_str(), pid, offset);
6825 return 1;
6826 }
6827 PDLOG(INFO, "term[%lu] offset has matched. name[%s] pid[%u] offset[%lu]", term, name.c_str(), pid, offset);
6828 return 0;
6829}
6830
6831void NameServerImpl::WrapTaskFun(const boost::function<bool()>& fun,
6832 std::shared_ptr<::fedb::api::TaskInfo> task_info) {

Callers

nothing calls this directly

Calls 1

insertMethod · 0.80

Tested by

no test coverage detected