mirror of https://gitee.com/bigwinds/arangodb
use unique_ptrs for QueryRegistry
This commit is contained in:
parent
91756ef9dd
commit
2bfec8ecee
|
@ -82,7 +82,7 @@ void QueryRegistry::insert(QueryId id, Query* query, double ttl, bool isPrepared
|
|||
auto m = _queries.find(vocbase.name());
|
||||
if (m == _queries.end()) {
|
||||
m = _queries.emplace(vocbase.name(),
|
||||
std::unordered_map<QueryId, QueryInfo*>()).first;
|
||||
std::unordered_map<QueryId, std::unique_ptr<QueryInfo>>()).first;
|
||||
|
||||
TRI_ASSERT(_queries.find(vocbase.name()) != _queries.end());
|
||||
}
|
||||
|
@ -94,8 +94,7 @@ void QueryRegistry::insert(QueryId id, Query* query, double ttl, bool isPrepared
|
|||
TRI_ERROR_INTERNAL, "query with given vocbase and id already there");
|
||||
}
|
||||
|
||||
m->second.emplace(id, p.get());
|
||||
p.release();
|
||||
m->second.emplace(id, std::move(p));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +116,7 @@ Query* QueryRegistry::open(TRI_vocbase_t* vocbase, QueryId id) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
QueryInfo* qi = q->second;
|
||||
std::unique_ptr<QueryInfo>& qi = q->second;
|
||||
if (qi->_isOpen) {
|
||||
LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "Query with id " << id << " is already in open";
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(
|
||||
|
@ -151,7 +150,7 @@ void QueryRegistry::close(TRI_vocbase_t* vocbase, QueryId id, double ttl) {
|
|||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||
"query with given vocbase and id not found");
|
||||
}
|
||||
QueryInfo* qi = q->second;
|
||||
std::unique_ptr<QueryInfo>& qi = q->second;
|
||||
if (!qi->_isOpen) {
|
||||
LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "query id " << id << " was not open.";
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(
|
||||
|
@ -198,10 +197,9 @@ void QueryRegistry::destroy(std::string const& vocbase, QueryId id,
|
|||
|
||||
// move query into our unique ptr, so we can process it outside
|
||||
// of the lock
|
||||
queryInfo.reset(q->second);
|
||||
queryInfo = std::move(q->second);
|
||||
|
||||
// remove query from the table of running queries
|
||||
q->second = nullptr;
|
||||
m->second.erase(q);
|
||||
}
|
||||
|
||||
|
@ -239,11 +237,11 @@ void QueryRegistry::expireQueries() {
|
|||
WRITE_LOCKER(writeLocker, _lock);
|
||||
for (auto& x : _queries) {
|
||||
// x.first is a TRI_vocbase_t* and
|
||||
// x.second is a std::unordered_map<QueryId, QueryInfo*>
|
||||
// x.second is a std::unordered_map<QueryId, std::unique_ptr<QueryInfo>>
|
||||
for (auto& y : x.second) {
|
||||
// y.first is a QueryId and
|
||||
// y.second is a QueryInfo*
|
||||
QueryInfo*& qi = y.second;
|
||||
// y.second is an std::unique_ptr<QueryInfo>
|
||||
std::unique_ptr<QueryInfo> const& qi = y.second;
|
||||
if (!qi->_isOpen && now > qi->_expires) {
|
||||
toDelete.emplace_back(x.first, y.first);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue