1
0
Fork 0

use unique_ptrs for QueryRegistry

This commit is contained in:
jsteemann 2018-07-26 11:54:38 +02:00
parent 91756ef9dd
commit 2bfec8ecee
1 changed files with 8 additions and 10 deletions

View File

@ -82,7 +82,7 @@ void QueryRegistry::insert(QueryId id, Query* query, double ttl, bool isPrepared
auto m = _queries.find(vocbase.name()); auto m = _queries.find(vocbase.name());
if (m == _queries.end()) { if (m == _queries.end()) {
m = _queries.emplace(vocbase.name(), 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()); 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"); TRI_ERROR_INTERNAL, "query with given vocbase and id already there");
} }
m->second.emplace(id, p.get()); m->second.emplace(id, std::move(p));
p.release();
} }
} }
@ -117,7 +116,7 @@ Query* QueryRegistry::open(TRI_vocbase_t* vocbase, QueryId id) {
return nullptr; return nullptr;
} }
QueryInfo* qi = q->second; std::unique_ptr<QueryInfo>& qi = q->second;
if (qi->_isOpen) { if (qi->_isOpen) {
LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "Query with id " << id << " is already in open"; LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "Query with id " << id << " is already in open";
THROW_ARANGO_EXCEPTION_MESSAGE( 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, THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"query with given vocbase and id not found"); "query with given vocbase and id not found");
} }
QueryInfo* qi = q->second; std::unique_ptr<QueryInfo>& qi = q->second;
if (!qi->_isOpen) { if (!qi->_isOpen) {
LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "query id " << id << " was not open."; LOG_TOPIC(DEBUG, arangodb::Logger::AQL) << "query id " << id << " was not open.";
THROW_ARANGO_EXCEPTION_MESSAGE( 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 // move query into our unique ptr, so we can process it outside
// of the lock // of the lock
queryInfo.reset(q->second); queryInfo = std::move(q->second);
// remove query from the table of running queries // remove query from the table of running queries
q->second = nullptr;
m->second.erase(q); m->second.erase(q);
} }
@ -239,11 +237,11 @@ void QueryRegistry::expireQueries() {
WRITE_LOCKER(writeLocker, _lock); WRITE_LOCKER(writeLocker, _lock);
for (auto& x : _queries) { for (auto& x : _queries) {
// x.first is a TRI_vocbase_t* and // 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) { for (auto& y : x.second) {
// y.first is a QueryId and // y.first is a QueryId and
// y.second is a QueryInfo* // y.second is an std::unique_ptr<QueryInfo>
QueryInfo*& qi = y.second; std::unique_ptr<QueryInfo> const& qi = y.second;
if (!qi->_isOpen && now > qi->_expires) { if (!qi->_isOpen && now > qi->_expires) {
toDelete.emplace_back(x.first, y.first); toDelete.emplace_back(x.first, y.first);
} else { } else {