| 1690 | } |
| 1691 | |
| 1692 | bool TabletManager::DumpMetaTableToFile(const std::string& filename, StatusCode* status) { |
| 1693 | std::ofstream ofs(filename.c_str(), std::ofstream::binary | std::ofstream::trunc); |
| 1694 | if (!ofs.is_open()) { |
| 1695 | LOG(WARNING) << "fail to open file " << filename << " for write"; |
| 1696 | SetStatusCode(kIOError, status); |
| 1697 | return false; |
| 1698 | } |
| 1699 | |
| 1700 | // get all table and tablet meta |
| 1701 | std::vector<TablePtr> table_list; |
| 1702 | std::vector<TabletPtr> tablet_list; |
| 1703 | ShowTable(&table_list, &tablet_list); |
| 1704 | |
| 1705 | // dump table meta |
| 1706 | for (size_t i = 0; i < table_list.size(); i++) { |
| 1707 | TablePtr table = table_list[i]; |
| 1708 | std::string key, value; |
| 1709 | table->ToMetaTableKeyValue(&key, &value); |
| 1710 | WriteToStream(ofs, key, value); |
| 1711 | } |
| 1712 | |
| 1713 | // dump tablet meta |
| 1714 | for (size_t i = 0; i < tablet_list.size(); i++) { |
| 1715 | TabletPtr tablet = tablet_list[i]; |
| 1716 | std::string key, value; |
| 1717 | tablet->ToMetaTableKeyValue(&key, &value); |
| 1718 | WriteToStream(ofs, key, value); |
| 1719 | } |
| 1720 | |
| 1721 | if (ofs.fail()) { |
| 1722 | LOG(WARNING) << "fail to write to file " << filename; |
| 1723 | SetStatusCode(kIOError, status); |
| 1724 | return false; |
| 1725 | } |
| 1726 | ofs.close(); |
| 1727 | return true; |
| 1728 | } |
| 1729 | |
| 1730 | void TabletManager::LoadTableMeta(const std::string& key, const std::string& value) { |
| 1731 | TableMeta meta; |
no test coverage detected