| 166 | } |
| 167 | |
| 168 | Status Namespace::Add(const std::string& ns, const std::string& token) { |
| 169 | { |
| 170 | std::shared_lock lock(tokens_mu_); |
| 171 | // duplicate namespace |
| 172 | for (const auto& iter : tokens_) { |
| 173 | if (iter.second == ns) { |
| 174 | if (iter.first == token) return Status::OK(); |
| 175 | return {Status::NotOK, kErrNamespaceExists}; |
| 176 | } |
| 177 | } |
| 178 | // duplicate token |
| 179 | if (tokens_.find(token) != tokens_.end()) { |
| 180 | return {Status::NotOK, kErrTokenExists}; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // we don't need to lock the mutex here because the Set method will lock it |
| 185 | return Set(ns, token); |
| 186 | } |
| 187 | |
| 188 | Status Namespace::Del(const std::string& ns) { |
| 189 | if (ns == kDefaultNamespace) { |