| 861 | } |
| 862 | |
| 863 | Status VersionSet::Recover(bool* save_manifest) { |
| 864 | struct LogReporter : public log::Reader::Reporter { |
| 865 | Status* status; |
| 866 | void Corruption(size_t bytes, const Status& s) override { |
| 867 | if (this->status->ok()) *this->status = s; |
| 868 | } |
| 869 | }; |
| 870 | |
| 871 | // Read "CURRENT" file, which contains a pointer to the current manifest file |
| 872 | std::string current; |
| 873 | Status s = ReadFileToString(env_, CurrentFileName(dbname_), ¤t); |
| 874 | if (!s.ok()) { |
| 875 | return s; |
| 876 | } |
| 877 | if (current.empty() || current[current.size() - 1] != '\n') { |
| 878 | return Status::Corruption("CURRENT file does not end with newline"); |
| 879 | } |
| 880 | current.resize(current.size() - 1); |
| 881 | |
| 882 | std::string dscname = dbname_ + "/" + current; |
| 883 | SequentialFile* file; |
| 884 | s = env_->NewSequentialFile(dscname, &file); |
| 885 | if (!s.ok()) { |
| 886 | if (s.IsNotFound()) { |
| 887 | return Status::Corruption("CURRENT points to a non-existent file", |
| 888 | s.ToString()); |
| 889 | } |
| 890 | return s; |
| 891 | } |
| 892 | |
| 893 | bool have_log_number = false; |
| 894 | bool have_prev_log_number = false; |
| 895 | bool have_next_file = false; |
| 896 | bool have_last_sequence = false; |
| 897 | uint64_t next_file = 0; |
| 898 | uint64_t last_sequence = 0; |
| 899 | uint64_t log_number = 0; |
| 900 | uint64_t prev_log_number = 0; |
| 901 | Builder builder(this, current_); |
| 902 | |
| 903 | { |
| 904 | LogReporter reporter; |
| 905 | reporter.status = &s; |
| 906 | log::Reader reader(file, &reporter, true /*checksum*/, |
| 907 | 0 /*initial_offset*/); |
| 908 | Slice record; |
| 909 | std::string scratch; |
| 910 | while (reader.ReadRecord(&record, &scratch) && s.ok()) { |
| 911 | VersionEdit edit; |
| 912 | s = edit.DecodeFrom(record); |
| 913 | if (s.ok()) { |
| 914 | if (edit.has_comparator_ && |
| 915 | edit.comparator_ != icmp_.user_comparator()->Name()) { |
| 916 | s = Status::InvalidArgument( |
| 917 | edit.comparator_ + " does not match existing comparator ", |
| 918 | icmp_.user_comparator()->Name()); |
| 919 | } |
| 920 | } |
nothing calls this directly
no test coverage detected