1
0
Fork 0

Bug fix/cppcheck issues (#10105)

This commit is contained in:
Jan 2019-09-30 09:27:33 +02:00 committed by GitHub
parent c21f4c92aa
commit 2e293b85ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 31 additions and 45 deletions

View File

@ -58,7 +58,6 @@ std::string const NO_LEADER("");
/// Agent configuration /// Agent configuration
Agent::Agent(ApplicationServer& server, config_t const& config) Agent::Agent(ApplicationServer& server, config_t const& config)
: Thread(server, "Agent"), : Thread(server, "Agent"),
_server(server),
_constituent(server), _constituent(server),
_supervision(server), _supervision(server),
_config(config), _config(config),
@ -79,9 +78,6 @@ Agent::Agent(ApplicationServer& server, config_t const& config)
} }
} }
/// @brief the underlying application server
application_features::ApplicationServer& Agent::server() { return _server; }
/// This agent's id /// This agent's id
std::string Agent::id() const { return _config.id(); } std::string Agent::id() const { return _config.id(); }

View File

@ -51,9 +51,6 @@ class Agent final : public arangodb::Thread, public AgentInterface {
/// @brief Clean up /// @brief Clean up
~Agent(); ~Agent();
/// @brief the underlying application server
application_features::ApplicationServer& server();
/// @brief bring down threads, can be called multiple times. /// @brief bring down threads, can be called multiple times.
void waitForThreadsStop(); void waitForThreadsStop();
@ -332,9 +329,6 @@ class Agent final : public arangodb::Thread, public AgentInterface {
/// @brief Find out, if we've had acknowledged RPCs recent enough /// @brief Find out, if we've had acknowledged RPCs recent enough
bool challengeLeadership(); bool challengeLeadership();
/// @brief underlying application server
application_features::ApplicationServer& _server;
/// @brief Leader election delegate /// @brief Leader election delegate
Constituent _constituent; Constituent _constituent;

View File

@ -52,7 +52,7 @@ class Agent;
// RAFT leader election // RAFT leader election
class Constituent : public Thread { class Constituent : public Thread {
public: public:
Constituent(application_features::ApplicationServer&); explicit Constituent(application_features::ApplicationServer&);
// clean up and exit election // clean up and exit election
virtual ~Constituent(); virtual ~Constituent();

View File

@ -90,7 +90,7 @@ class Supervision : public arangodb::CriticalThread {
}; };
/// @brief Construct sanity checking /// @brief Construct sanity checking
Supervision(application_features::ApplicationServer& server); explicit Supervision(application_features::ApplicationServer& server);
/// @brief Default dtor /// @brief Default dtor
~Supervision(); ~Supervision();

View File

@ -77,7 +77,9 @@ BlocksWithClients::BlocksWithClients(ExecutionEngine* engine, ExecutionNode cons
} }
std::pair<ExecutionState, bool> BlocksWithClients::getBlock(size_t atMost) { std::pair<ExecutionState, bool> BlocksWithClients::getBlock(size_t atMost) {
throwIfKilled(); // check if we were aborted if (_engine->getQuery()->killed()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED);
}
auto res = _dependencies[0]->getSome(atMost); auto res = _dependencies[0]->getSome(atMost);
if (res.first == ExecutionState::WAITING) { if (res.first == ExecutionState::WAITING) {
@ -127,11 +129,6 @@ size_t BlocksWithClients::getClientId(std::string const& shardId) const {
return it->second; return it->second;
} }
void BlocksWithClients::throwIfKilled() {
if (_engine->getQuery()->killed()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED);
}
}
std::pair<ExecutionState, SharedAqlItemBlockPtr> BlocksWithClients::getSome(size_t) { std::pair<ExecutionState, SharedAqlItemBlockPtr> BlocksWithClients::getSome(size_t) {
TRI_ASSERT(false); TRI_ASSERT(false);
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED); THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);

View File

@ -87,9 +87,6 @@ class BlocksWithClients : public ExecutionBlock {
/// corresponding to <shardId> /// corresponding to <shardId>
size_t getClientId(std::string const& shardId) const; size_t getClientId(std::string const& shardId) const;
/// @brief throw an exception if query was killed
void throwIfKilled();
/// @brief _shardIdMap: map from shardIds to clientNrs /// @brief _shardIdMap: map from shardIds to clientNrs
std::unordered_map<std::string, size_t> _shardIdMap; std::unordered_map<std::string, size_t> _shardIdMap;

View File

@ -64,7 +64,6 @@ class ExpressionContext {
transaction::Methods*, transaction::Methods*,
bool& isEmptyExpression) = 0; bool& isEmptyExpression) = 0;
virtual bool killed() const = 0;
virtual TRI_vocbase_t& vocbase() const = 0; virtual TRI_vocbase_t& vocbase() const = 0;
virtual Query* query() const = 0; virtual Query* query() const = 0;
}; };

View File

@ -4186,19 +4186,21 @@ AqlValue Functions::Sleep(ExpressionContext* expressionContext,
return AqlValue(AqlValueHintNull()); return AqlValue(AqlValueHintNull());
} }
double now = TRI_microtime();
double const until = now + value.toDouble();
auto& server = application_features::ApplicationServer::server(); auto& server = application_features::ApplicationServer::server();
while (now < until) { double const sleepValue = value.toDouble();
std::this_thread::sleep_for(std::chrono::milliseconds(100)); auto now = std::chrono::steady_clock::now();
auto const endTime = now + std::chrono::milliseconds(static_cast<int64_t>(sleepValue * 1000.0));
if (expressionContext->killed()) { while (now < endTime) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
if (expressionContext->query()->killed()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED); THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED);
} else if (server.isStopping()) { } else if (server.isStopping()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN); THROW_ARANGO_EXCEPTION(TRI_ERROR_SHUTTING_DOWN);
} }
now = TRI_microtime(); now = std::chrono::steady_clock::now();
} }
return AqlValue(AqlValueHintNull()); return AqlValue(AqlValueHintNull());
} }

View File

@ -54,8 +54,6 @@ icu::RegexMatcher* QueryExpressionContext::buildSplitMatcher(AqlValue splitExpre
return _query->regexCache()->buildSplitMatcher(splitExpression, trx, isEmptyExpression); return _query->regexCache()->buildSplitMatcher(splitExpression, trx, isEmptyExpression);
} }
bool QueryExpressionContext::killed() const { return _query->killed(); }
TRI_vocbase_t& QueryExpressionContext::vocbase() const { TRI_vocbase_t& QueryExpressionContext::vocbase() const {
return _query->vocbase(); return _query->vocbase();
} }

View File

@ -45,7 +45,6 @@ class QueryExpressionContext : public ExpressionContext {
icu::RegexMatcher* buildSplitMatcher(AqlValue splitExpression, transaction::Methods*, icu::RegexMatcher* buildSplitMatcher(AqlValue splitExpression, transaction::Methods*,
bool& isEmptyExpression) override; bool& isEmptyExpression) override;
bool killed() const override final;
TRI_vocbase_t& vocbase() const override final; TRI_vocbase_t& vocbase() const override final;
Query* query() const override final; Query* query() const override final;

View File

@ -466,7 +466,7 @@ class ClusterComm {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
ClusterComm(application_features::ApplicationServer&); ClusterComm(application_features::ApplicationServer&);
ClusterComm(ClusterComm const&); // not implemented explicit ClusterComm(ClusterComm const&); // not implemented
void operator=(ClusterComm const&); // not implemented void operator=(ClusterComm const&); // not implemented
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -717,7 +717,7 @@ class ClusterCommThread : public Thread {
ClusterCommThread& operator=(ClusterCommThread const&); ClusterCommThread& operator=(ClusterCommThread const&);
public: public:
ClusterCommThread(application_features::ApplicationServer&); explicit ClusterCommThread(application_features::ApplicationServer&);
~ClusterCommThread(); ~ClusterCommThread();
public: public:
void beginShutdown() override; void beginShutdown() override;

View File

@ -52,7 +52,7 @@ class RecoveryManager {
void _renewPrimaryServer(ShardID const& shard); void _renewPrimaryServer(ShardID const& shard);
public: public:
RecoveryManager(ClusterInfo&); explicit RecoveryManager(ClusterInfo&);
~RecoveryManager(); ~RecoveryManager();
void monitorCollections(DatabaseID const& database, void monitorCollections(DatabaseID const& database,

View File

@ -81,7 +81,7 @@ class ReplicationApplierConfiguration {
std::string _clientInfoString; std::string _clientInfoString;
public: public:
ReplicationApplierConfiguration(application_features::ApplicationServer&); explicit ReplicationApplierConfiguration(application_features::ApplicationServer&);
~ReplicationApplierConfiguration() = default; ~ReplicationApplierConfiguration() = default;
ReplicationApplierConfiguration(ReplicationApplierConfiguration const&) = default; ReplicationApplierConfiguration(ReplicationApplierConfiguration const&) = default;

View File

@ -57,7 +57,7 @@ class DatabaseManagerThread final : public Thread {
DatabaseManagerThread(DatabaseManagerThread const&) = delete; DatabaseManagerThread(DatabaseManagerThread const&) = delete;
DatabaseManagerThread& operator=(DatabaseManagerThread const&) = delete; DatabaseManagerThread& operator=(DatabaseManagerThread const&) = delete;
DatabaseManagerThread(application_features::ApplicationServer&); explicit DatabaseManagerThread(application_features::ApplicationServer&);
~DatabaseManagerThread(); ~DatabaseManagerThread();
void run() override; void run() override;

View File

@ -79,7 +79,7 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class RocksDBEventListener : public rocksdb::EventListener { class RocksDBEventListener : public rocksdb::EventListener {
public: public:
RocksDBEventListener(application_features::ApplicationServer&); explicit RocksDBEventListener(application_features::ApplicationServer&);
virtual ~RocksDBEventListener(); virtual ~RocksDBEventListener();
void OnFlushCompleted(rocksdb::DB* db, const rocksdb::FlushJobInfo& flush_job_info) override; void OnFlushCompleted(rocksdb::DB* db, const rocksdb::FlushJobInfo& flush_job_info) override;

View File

@ -84,7 +84,8 @@ StatisticsDistribution TRI_TotalTimeDistributionStatistics(TRI_RequestTimeDistri
class StatisticsThread final : public Thread { class StatisticsThread final : public Thread {
public: public:
StatisticsThread(ApplicationServer& server) : Thread(server, "Statistics") {} explicit StatisticsThread(ApplicationServer& server)
: Thread(server, "Statistics") {}
~StatisticsThread() { shutdown(); } ~StatisticsThread() { shutdown(); }
public: public:

View File

@ -44,7 +44,7 @@ enum BACKUP_ENGINE {ROCKSDB, MMFILES, CLUSTER};
class HotBackup { class HotBackup {
public: public:
HotBackup(application_features::ApplicationServer& server); explicit HotBackup(application_features::ApplicationServer& server);
virtual ~HotBackup() = default; virtual ~HotBackup() = default;
/** /**

View File

@ -158,13 +158,13 @@ std::string Thread::stringify(ThreadState state) {
Thread::Thread(application_features::ApplicationServer& server, std::string const& name, Thread::Thread(application_features::ApplicationServer& server, std::string const& name,
bool deleteOnExit, std::uint32_t terminationTimeout) bool deleteOnExit, std::uint32_t terminationTimeout)
: _server(server), : _server(server),
_deleteOnExit(deleteOnExit),
_threadStructInitialized(false), _threadStructInitialized(false),
_refs(0), _refs(0),
_name(name), _name(name),
_thread(), _thread(),
_threadNumber(0), _threadNumber(0),
_terminationTimeout(terminationTimeout), _terminationTimeout(terminationTimeout),
_deleteOnExit(deleteOnExit),
_finishedCondition(nullptr), _finishedCondition(nullptr),
_state(ThreadState::CREATED) { _state(ThreadState::CREATED) {
TRI_InitThread(&_thread); TRI_InitThread(&_thread);

View File

@ -89,13 +89,15 @@ class Thread {
bool deleteOnExit = false, std::uint32_t terminationTimeout = INFINITE); bool deleteOnExit = false, std::uint32_t terminationTimeout = INFINITE);
virtual ~Thread(); virtual ~Thread();
public:
// whether or not the thread is allowed to start during prepare // whether or not the thread is allowed to start during prepare
virtual bool isSystem() { return false; } virtual bool isSystem() { return false; }
/// @brief whether or not the thread is chatty on shutdown /// @brief whether or not the thread is chatty on shutdown
virtual bool isSilent() { return false; } virtual bool isSilent() { return false; }
/// @brief the underlying application server
application_features::ApplicationServer& server() { return _server; }
/// @brief flags the thread as stopping /// @brief flags the thread as stopping
/// Classes that override this function must ensure that they /// Classes that override this function must ensure that they
/// always call Thread::beginShutdown()! /// always call Thread::beginShutdown()!
@ -144,9 +146,6 @@ class Thread {
/// be threadsafe! /// be threadsafe!
void shutdown(); void shutdown();
protected:
application_features::ApplicationServer& _server;
protected: protected:
/// @brief the thread program /// @brief the thread program
virtual void run() = 0; virtual void run() = 0;
@ -161,8 +160,10 @@ class Thread {
void runMe(); void runMe();
void releaseRef(); void releaseRef();
protected:
application_features::ApplicationServer& _server;
private: private:
bool const _deleteOnExit;
std::atomic<bool> _threadStructInitialized; std::atomic<bool> _threadStructInitialized;
std::atomic<int> _refs; std::atomic<int> _refs;
@ -178,6 +179,8 @@ class Thread {
// The default value is INFINITE, i.e., we want to wait forever instead of aborting the process. // The default value is INFINITE, i.e., we want to wait forever instead of aborting the process.
std::uint32_t _terminationTimeout; std::uint32_t _terminationTimeout;
bool const _deleteOnExit;
basics::ConditionVariable* _finishedCondition; basics::ConditionVariable* _finishedCondition;
std::atomic<ThreadState> _state; std::atomic<ThreadState> _state;