| 231 | } |
| 232 | |
| 233 | bool MergedSSTableReader::LoadSSTableReader(const std::string &path, ReadMode type) { |
| 234 | SSTableReader *sstable = SSTableReader::Open(path, type); |
| 235 | if (sstable == NULL) { |
| 236 | LOG(ERROR)<< "Failed to open sstable:" << path; |
| 237 | return false; |
| 238 | } |
| 239 | if (sstable->EntryCount() == 0) { |
| 240 | LOG(WARNING)<< "sstable " << path << " is empty."; |
| 241 | delete sstable; |
| 242 | return false; |
| 243 | } |
| 244 | |
| 245 | // now fill it into proper sstable set. |
| 246 | std::string set_id = sstable->GetMetaData(kSSTableSetID); |
| 247 | if (set_id.empty()) { |
| 248 | LOG(WARNING)<< "sstable with empty set id"; |
| 249 | } |
| 250 | std::string policy = sstable->GetMetaData(kShardPolicy); |
| 251 | std::string str_num_shard = sstable->GetMetaData(kShardTotalNum); |
| 252 | std::string str_shard_id = sstable->GetMetaData(kShardID); |
| 253 | VLOG(2) << "set_id: " << set_id << ", policy: " << policy << ", num_shard: " |
| 254 | << str_num_shard << ", shard_id: " << str_shard_id; |
| 255 | |
| 256 | int num_shard = 0; |
| 257 | if (!StringToNumber(str_num_shard, &num_shard)) { |
| 258 | if (!set_id.empty()) { |
| 259 | LOG(WARNING)<< "bad num shard: " << str_num_shard << ", path: " |
| 260 | << sstable->GetPath(); |
| 261 | delete sstable; |
| 262 | return false; |
| 263 | } |
| 264 | } |
| 265 | int shard_id = -1; |
| 266 | if (!StringToNumber(str_shard_id, &shard_id)) { |
| 267 | if (!set_id.empty()) { |
| 268 | LOG(WARNING)<< "bad shard id: " << str_shard_id; |
| 269 | delete sstable; |
| 270 | return false; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | std::map<std::string, SSTableReaderSet*>::iterator it = impl_->sets_.find(set_id); |
| 275 | if (it == impl_->sets_.end()) { |
| 276 | if (set_id.empty()) { |
| 277 | // Ignore sharding policy for sstable files that has no set id |
| 278 | if (FLAGS_ignore_sstable_setid) { |
| 279 | impl_->sets_[""] = new SSTableReaderSet("", policy, num_shard); |
| 280 | } else { |
| 281 | impl_->sets_[""] = new SSTableReaderSet("", "", 0); |
| 282 | } |
| 283 | } else { |
| 284 | impl_->sets_[set_id] = new SSTableReaderSet(set_id, policy, num_shard); |
| 285 | } |
| 286 | it = impl_->sets_.find(set_id); |
| 287 | } |
| 288 | |
| 289 | impl_->tables_.push_back(sstable); |
| 290 | return it->second->AddSSTableReader(sstable, set_id, policy, num_shard, shard_id); |
nothing calls this directly
no test coverage detected