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

View File

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

View File

@ -27,6 +27,8 @@
#include "Basics/MutexLocker.h"
#include "Basics/asio-helper.h"
#include "Logger/Logger.h"
#include "Scheduler/Scheduler.h"
#include "Scheduler/SchedulerFeature.h"
using namespace arangodb::basics;
@ -37,12 +39,12 @@ using namespace arangodb::basics;
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() {
auto self = shared_from_this();
_queue->ioService()->post([self, this]() {
SchedulerFeature::SCHEDULER->post([self, this]() {
_queue->startTask();
try {
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() {
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)
: _ioService(ioService),
_queue(),
LocalTaskQueue::LocalTaskQueue()
: _queue(),
_callbackQueue(),
_condition(),
_mutex(),
_missing(0),
_started(0),
_status(TRI_ERROR_NO_ERROR) {
TRI_ASSERT(_ioService != nullptr);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief exposes underlying io_service
//////////////////////////////////////////////////////////////////////////////
boost::asio::io_service* LocalTaskQueue::ioService() { return _ioService; }
_status(TRI_ERROR_NO_ERROR) {}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the queue.
@ -183,7 +176,7 @@ void LocalTaskQueue::dispatchAndWait() {
if (_missing > 0 &&
_started == 0 &&
_ioService->stopped()) {
SchedulerFeature::SCHEDULER->isStopping()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN);
}
@ -213,7 +206,7 @@ void LocalTaskQueue::dispatchAndWait() {
if (_missing > 0 &&
_started == 0 &&
_ioService->stopped()) {
SchedulerFeature::SCHEDULER->isStopping()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN);
}

View File

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