8000 noexcept requirement ScopeGuard by maierlars · Pull Request #14713 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content
Merged
3 changes: 1 addition & 2 deletions arangod/Agency/AgencyComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,9 +1199,8 @@ AgencyCommResult AgencyComm::sendWithFailover(arangodb::rest::RequestType method

auto started = std::chrono::steady_clock::now();

TRI_DEFER({
auto sg = ScopeGuard([&]() noexcept {
auto end = std::chrono::steady_clock::now();

_agency_comm_request_time_ms.count(std::chrono::duration_cast<std::chrono::milliseconds>(end - started).count());
});

Expand Down
10 changes: 5 additions & 5 deletions arangod/Agency/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ trans_ret_t Agent::transact(query_t const& queries) {
size_t failed;
auto ret = std::make_shared<arangodb::velocypack::Builder>();
{
TRI_DEFER(removeTrxsOngoing(qs));
auto sg = arangodb::scopeGuard([&]() noexcept { removeTrxsOngoing(qs); });
// Note that once the transactions are in our log, we can remove them
// from the list of ongoing ones, although they might not yet be committed.
// This is because then, inquire will find them in the log and draw its
Expand Down Expand Up @@ -1362,16 +1362,16 @@ write_ret_t Agent::write(query_t const& query, WriteMode const& wmode) {
}

{
addTrxsOngoing(query->slice()); // remember that these are ongoing
TRI_DEFER(removeTrxsOngoing(query->slice()));
auto slice = query->slice();
addTrxsOngoing(slice); // remember that these are ongoing
auto sg = arangodb::scopeGuard([&]() noexcept { removeTrxsOngoing(slice); });
// Note that once the transactions are in our log, we can remove them
// from the list of ongoing ones, although they might not yet be committed.
// This is because then, inquire will find them in the log and draw its
// own conclusions. The map of ongoing trxs is only to cover the time
// from when we receive the request until we have appended the trxs
// ourselves.

auto slice = query->slice();
size_t ntrans = slice.length();
size_t npacks = ntrans / _config.maxAppendSize();
if (ntrans % _config.maxAppendSize() != 0) {
Expand Down Expand Up @@ -2379,7 +2379,7 @@ void Agent::addTrxsOngoing(Slice trxs) {
}
}

void Agent::removeTrxsOngoing(Slice trxs) {
void Agent::removeTrxsOngoing(Slice trxs) noexcept {
try {
MUTEX_LOCKER(guard, _trxsLock);
for (auto const& trx : VPackArrayIterator(trxs)) {
Expand Down
2 changes: 1 addition & 1 deletion arangod/Agency/Agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Agent final : public arangodb::Thread, public AgentInterface {
void addTrxsOngoing(Slice trxs);

/// @brief Remove trxs from list of ongoing ones.
void removeTrxsOngoing(Slice trxs);
void removeTrxsOngoing(Slice trxs) noexcept;

/// @brief Check whether a trx is ongoing.
bool isTrxOngoing(std::string& id);
Expand Down
2 changes: 1 addition & 1 deletion arangod/Aql/AstNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,7 @@ void AstNode::appendValue(arangodb::basics::StringBuffer* buffer) const {
}
}

void AstNode::markFinalized(AstNode* subtreeRoot) {
void AstNode::markFinalized(AstNode* subtreeRoot) noexcept {
if ((nullptr == subtreeRoot) || subtreeRoot->hasFlag(AstNodeFlagType::FLAG_FINALIZED)) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/AstNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ struct AstNode {
/// If it runs into a finalized node, it assumes the whole subtree beneath
/// it is marked already and exits early; otherwise it will finalize the node
/// and recurse on its subtree.
static void markFinalized(AstNode* subtreeRoot);
static void markFinalized(AstNode* subtreeRoot) noexcept;

/// @brief sets the computed value pointer.
void setComputedValue(uint8_t* data);
Expand Down Expand Up @@ -655,7 +655,7 @@ std::ostream& operator<<(std::ostream&, arangodb::aql::AstNode const&);
if (wasFinalizedAlready) { \
(n)->flags = ((n)->flags & ~arangodb::aql::AstNodeFlagType::FLAG_FINALIZED); \
} \
TRI_DEFER(FINALIZE_SUBTREE_CONDITIONAL(n, wasFinalizedAlready));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE_CONDITIONAL(n, wasFinalizedAlready); });
#else
#define FINALIZE_SUBTREE(n) \
while (0) { \
Expand Down
2 changes: 1 addition & 1 deletion arangod/Aql/AstResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ char* AstResources::registerLongString(char* copy, size_t length) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
}

auto guard = scopeGuard([copy]() {
auto guard = scopeGuard([copy]() noexcept {
// in case something goes wrong, we must free the string we got to prevent
// memleaks
TRI_FreeString(copy);
Expand Down
6 changes: 1 addition & 5 deletions arangod/Aql/BlocksWithClients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,9 @@ auto BlocksWithClientsImpl<Executor>::executeForClient(AqlCallStack stack,
_executor.acquireLock();
}

auto guard = scopeGuard([this]() {
auto guard = scopeGuard([&]() noexcept {
if constexpr (std::is_same<MutexExecutor, Executor>::value) {
_executor.releaseLock();
} else {
// mark "this" as unused. unfortunately we cannot use [[maybe_unsed]]
// in the lambda capture as it does not parse
(void) this;
}
});

Expand Down
6 changes: 3 additions & 3 deletions arangod/Aql/CalculationExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void CalculationExecutor<calculationType>::enterContext() {

template <CalculationType calculationType>
template <CalculationType U, typename>
void CalculationExecutor<calculationType>::exitContext() {
void CalculationExecutor<calculationType>::exitContext() noexcept {
if (shouldExitContextBetweenBlocks()) {
// must invalidate the expression now as we might be called from
// different threads
Expand All @@ -140,7 +140,7 @@ void CalculationExecutor<calculationType>::exitContext() {
}

template <CalculationType calculationType>
bool CalculationExecutor<calculationType>::shouldExitContextBetweenBlocks() const {
bool CalculationExecutor<calculationType>::shouldExitContextBetweenBlocks() const noexcept {
static bool const isRunningInCluster = ServerState::instance()->isRunningInCluster();
bool const stream = _infos.getQuery().queryOptions().stream;

Expand Down Expand Up @@ -198,7 +198,7 @@ void CalculationExecutor<CalculationType::V8Condition>::doEvaluation(InputAqlIte
_hasEnteredContext == !input.isFirstDataRowInBlock());

enterContext();
auto contextGuard = scopeGuard([this]() { exitContext(); });
auto contextGuard = scopeGuard([this]() noexcept { exitContext(); });

ISOLATE;
v8::HandleScope scope(isolate); // do not delete this!
Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/CalculationExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class CalculationExecutor {

// Only for V8Conditions
template <CalculationType U = calculationType, typename = std::enable_if_t<U == CalculationType::V8Condition>>
void exitContext();
void exitContext() noexcept;

[[nodiscard]] bool shouldExitContextBetweenBlocks() const;
[[nodiscard]] bool shouldExitContextBetweenBlocks() const noexcept;

private:
transaction::Methods _trx;
Expand Down
26 changes: 13 additions & 13 deletions arangod/Aql/Condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ bool Condition::removeInvalidVariables(VarSet const& validVars) {

auto oldRoot = _root;
_root = _ast->shallowCopyForModify(oldRoot);
TRI_DEFER(FINALIZE_SUBTREE(_root));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(_root); });

bool isEmpty = false;

Expand All @@ -1008,7 +1008,7 @@ bool Condition::removeInvalidVariables(VarSet const& validVars) {
for (size_t i = 0; i < n; ++i) {
auto oldAndNode = _root->getMemberUnchecked(i);
auto andNode = _ast->shallowCopyForModify(oldAndNode);
TRI_DEFER(FINALIZE_SUBTREE(andNode));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(andNode); });
_root->changeMember(i, andNode);

TRI_ASSERT(andNode->type == NODE_TYPE_OPERATOR_NARY_AND);
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void Condition::deduplicateComparisonsRecursive(AstNode* p) {
auto op = p->getMemberUnchecked(j);
auto newNode = _ast->shallowCopyForModify(op);
p->changeMember(j, newNode);
TRI_DEFER(FINALIZE_SUBTREE(newNode));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(newNode); });
if (newNode->type == NODE_TYPE_OPERATOR_BINARY_IN) {
auto deduplicated = deduplicateInOperation(newNode);
p->changeMember(j, deduplicated);
Expand All @@ -1074,7 +1074,7 @@ void Condition::deduplicateComparisonsRecursive(AstNode* p) {
void Condition::optimizeNonDnf() {
auto oldRoot = _root;
_root = _ast->shallowCopyForModify(oldRoot);
TRI_DEFER(FINALIZE_SUBTREE(_root));
auto sg = arangodb::scopeGuard([&, this]() noexcept { FINALIZE_SUBTREE(_root); });
// Sorting and deduplicating all IN/AND/OR nodes
deduplicateComparisonsRecursive(_root);
}
Expand Down Expand Up @@ -1174,7 +1174,7 @@ void Condition::optimize(ExecutionPlan* plan, bool multivalued) {

auto oldRoot = _root;
_root = _ast->shallowCopyForModify(oldRoot);
TRI_DEFER(FINALIZE_SUBTREE(_root));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(_root); });

std::pair<Variable const*, std::vector<arangodb::basics::AttributeName>> varAccess;

Expand All @@ -1190,7 +1190,7 @@ void Condition::optimize(ExecutionPlan* plan, bool multivalued) {
TRI_ASSERT(oldAnd->type == NODE_TYPE_OPERATOR_NARY_AND);
auto andNode = _ast->shallowCopyForModify(oldAnd);
_root->changeMember(r, andNode);
TRI_DEFER(FINALIZE_SUBTREE(andNode));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(andNode); });

restartThisOrItem:
size_t andNumMembers = andNode->numMembers();
Expand Down Expand Up @@ -1322,7 +1322,7 @@ void Condition::optimize(ExecutionPlan* plan, bool multivalued) {
// copy & modify leftNode
auto oldLeft = andNode->getMemberUnchecked(leftPos);
auto leftNode = _ast->shallowCopyForModify(oldLeft);
TRI_DEFER(FINALIZE_SUBTREE(leftNode));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(leftNode); });
andNode->changeMember(leftPos, leftNode);

ConditionPart current(variable, attributeName, leftNode, positions[0].second, nullptr);
Expand Down Expand Up @@ -1436,7 +1436,7 @@ void Condition::optimize(ExecutionPlan* plan, bool multivalued) {
for (size_t iMemb = 0; iMemb < origNode->numMembers(); iMemb++) {
newNode->addMember(origNode->getMemberUnchecked(iMemb));
}
TRI_DEFER(FINALIZE_SUBTREE(newNode));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(newNode); });

andNode->changeMember(positions.at(0).first, newNode);
goto restartThisOrItem;
Expand Down Expand Up @@ -1630,7 +1630,7 @@ AstNode* Condition::deduplicateInOperation(AstNode* operation) {
if (deduplicated != rhs) {
// there were duplicates
auto newOperation = _ast->shallowCopyForModify(operation);
TRI_DEFER(FINALIZE_SUBTREE(newOperation));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(newOperation); });

newOperation->changeMember(1, const_cast<AstNode*>(deduplicated));
return newOperation;
Expand Down Expand Up @@ -1691,7 +1691,7 @@ AstNode* switchSidesInCompare(Ast* ast, AstNode* node) {
auto second = node->getMemberUnchecked(1);

auto newOperator = ast->shallowCopyForModify(node);
TRI_DEFER(FINALIZE_SUBTREE(newOperator));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(newOperator); });

newOperator->changeMember(0, second);
newOperator->changeMember(1, first);
Expand Down Expand Up @@ -1824,7 +1824,7 @@ AstNode* Condition::transformNodePostorder(
if (node->type == NODE_TYPE_OPERATOR_NARY_AND) {
auto old = node;
node = _ast->shallowCopyForModify(old);
TRI_DEFER(FINALIZE_SUBTREE(node));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(node); });

bool distributeOverChildren = false;
bool mustCollapse = false;
Expand Down Expand Up @@ -1931,7 +1931,7 @@ AstNode* Condition::transformNodePostorder(
if (node->type == NODE_TYPE_OPERATOR_NARY_OR) {
auto old = node;
node = _ast->shallowCopyForModify(old);
TRI_DEFER(FINALIZE_SUBTREE(node));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(node); });

size_t const n = node->numMembers();
bool mustCollapse = false;
Expand Down Expand Up @@ -1981,7 +1981,7 @@ AstNode* Condition::fixRoot(AstNode* node, int level) {

auto old = node;
node = _ast->shallowCopyForModify(old);
TRI_DEFER(FINALIZE_SUBTREE(node));
auto sg = arangodb::scopeGuard([&]() noexcept { FINALIZE_SUBTREE(node); });

for (size_t i = 0; i < n; ++i) {
auto sub = node->getMemberUnchecked(i);
Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/EngineInfoContainerDBServerServerBased.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Result EngineInfoContainerDBServerServerBased::buildEngines(

ErrorCode cleanupReason = TRI_ERROR_CLUSTER_TIMEOUT;

auto cleanupGuard = scopeGuard([this, &serverToQueryId, &cleanupReason]() {
auto cleanupGuard = scopeGuard([this, &serverToQueryId, &cleanupReason]() noexcept {
try {
transaction::Methods& trx = _query.trxForOptimization();
auto requests = cleanupEngines(cleanupReason, _query.vocbase().name(), serverToQueryId);
Expand Down Expand Up @@ -444,7 +444,7 @@ Result EngineInfoContainerDBServerServerBased::buildEngines(
// DB server(s).
_query.queryOptions().ttl = std::max<double>(oldTtl, transaction::Manager::idleTTLDBServer);

auto ttlGuard = scopeGuard([this, oldTtl]() {
auto ttlGuard = scopeGuard([this, oldTtl]() noexcept {
// restore previous TTL value
_query.queryOptions().ttl = oldTtl;
});
Expand Down
< 3D20 /copilot-diff-entry>
6 changes: 3 additions & 3 deletions arangod/Aql/ExecutionBlockImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ auto ExecutionBlockImpl<Executor>::executeSkipRowsRange(typename Fetcher::DataRa
-> std::tuple<ExecutorState, typename Executor::Stats, size_t, AqlCallType> {
// The skippedRows is a temporary counter used in this function
// We need to make sure to reset it afterwards.
TRI_DEFER(call.resetSkipCount());
auto sg = arangodb::scopeGuard([&]() noexcept { call.resetSkipCount(); });
if constexpr (skipRowsType<Executor>() == SkipRowsRangeVariant::EXECUTOR) {
if constexpr (isMultiDepExecutor<Executor>) {
TRI_ASSERT(inputRange.numberDependencies() == _dependencies.size());
Expand Down Expand Up @@ -1414,7 +1414,7 @@ ExecutionBlockImpl<Executor>::executeWithoutTrace(AqlCallStack const& callStack)
size_t skippedLocal = 0;
AqlCallType call{};
if constexpr (executorCanReturnWaiting<Executor>) {
TRI_DEFER(ctx.clientCall.resetSkipCount());
auto sg = arangodb::scopeGuard([&]() noexcept { ctx.clientCall.resetSkipCount(); });
ExecutionState executorState = ExecutionState::HASMORE;
std::tie(executorState, stats, skippedLocal, call) =
_executor.skipRowsRange(_lastRange, ctx.clientCall);
Expand Down Expand Up @@ -1557,7 +1557,7 @@ ExecutionBlockImpl<Executor>::executeWithoutTrace(AqlCallStack const& callStack)
<< printTypeInfo() << " all produced, fast forward to end up (sub-)query.";

AqlCall callCopy = ctx.clientCall;
TRI_DEFER(ctx.clientCall.resetSkipCount());
auto sg = arangodb::scopeGuard([&]() noexcept { ctx.clientCall.resetSkipCount(); });
if constexpr (executorHasSideEffects<Executor>) {
if (ctx.stack.needToSkipSubquery()) {
// Fast Forward call.
Expand Down
4 changes: 2 additions & 2 deletions arangod/Aql/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ AqlValue Expression::execute(ExpressionContext* ctx, bool& mustDestroy) {
TRI_ASSERT(_type != UNPROCESSED);

_expressionContext = ctx;
auto guard = scopeGuard([this] {
auto guard = scopeGuard([this]() noexcept {
_expressionContext = nullptr;
});

Expand Down Expand Up @@ -945,7 +945,7 @@ AqlValue Expression::executeSimpleExpressionFCallJS(AstNode const* node,

auto old = v8g->_expressionContext;
v8g->_expressionContext = _expressionContext;
TRI_DEFER(v8g->_expressionContext = old);
auto sg = arangodb::scopeGuard([&]() noexcept { v8g->_expressionContext = old; });

std::string jsName;
size_t const n = member->numMembers();
Expand Down
6 changes: 3 additions & 3 deletions arangod/Aql/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ AqlValue callApplyBackend(ExpressionContext* expressionContext, AstNode const& n

auto old = v8g->_expressionContext;
v8g->_expressionContext = expressionContext;
TRI_DEFER(v8g->_expressionContext = old);
auto sg = arangodb::scopeGuard([&]() noexcept { v8g->_expressionContext = old; });

VPackOptions const& options = trx.vpackOptions();
std::string jsName;
Expand Down Expand Up @@ -8264,7 +8264,7 @@ AqlValue Functions::Apply(ExpressionContext* expressionContext, AstNode const& n
AqlValue rawParamArray;
std::vector<bool> mustFree;

auto guard = scopeGuard([&mustFree, &invokeParams]() {
auto guard = scopeGuard([&mustFree, &invokeParams]() noexcept {
for (size_t i = 0; i < mustFree.size(); ++i) {
if (mustFree[i]) {
invokeParams[i].destroy();
Expand Down Expand Up @@ -8578,7 +8578,7 @@ AqlValue Functions::SchemaValidate(ExpressionContext* expressionContext,

Result res;
{
arangodb::ScopeGuard guardi([storedLevel, &validator]{
arangodb::ScopeGuard guard([storedLevel, &validator]() noexcept {
validator->setLevel(storedLevel);
});

Expand Down
2 changes: 1 addition & 1 deletion arangod/Aql/IResearchViewOptimizerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ void lateDocumentMaterializationArangoSearchRule(Optimizer* opt,
std::unique_ptr<ExecutionPlan> plan,
OptimizerRule const& rule) {
auto modified = false;
auto const addPlan = arangodb::scopeGuard([opt, &plan, &rule, &modified]() {
auto const addPlan = arangodb::scopeGuard([opt, &plan, &rule, &modified]() noexcept {
opt->addPlan(std::move(plan), rule, modified);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addPlan is not noexcept, and I think exceptions thrown be it should generally leave this method.

@maierlars, @mpoeter and I have discussed that this would best be done with another kind of scope guard that works like https://en.cppreference.com/w/cpp/experimental/scope_success.

We can also mimick the previous behavior by wrapping this into a try/catch, which is not quite correct though. But IMO this PR doesn't have to fix all places that used the old ScopeGuard incorrectly, as long as we make sure to fix them afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree! Perhaps we should add comments to mark these places so we can easily find and fix them latter.

});
// arangosearch view node supports late materialization
Expand Down
2 changes: 1 addition & 1 deletion arangod/Aql/IndexExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ void IndexExecutor::initIndexes(InputAqlItemRow& input) {
};

_infos.query().enterV8Context();
TRI_DEFER(cleanup());
auto sg = arangodb::scopeGuard([&]() noexcept { cleanup(); });

ISOLATE;
v8::HandleScope scope(isolate); // do not delete this!
Expand Down
2 changes: 1 addition & 1 deletion arangod/Aql/IndexNodeOptimizerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void arangodb::aql::lateDocumentMaterializationRule(Optimizer* opt,
std::unique_ptr<ExecutionPlan> plan,
OptimizerRule const& rule) {
auto modified = false;
auto const addPlan = arangodb::scopeGuard([opt, &plan, &rule, &modified]() {
auto const addPlan = arangodb::scopeGuard([opt, &plan, &rule, &modified]() noexcept {
opt->addPlan(std::move(plan), rule, modified);
});
Comment on lines -94 to 96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as my comment in arangod/Aql/IResearchViewOptimizerRules.cpp

// index node supports late materialization
Expand Down
6 changes: 4 additions & 2 deletions arangod/Aql/MutexExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ class MutexExecutor {
auto distributeBlock(SharedAqlItemBlockPtr const& block, SkipResult skipped,
std::unordered_map<std::string, ClientBlockData>& blockMap) -> void;

void acquireLock() {
void acquireLock() noexcept {
// don't continue if locking fails
_mutex.lock();
}

void releaseLock() {
void releaseLock() noexcept {
// don't continue if locking fails
_mutex.unlock();
}

Expand Down
Loading
0