| 652 | } |
| 653 | |
| 654 | bool 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 | |
| 691 | bool MasterImpl::ReadFromStream(std::ifstream &ifs, std::string *key, std::string *value) { |
| 692 | uint32_t key_size = 0, value_size = 0; |
nothing calls this directly
no test coverage detected