| 165 | } |
| 166 | |
| 167 | Status PersistentCacheImpl::Open() { |
| 168 | Status status; |
| 169 | |
| 170 | assert(!size_.Get()); |
| 171 | |
| 172 | // Check the validity of the options |
| 173 | status = opt_.ValidateSettings(); |
| 174 | assert(status.ok()); |
| 175 | if (!status.ok()) { |
| 176 | LEVELDB_LOG("Invalid persistent cache options.\n"); |
| 177 | return status; |
| 178 | } |
| 179 | |
| 180 | // Create base directory |
| 181 | status = opt_.env->CreateDir(opt_.path); |
| 182 | if (!status.ok()) { |
| 183 | LEVELDB_LOG("Error creating directory %s. %s.\n", opt_.path.c_str(), status.ToString().c_str()); |
| 184 | return status; |
| 185 | } |
| 186 | |
| 187 | // Create meta directory |
| 188 | status = opt_.env->CreateDir(GetMetaPath()); |
| 189 | assert(status.ok()); |
| 190 | if (!status.ok()) { |
| 191 | LEVELDB_LOG("Error creating directory %s. %s.\n", GetMetaPath().c_str(), |
| 192 | status.ToString().c_str()); |
| 193 | return status; |
| 194 | } |
| 195 | |
| 196 | status = metadata_.Init(&writer_cache_id_, this); |
| 197 | if (!status.ok()) { |
| 198 | LEVELDB_LOG("Init metadata failed, reason: %s.\n", status.ToString().c_str()); |
| 199 | return status; |
| 200 | } |
| 201 | metadata_size_.Set(metadata_.GetDBSize()); |
| 202 | if (opt_.transfer_flash_env_files) { |
| 203 | PullEnvFlashFiles(); |
| 204 | } |
| 205 | // Clean up non-cache file |
| 206 | CleanupCacheFolder(GetCachePath()); |
| 207 | |
| 208 | LEVELDB_LOG("Persistent Cache Init Done, writer_cache_id: %lu\n", writer_cache_id_); |
| 209 | |
| 210 | return Status::OK(); |
| 211 | } |
| 212 | |
| 213 | Status PersistentCacheImpl::Read(const Slice& key, size_t offset, size_t length, Slice* content, |
| 214 | SstDataScratch* scratch) { |
no test coverage detected