| 1076 | } |
| 1077 | |
| 1078 | Status DataCache::Partition::Load() { |
| 1079 | std::ifstream file; |
| 1080 | file.open(JoinPathSegments(path_, DUMP_FILE_NAME), std::ofstream::binary); |
| 1081 | if (!file) return Status::Expected(Substitute("Failed to open $0", DUMP_FILE_NAME)); |
| 1082 | LOG(INFO) << Substitute("Partition $0 start loading.", index_); |
| 1083 | DumpData dump_data; |
| 1084 | try { |
| 1085 | dump_data.deserialize(file); |
| 1086 | } catch (boost::archive::archive_exception& e) { |
| 1087 | LOG(ERROR) << Substitute("Partition $0 failed to deserialize dump file.", index_) |
| 1088 | << e.what(); |
| 1089 | return Status("Failed to deserialize dump file."); |
| 1090 | } |
| 1091 | file.close(); |
| 1092 | |
| 1093 | Status status = LoadCacheFiles(dump_data); |
| 1094 | if (!status.ok()) { |
| 1095 | cache_files_.clear(); |
| 1096 | return status; |
| 1097 | } |
| 1098 | |
| 1099 | status = LoadMetaCache(dump_data); |
| 1100 | if (!status.ok()) { |
| 1101 | cache_files_.clear(); |
| 1102 | meta_cache_.reset(NewCache(GetCacheEvictionPolicy(FLAGS_data_cache_eviction_policy), |
| 1103 | capacity_, path_)); |
| 1104 | // We have already successfully initialized meta_cache_ once before calling Load(), so |
| 1105 | // there is no reason for it to fail this time. |
| 1106 | ABORT_IF_ERROR(meta_cache_->Init()); |
| 1107 | return status; |
| 1108 | } |
| 1109 | |
| 1110 | LOG(INFO) << Substitute("Partition $0 load successfully.", index_); |
| 1111 | return Status::OK(); |
| 1112 | } |
| 1113 | |
| 1114 | Status DataCache::Partition::DumpCacheFiles(DumpData& dump_data) { |
| 1115 | lock_.DCheckLocked(); |