1
0
Fork 0

fix return value checks (#9852)

This commit is contained in:
Jan 2019-08-29 20:38:53 +02:00 committed by GitHub
parent aa4c9230e8
commit 30b36a2a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 23 deletions

View File

@ -1148,8 +1148,8 @@ void ClusterComm::disable() {
}
}
void ClusterComm::scheduleMe(std::function<void()> task) {
arangodb::SchedulerFeature::SCHEDULER->queue(RequestLane::CLUSTER_INTERNAL, std::move(task));
bool ClusterComm::scheduleMe(std::function<void()> task) {
return arangodb::SchedulerFeature::SCHEDULER->queue(RequestLane::CLUSTER_INTERNAL, std::move(task));
}

View File

@ -572,11 +572,10 @@ class ClusterComm {
void disable();
//////////////////////////////////////////////////////////////////////////////
/// @brief push all libcurl callback work to Scheduler threads. It is a
/// public static function that any object can use.
/// @brief push all libcurl callback work to Scheduler threads.
//////////////////////////////////////////////////////////////////////////////
static void scheduleMe(std::function<void()> task);
static bool scheduleMe(std::function<void()> task);
protected: // protected members are for unit test purposes
/// @brief Constructor for test cases.

View File

@ -1704,8 +1704,8 @@ int MMFilesCollection::fillIndexes(transaction::Methods& trx,
_logicalCollection.vocbase().name() + "/" + _logicalCollection.name() +
" }, indexes: " + std::to_string(n - 1));
auto poster = [](std::function<void()> fn) -> void {
SchedulerFeature::SCHEDULER->queue(RequestLane::INTERNAL_LOW, fn);
auto poster = [](std::function<void()> fn) -> bool {
return SchedulerFeature::SCHEDULER->queue(RequestLane::INTERNAL_LOW, fn);
};
auto queue = std::make_shared<arangodb::basics::LocalTaskQueue>(poster);

View File

@ -345,7 +345,7 @@ void Syncer::JobSynchronizer::request(std::function<void()> const& cb) {
}
try {
SchedulerFeature::SCHEDULER->queue(RequestLane::INTERNAL_LOW, [self = shared_from_this(), cb]() {
bool queued = SchedulerFeature::SCHEDULER->queue(RequestLane::INTERNAL_LOW, [self = shared_from_this(), cb]() {
// whatever happens next, when we leave this here, we need to indicate
// that there is no more posted job.
// otherwise the calling thread may block forever waiting on the
@ -354,9 +354,14 @@ void Syncer::JobSynchronizer::request(std::function<void()> const& cb) {
cb();
});
if (!queued) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUEUE_FULL);
}
} catch (...) {
// will get here only if Scheduler::post threw
jobDone();
throw;
}
}

View File

@ -43,7 +43,7 @@ class SupervisedScheduler final : public Scheduler {
uint64_t fifo1Size, uint64_t fifo2Size);
virtual ~SupervisedScheduler();
bool queue(RequestLane lane, std::function<void()>, bool allowDirectHandling = false) override;
bool queue(RequestLane lane, std::function<void()>, bool allowDirectHandling = false) override ADB_WARN_UNUSED_RESULT;
private:
std::atomic<size_t> _numWorkers;

View File

@ -727,12 +727,13 @@ Result Collections::warmup(TRI_vocbase_t& vocbase, LogicalCollection const& coll
return res;
}
auto idxs = coll.getIndexes();
auto poster = [](std::function<void()> fn) -> void {
SchedulerFeature::SCHEDULER->queue(RequestLane::INTERNAL_LOW, fn);
auto poster = [](std::function<void()> fn) -> bool {
return SchedulerFeature::SCHEDULER->queue(RequestLane::INTERNAL_LOW, fn);
};
auto queue = std::make_shared<basics::LocalTaskQueue>(poster);
auto idxs = coll.getIndexes();
for (auto& idx : idxs) {
idx->warmup(&trx, queue);
}

View File

@ -44,8 +44,7 @@ LocalTask::LocalTask(std::shared_ptr<LocalTaskQueue> const& queue)
////////////////////////////////////////////////////////////////////////////////
void LocalTask::dispatch() {
auto self = shared_from_this();
_queue->post([self, this]() {
_queue->post([self = shared_from_this(), this]() {
_queue->startTask();
try {
run();
@ -54,6 +53,7 @@ void LocalTask::dispatch() {
_queue->stopTask();
throw;
}
return true;
});
}
@ -82,8 +82,10 @@ void LocalCallbackTask::run() {
////////////////////////////////////////////////////////////////////////////////
void LocalCallbackTask::dispatch() {
auto self = shared_from_this();
_queue->post([self, this]() { run(); });
_queue->post([self = shared_from_this(), this]() {
run();
return true;
});
}
////////////////////////////////////////////////////////////////////////////////
@ -140,7 +142,12 @@ void LocalTaskQueue::enqueueCallback(std::shared_ptr<LocalCallbackTask> task) {
/// by task dispatch.
//////////////////////////////////////////////////////////////////////////////
void LocalTaskQueue::post(std::function<void()> fn) { _poster(fn); }
void LocalTaskQueue::post(std::function<bool()> fn) {
bool result = _poster(fn);
if (!result) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUEUE_FULL);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief join a single task. reduces the number of waiting tasks and wakes

View File

@ -87,7 +87,7 @@ class LocalCallbackTask : public std::enable_shared_from_this<LocalCallbackTask>
class LocalTaskQueue {
public:
typedef std::function<void(std::function<void()>)> PostFn;
typedef std::function<bool(std::function<void()>)> PostFn;
LocalTaskQueue() = delete;
LocalTaskQueue(LocalTaskQueue const&) = delete;
@ -118,7 +118,7 @@ class LocalTaskQueue {
/// by task dispatch.
//////////////////////////////////////////////////////////////////////////////
void post(std::function<void()> fn);
void post(std::function<bool()> fn);
//////////////////////////////////////////////////////////////////////////////
/// @brief join a single task. reduces the number of waiting tasks and wakes

View File

@ -36,7 +36,7 @@ class Callbacks {
typedef std::function<void(std::unique_ptr<GeneralResponse>)> OnSuccessCallback;
typedef std::function<void(std::function<void()>)> ScheduleMeCallback;
typedef std::function<bool(std::function<void()> const&)> ScheduleMeCallback;
Callbacks() {}
Callbacks(OnSuccessCallback const& onSuccess, OnErrorCallback const& onError)
@ -51,7 +51,10 @@ class Callbacks {
ScheduleMeCallback _scheduleMe;
protected:
static void defaultScheduleMe(std::function<void()> task) { task(); }
static bool defaultScheduleMe(std::function<void()> const& task) {
task();
return true;
}
};
} // namespace communicator
} // namespace arangodb

View File

@ -506,7 +506,7 @@ void Communicator::handleResult(CURL* handle, CURLcode rc) {
// defensive code: intentionally not passing "this". There is a
// possibility that Scheduler will execute the code after Communicator
// object destroyed. use shared_from_this() if ever essential.
rip->_newRequest->_callbacks._scheduleMe([curlHandle, handle, rc, rip] {
bool queued = rip->_newRequest->_callbacks._scheduleMe([curlHandle, handle, rc, rip] {
double connectTime = 0.0;
LOG_TOPIC("44845", TRACE, Logger::COMMUNICATION)
<< ::buildPrefix(rip->_newRequest->_ticketId) << "curl rc is : " << rc << " after "
@ -588,6 +588,10 @@ void Communicator::handleResult(CURL* handle, CURLcode rc) {
break;
}
});
if (!queued) {
callErrorFn(rip, TRI_ERROR_QUEUE_FULL, {nullptr});
}
}
size_t Communicator::readBody(void* data, size_t size, size_t nitems, void* userp) {

View File

@ -497,8 +497,9 @@ std::shared_ptr<arangodb::Index> PhysicalCollectionMock::createIndex(
}
asio_ns::io_context ioContext;
auto poster = [&ioContext](std::function<void()> fn) -> void {
auto poster = [&ioContext](std::function<void()> fn) -> bool {
ioContext.post(fn);
return true;
};
arangodb::basics::LocalTaskQueue taskQueue(poster);
std::shared_ptr<arangodb::basics::LocalTaskQueue> taskQueuePtr(