MCPcopy Create free account
hub / github.com/baidu/tera / LoadMetaTableFromFile

Method LoadMetaTableFromFile

src/master/master_impl.cc:654–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654bool MasterImpl::LoadMetaTableFromFile(const std::string &filename, StatusCode *ret_status) {
655 tablet_manager_->ClearTableList();
656 std::ifstream ifs(filename.c_str(), std::ofstream::binary);
657 if (!ifs.is_open()) {
658 LOG(ERROR) << "fail to open file " << filename << " for read";
659 SetStatusCode(kIOError, ret_status);
660 return false;
661 }
662
663 uint64_t count = 0;
664 std::string key, value;
665 while (ReadFromStream(ifs, &key, &value)) {
666 if (key.empty()) {
667 return true;
668 }
669
670 char first_key_char = key[0];
671 if (first_key_char == '~') {
672 user_manager_->LoadUserMeta(key, value);
673 } else if (first_key_char == '|') {
674 // user&passwd&role&permission
675 } else if (first_key_char == '@') {
676 tablet_manager_->LoadTableMeta(key, value);
677 } else if (first_key_char > '@') {
678 tablet_manager_->LoadTabletMeta(key, value);
679 } else {
680 continue;
681 }
682
683 count++;
684 }
685 tablet_manager_->ClearTableList();
686 SetStatusCode(kIOError, ret_status);
687 LOG(ERROR) << "fail to load meta table: " << StatusCodeToString(kIOError);
688 return false;
689}
690
691bool MasterImpl::ReadFromStream(std::ifstream &ifs, std::string *key, std::string *value) {
692 uint32_t key_size = 0, value_size = 0;

Callers

nothing calls this directly

Calls 7

StatusCodeToStringFunction · 0.85
ClearTableListMethod · 0.80
LoadUserMetaMethod · 0.80
LoadTableMetaMethod · 0.80
LoadTabletMetaMethod · 0.80
SetStatusCodeFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected