| 92 | google::protobuf::Closure* done); |
| 93 | |
| 94 | Table* OpenTableWithCache(const std::string& tablename, ErrorCode* err) { |
| 95 | MutexLock l(&mutex_); |
| 96 | std::map<std::string, tera::Table*>::iterator it = tables_.find(tablename); |
| 97 | if (it == tables_.end()) { |
| 98 | mutex_.Unlock(); |
| 99 | Table* table = client_->OpenTable(tablename, err); |
| 100 | mutex_.Lock(); |
| 101 | if (table == NULL) { |
| 102 | VLOG(20) << "[OpenTableWithCache] open table failed:" << tablename << " for " |
| 103 | << err->GetReason(); |
| 104 | return NULL; |
| 105 | } |
| 106 | VLOG(25) << "[OpenTableWithCache] open table done:" << tablename; |
| 107 | tables_[tablename] = table; |
| 108 | return table; |
| 109 | } else { |
| 110 | VLOG(25) << "[OpenTableWithCache] open table(cached):" << tablename; |
| 111 | return it->second; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | private: |
| 116 | mutable Mutex mutex_; |