1
0
Fork 0

Changed some tasks to post through Scheduler instead of directly. (#3159)

This commit is contained in:
Dan Larkin 2017-08-30 04:41:41 -04:00 committed by Frank Celler
parent 1ace247273
commit 6a068d062e
4 changed files with 42 additions and 63 deletions

View File

@ -27,6 +27,8 @@
#include "Cache/Cache.h" #include "Cache/Cache.h"
#include "Cache/Manager.h" #include "Cache/Manager.h"
#include "Cache/Metadata.h" #include "Cache/Metadata.h"
#include "Scheduler/Scheduler.h"
#include "Scheduler/SchedulerFeature.h"
using namespace arangodb::cache; using namespace arangodb::cache;
@ -37,14 +39,14 @@ FreeMemoryTask::FreeMemoryTask(Manager::TaskEnvironment environment,
FreeMemoryTask::~FreeMemoryTask() {} FreeMemoryTask::~FreeMemoryTask() {}
bool FreeMemoryTask::dispatch() { bool FreeMemoryTask::dispatch() {
auto ioService = _manager->ioService(); auto scheduler = SchedulerFeature::SCHEDULER;
if (ioService == nullptr) { if (scheduler == nullptr) {
return false; return false;
} }
_manager->prepareTask(_environment); _manager->prepareTask(_environment);
auto self = shared_from_this(); auto self = shared_from_this();
ioService->post([self, this]() -> void { run(); }); scheduler->post([self, this]() -> void { run(); });
return true; return true;
} }
@ -78,14 +80,14 @@ MigrateTask::MigrateTask(Manager::TaskEnvironment environment, Manager* manager,
MigrateTask::~MigrateTask() {} MigrateTask::~MigrateTask() {}
bool MigrateTask::dispatch() { bool MigrateTask::dispatch() {
auto ioService = _manager->ioService(); auto scheduler = SchedulerFeature::SCHEDULER;
if (ioService == nullptr) { if (scheduler == nullptr) {
return false; return false;
} }
_manager->prepareTask(_environment); _manager->prepareTask(_environment);
auto self = shared_from_this(); auto self = shared_from_this();
ioService->post([self, this]() -> void { run(); }); scheduler->post([self, this]() -> void { run(); });
return true; return true;
} }

View File

@ -1603,16 +1603,12 @@ int MMFilesCollection::fillIndexes(
TRI_ASSERT(n > 0); TRI_ASSERT(n > 0);
TRI_ASSERT(SchedulerFeature::SCHEDULER != nullptr);
auto ioService = SchedulerFeature::SCHEDULER->ioService();
TRI_ASSERT(ioService != nullptr);
PerformanceLogScope logScope( PerformanceLogScope logScope(
std::string("fill-indexes-document-collection { collection: ") + std::string("fill-indexes-document-collection { collection: ") +
_logicalCollection->vocbase()->name() + "/" + _logicalCollection->name() + _logicalCollection->vocbase()->name() + "/" + _logicalCollection->name() +
" }, indexes: " + std::to_string(n - 1)); " }, indexes: " + std::to_string(n - 1));
auto queue = std::make_shared<arangodb::basics::LocalTaskQueue>(ioService); auto queue = std::make_shared<arangodb::basics::LocalTaskQueue>();
try { try {
TRI_ASSERT(!ServerState::instance()->isCoordinator()); TRI_ASSERT(!ServerState::instance()->isCoordinator());

View File

@ -27,6 +27,8 @@
#include "Basics/MutexLocker.h" #include "Basics/MutexLocker.h"
#include "Basics/asio-helper.h" #include "Basics/asio-helper.h"
#include "Logger/Logger.h" #include "Logger/Logger.h"
#include "Scheduler/Scheduler.h"
#include "Scheduler/SchedulerFeature.h"
using namespace arangodb::basics; using namespace arangodb::basics;
@ -37,12 +39,12 @@ using namespace arangodb::basics;
LocalTask::LocalTask(std::shared_ptr<LocalTaskQueue> const& queue) : _queue(queue) {} LocalTask::LocalTask(std::shared_ptr<LocalTaskQueue> const& queue) : _queue(queue) {}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief dispatch this task to the underlying io_service /// @brief dispatch this task to the scheduler
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void LocalTask::dispatch() { void LocalTask::dispatch() {
auto self = shared_from_this(); auto self = shared_from_this();
_queue->ioService()->post([self, this]() { SchedulerFeature::SCHEDULER->post([self, this]() {
_queue->startTask(); _queue->startTask();
try { try {
run(); run();
@ -75,35 +77,26 @@ void LocalCallbackTask::run() {
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief dispatch this task to the underlying io_service /// @brief dispatch the callback task to the scheduler
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void LocalCallbackTask::dispatch() { void LocalCallbackTask::dispatch() {
auto self = shared_from_this(); auto self = shared_from_this();
_queue->ioService()->post([self, this]() { run(); }); SchedulerFeature::SCHEDULER->post([self, this]() { run(); });
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief create a queue using the specified io_service /// @brief create a queue
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
LocalTaskQueue::LocalTaskQueue(boost::asio::io_service* ioService) LocalTaskQueue::LocalTaskQueue()
: _ioService(ioService), : _queue(),
_queue(),
_callbackQueue(), _callbackQueue(),
_condition(), _condition(),
_mutex(), _mutex(),
_missing(0), _missing(0),
_started(0), _started(0),
_status(TRI_ERROR_NO_ERROR) { _status(TRI_ERROR_NO_ERROR) {}
TRI_ASSERT(_ioService != nullptr);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief exposes underlying io_service
//////////////////////////////////////////////////////////////////////////////
boost::asio::io_service* LocalTaskQueue::ioService() { return _ioService; }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the queue. /// @brief destroy the queue.
@ -183,7 +176,7 @@ void LocalTaskQueue::dispatchAndWait() {
if (_missing > 0 && if (_missing > 0 &&
_started == 0 && _started == 0 &&
_ioService->stopped()) { SchedulerFeature::SCHEDULER->isStopping()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN); THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN);
} }
@ -213,7 +206,7 @@ void LocalTaskQueue::dispatchAndWait() {
if (_missing > 0 && if (_missing > 0 &&
_started == 0 && _started == 0 &&
_ioService->stopped()) { SchedulerFeature::SCHEDULER->isStopping()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN); THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN);
} }

View File

@ -90,19 +90,13 @@ class LocalTaskQueue {
LocalTaskQueue(LocalTaskQueue const&) = delete; LocalTaskQueue(LocalTaskQueue const&) = delete;
LocalTaskQueue& operator=(LocalTaskQueue const&) = delete; LocalTaskQueue& operator=(LocalTaskQueue const&) = delete;
explicit LocalTaskQueue(boost::asio::io_service*); explicit LocalTaskQueue();
~LocalTaskQueue(); ~LocalTaskQueue();
void startTask(); void startTask();
void stopTask(); void stopTask();
//////////////////////////////////////////////////////////////////////////////
/// @brief exposes underlying io_service
//////////////////////////////////////////////////////////////////////////////
boost::asio::io_service* ioService();
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief enqueue a task to be run /// @brief enqueue a task to be run
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -144,12 +138,6 @@ class LocalTaskQueue {
int status(); int status();
private: private:
//////////////////////////////////////////////////////////////////////////////
/// @brief io_service to dispatch tasks to
//////////////////////////////////////////////////////////////////////////////
boost::asio::io_service* _ioService;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief internal task queue /// @brief internal task queue
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////