1
0
Fork 0

Implement expireQueries in QueryRegistry.

This commit is contained in:
Max Neunhoeffer 2014-09-24 16:26:31 +02:00
parent 784a299ab8
commit afc54a07a9
1 changed files with 24 additions and 2 deletions

View File

@ -134,6 +134,7 @@ void QueryRegistry::close (TRI_vocbase_t* vocbase, QueryId id, double ttl) {
triagens::arango::TransactionBase::increaseNumbers(1, 1);
qi->_isOpen = false;
qi->_expires = TRI_microtime() + qi->_timeToLive;
}
////////////////////////////////////////////////////////////////////////////////
@ -173,8 +174,29 @@ void QueryRegistry::destroy (TRI_vocbase_t* vocbase, QueryId id) {
/// @brief expireQueries
////////////////////////////////////////////////////////////////////////////////
void expireQueries () {
// TODO
void QueryRegistry::expireQueries () {
WRITE_LOCKER(_lock);
std::vector<std::pair<TRI_vocbase_t*, QueryId>> toDelete;
double now = TRI_microtime();
for (auto& x : _queries) {
// x.first is a TRI_vocbase_t* and
// x.second is a std::unordered_map<QueryId, QueryInfo*>
for (auto& y : x.second) {
// y.first is a QueryId and
// y.second is a QueryInfo*
QueryInfo*& qi(y.second);
if (! qi->isOpen && now > qi->_expires) {
toDelete.emplace_back(x.first, y.first);
}
}
}
for (auto& p : toDelete) {
try { // just in case
destroy(p.first, p.second);
}
catch (...) {
}
}
}
// -----------------------------------------------------------------------------