From 69e254d28a94b39bf45cc6d5e87209fa0e052edf Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Mon, 6 Jun 2016 23:49:36 +0200 Subject: [PATCH] trying to fix cleanup --- arangod/Agency/AgencyFeature.cpp | 2 +- arangod/Agency/AgencyFeature.h | 2 +- arangod/Cluster/ClusterFeature.cpp | 2 +- arangod/Cluster/ClusterFeature.h | 2 +- arangod/Dispatcher/Dispatcher.cpp | 26 +++++++++++-------- arangod/Dispatcher/DispatcherFeature.cpp | 4 ++- arangod/RestServer/BootstrapFeature.cpp | 2 +- arangod/RestServer/BootstrapFeature.h | 2 +- arangod/RestServer/ConsoleFeature.cpp | 4 +-- arangod/RestServer/ConsoleFeature.h | 1 - arangod/Scheduler/SchedulerFeature.cpp | 12 +++++---- arangod/Scheduler/SchedulerFeature.h | 1 + arangod/Statistics/StatisticsFeature.cpp | 2 +- arangod/Statistics/StatisticsFeature.h | 2 +- arangod/Wal/LogfileManager.cpp | 2 +- arangod/Wal/LogfileManager.h | 2 +- lib/ApplicationFeatures/ApplicationServer.cpp | 2 +- 17 files changed, 38 insertions(+), 32 deletions(-) diff --git a/arangod/Agency/AgencyFeature.cpp b/arangod/Agency/AgencyFeature.cpp index 4c54c29f15..872e788f63 100644 --- a/arangod/Agency/AgencyFeature.cpp +++ b/arangod/Agency/AgencyFeature.cpp @@ -189,7 +189,7 @@ void AgencyFeature::start() { _agent->load(); } -void AgencyFeature::stop() { +void AgencyFeature::unprepare() { if (!isEnabled()) { return; diff --git a/arangod/Agency/AgencyFeature.h b/arangod/Agency/AgencyFeature.h index c810ef0203..f5379d5653 100644 --- a/arangod/Agency/AgencyFeature.h +++ b/arangod/Agency/AgencyFeature.h @@ -40,7 +40,7 @@ class AgencyFeature : virtual public application_features::ApplicationFeature { void validateOptions(std::shared_ptr) override final; void prepare() override final; void start() override final; - void stop() override final; + void unprepare() override final; private: uint64_t _size; // agency size (default: 5) diff --git a/arangod/Cluster/ClusterFeature.cpp b/arangod/Cluster/ClusterFeature.cpp index b6d66318f1..82a9be79f0 100644 --- a/arangod/Cluster/ClusterFeature.cpp +++ b/arangod/Cluster/ClusterFeature.cpp @@ -461,7 +461,7 @@ void ClusterFeature::start() { dispatcher->buildAqlQueue(); } -void ClusterFeature::stop() { +void ClusterFeature::unprepare() { if (_enableCluster) { if (_heartbeatThread != nullptr) { _heartbeatThread->beginShutdown(); diff --git a/arangod/Cluster/ClusterFeature.h b/arangod/Cluster/ClusterFeature.h index 1b76ecf956..cbb0abe161 100644 --- a/arangod/Cluster/ClusterFeature.h +++ b/arangod/Cluster/ClusterFeature.h @@ -42,7 +42,7 @@ class ClusterFeature : public application_features::ApplicationFeature { void validateOptions(std::shared_ptr) override final; void prepare() override final; void start() override final; - void stop() override final; + void unprepare() override final; private: std::vector _agencyEndpoints; diff --git a/arangod/Dispatcher/Dispatcher.cpp b/arangod/Dispatcher/Dispatcher.cpp index 3c45027784..d55594c1ba 100644 --- a/arangod/Dispatcher/Dispatcher.cpp +++ b/arangod/Dispatcher/Dispatcher.cpp @@ -24,10 +24,10 @@ #include "Dispatcher.h" -#include "Logger/Logger.h" #include "Dispatcher/DispatcherQueue.h" #include "Dispatcher/DispatcherThread.h" #include "Dispatcher/Job.h" +#include "Logger/Logger.h" using namespace arangodb::basics; using namespace arangodb::rest; @@ -59,21 +59,22 @@ void Dispatcher::addStandardQueue(size_t nrThreads, size_t nrExtraThreads, size_t maxSize) { TRI_ASSERT(_queues[STANDARD_QUEUE] == nullptr); - _queues[STANDARD_QUEUE] = - new DispatcherQueue(_scheduler, this, STANDARD_QUEUE, - CreateDispatcherThread, nrThreads, nrExtraThreads, maxSize); + _queues[STANDARD_QUEUE] = new DispatcherQueue( + _scheduler, this, STANDARD_QUEUE, CreateDispatcherThread, nrThreads, + nrExtraThreads, maxSize); } //////////////////////////////////////////////////////////////////////////////// /// @brief adds the AQL queue (used for the cluster) //////////////////////////////////////////////////////////////////////////////// -void Dispatcher::addAQLQueue(size_t nrThreads, size_t nrExtraThreads, +void Dispatcher::addAQLQueue(size_t nrThreads, size_t nrExtraThreads, size_t maxSize) { TRI_ASSERT(_queues[AQL_QUEUE] == nullptr); - _queues[AQL_QUEUE] = new DispatcherQueue( - _scheduler, this, AQL_QUEUE, CreateDispatcherThread, nrThreads, nrExtraThreads, maxSize); + _queues[AQL_QUEUE] = + new DispatcherQueue(_scheduler, this, AQL_QUEUE, CreateDispatcherThread, + nrThreads, nrExtraThreads, maxSize); } //////////////////////////////////////////////////////////////////////////////// @@ -100,7 +101,8 @@ int Dispatcher::addJob(std::unique_ptr& job, bool startThread) { // log success, but do this BEFORE the real add, because the addJob might // execute // and delete the job before we have a chance to log something - LOG(TRACE) << "added job " << (void*)(job.get()) << " to queue '" << qnr << "'"; + LOG(TRACE) << "added job " << (void*)(job.get()) << " to queue '" << qnr + << "'"; // add the job to the list of ready jobs return queue->addJob(job, startThread); @@ -152,8 +154,6 @@ void Dispatcher::shutdown() { LOG(DEBUG) << "shutting down the dispatcher"; for (auto queue : _queues) { - - if (queue != nullptr) { queue->shutdown(); } @@ -169,7 +169,11 @@ void Dispatcher::reportStatus() { DispatcherQueue* queue = _queues[i]; if (queue != nullptr) { - LOG(INFO) << "dispatcher queue '" << i << "': initial = " << queue->_nrThreads << ", running = " << queue->_nrRunning.load() << ", waiting = " << queue->_nrWaiting.load() << ", blocked = " << queue->_nrBlocked.load(); + LOG(INFO) << "dispatcher queue '" << i + << "': initial = " << queue->_nrThreads + << ", running = " << queue->_nrRunning.load() + << ", waiting = " << queue->_nrWaiting.load() + << ", blocked = " << queue->_nrBlocked.load(); } } } diff --git a/arangod/Dispatcher/DispatcherFeature.cpp b/arangod/Dispatcher/DispatcherFeature.cpp index 56fca43588..565f316c2d 100644 --- a/arangod/Dispatcher/DispatcherFeature.cpp +++ b/arangod/Dispatcher/DispatcherFeature.cpp @@ -57,7 +57,9 @@ DispatcherFeature::DispatcherFeature( } DispatcherFeature::~DispatcherFeature() { - delete _dispatcher; + if (_dispatcher != nullptr) { + delete _dispatcher; + } } void DispatcherFeature::collectOptions( diff --git a/arangod/RestServer/BootstrapFeature.cpp b/arangod/RestServer/BootstrapFeature.cpp index 0095d9ceb5..2fb139c153 100644 --- a/arangod/RestServer/BootstrapFeature.cpp +++ b/arangod/RestServer/BootstrapFeature.cpp @@ -162,7 +162,7 @@ void BootstrapFeature::start() { _isReady = true; } -void BootstrapFeature::stop() { +void BootstrapFeature::unprepare() { auto server = ApplicationServer::getFeature("DatabaseServer"); TRI_server_t* s = server->SERVER; diff --git a/arangod/RestServer/BootstrapFeature.h b/arangod/RestServer/BootstrapFeature.h index 21f9ddbb99..5813102671 100644 --- a/arangod/RestServer/BootstrapFeature.h +++ b/arangod/RestServer/BootstrapFeature.h @@ -33,7 +33,7 @@ class BootstrapFeature final : public application_features::ApplicationFeature { public: void collectOptions(std::shared_ptr) override final; void start() override final; - void stop() override final; + void unprepare() override final; bool isReady() const { return _isReady; diff --git a/arangod/RestServer/ConsoleFeature.cpp b/arangod/RestServer/ConsoleFeature.cpp index 13e6f61381..184aa07bdb 100644 --- a/arangod/RestServer/ConsoleFeature.cpp +++ b/arangod/RestServer/ConsoleFeature.cpp @@ -60,7 +60,7 @@ void ConsoleFeature::start() { _consoleThread->start(); } -void ConsoleFeature::stop() { +void ConsoleFeature::unprepare() { if (_operationMode != OperationMode::MODE_CONSOLE) { return; } @@ -73,8 +73,6 @@ void ConsoleFeature::stop() { while (_consoleThread->isRunning() && ++iterations < 30) { usleep(100 * 1000); // spin while console is still needed } -} -void ConsoleFeature::unprepare() { std::cout << std::endl << TRI_BYE_MESSAGE << std::endl; } diff --git a/arangod/RestServer/ConsoleFeature.h b/arangod/RestServer/ConsoleFeature.h index 63e9f56609..961d6d1803 100644 --- a/arangod/RestServer/ConsoleFeature.h +++ b/arangod/RestServer/ConsoleFeature.h @@ -36,7 +36,6 @@ class ConsoleFeature final : public application_features::ApplicationFeature { public: void start() override final; - void stop() override final; void unprepare() override final; private: diff --git a/arangod/Scheduler/SchedulerFeature.cpp b/arangod/Scheduler/SchedulerFeature.cpp index 43dc75634f..5218e53053 100644 --- a/arangod/Scheduler/SchedulerFeature.cpp +++ b/arangod/Scheduler/SchedulerFeature.cpp @@ -58,6 +58,12 @@ SchedulerFeature::SchedulerFeature( startsAfter("WorkMonitor"); } +SchedulerFeature::~SchedulerFeature() { + if (_scheduler != nullptr) { + delete _scheduler; + } +} + void SchedulerFeature::collectOptions( std::shared_ptr options) { options->addSection("scheduler", "Configure the I/O scheduler"); @@ -145,11 +151,7 @@ void SchedulerFeature::stop() { } void SchedulerFeature::unprepare() { - if (_scheduler != nullptr) { - delete _scheduler; - _scheduler = nullptr; - SCHEDULER = nullptr; - } + SCHEDULER = nullptr; } #ifdef _WIN32 diff --git a/arangod/Scheduler/SchedulerFeature.h b/arangod/Scheduler/SchedulerFeature.h index 755fd19445..c739db6969 100644 --- a/arangod/Scheduler/SchedulerFeature.h +++ b/arangod/Scheduler/SchedulerFeature.h @@ -40,6 +40,7 @@ class SchedulerFeature final : public application_features::ApplicationFeature { public: explicit SchedulerFeature(application_features::ApplicationServer* server); + ~SchedulerFeature(); public: void collectOptions(std::shared_ptr) override final; diff --git a/arangod/Statistics/StatisticsFeature.cpp b/arangod/Statistics/StatisticsFeature.cpp index 959cc795cb..8879f91e36 100644 --- a/arangod/Statistics/StatisticsFeature.cpp +++ b/arangod/Statistics/StatisticsFeature.cpp @@ -54,7 +54,7 @@ void StatisticsFeature::start() { TRI_InitializeStatistics(); } -void StatisticsFeature::stop() { +void StatisticsFeature::unprepare() { TRI_ShutdownStatistics(); STATISTICS = nullptr; } diff --git a/arangod/Statistics/StatisticsFeature.h b/arangod/Statistics/StatisticsFeature.h index 854eb3b06c..9054da2803 100644 --- a/arangod/Statistics/StatisticsFeature.h +++ b/arangod/Statistics/StatisticsFeature.h @@ -42,7 +42,7 @@ class StatisticsFeature final public: void collectOptions(std::shared_ptr) override final; void start() override final; - void stop() override final; + void unprepare() override final; public: void disableStatistics() { _statistics = false; } diff --git a/arangod/Wal/LogfileManager.cpp b/arangod/Wal/LogfileManager.cpp index 49464e9ae4..2c34287e1e 100644 --- a/arangod/Wal/LogfileManager.cpp +++ b/arangod/Wal/LogfileManager.cpp @@ -454,7 +454,7 @@ bool LogfileManager::open() { return true; } -void LogfileManager::stop() { +void LogfileManager::unprepare() { _shutdown = 1; LOG(TRACE) << "shutting down WAL"; diff --git a/arangod/Wal/LogfileManager.h b/arangod/Wal/LogfileManager.h index c2b2fa9b60..91ab218124 100644 --- a/arangod/Wal/LogfileManager.h +++ b/arangod/Wal/LogfileManager.h @@ -116,7 +116,7 @@ class LogfileManager final : public application_features::ApplicationFeature { void validateOptions(std::shared_ptr) override final; void prepare() override final; void start() override final; - void stop() override final; + void unprepare() override final; public: // run the recovery procedure diff --git a/lib/ApplicationFeatures/ApplicationServer.cpp b/lib/ApplicationFeatures/ApplicationServer.cpp index 3eb5ce3b84..c91caaa758 100644 --- a/lib/ApplicationFeatures/ApplicationServer.cpp +++ b/lib/ApplicationFeatures/ApplicationServer.cpp @@ -545,7 +545,7 @@ void ApplicationServer::stop() { auto feature = *it; LOG_TOPIC(TRACE, Logger::STARTUP) << feature->name() << "::stop"; - // feature->stop(); + feature->stop(); feature->state(FeatureState::STOPPED); reportFeatureProgress(_state, feature->name()); }