Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check max validate depth #5790

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graph/validator/AssignmentValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace graph {

Status AssignmentValidator::validateImpl() {
auto *assignSentence = static_cast<AssignmentSentence *>(sentence_);

NG_RETURN_IF_ERROR(validator_->validate());

auto outputs = validator_->outputCols();
Expand Down
1 change: 0 additions & 1 deletion src/graph/validator/SequentialValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace graph {
// Validator of sequential sentences which combine multiple sentences, e.g. GO ...; GO ...;
// Call validator of sub-sentences.
Status SequentialValidator::validateImpl() {
Status status;
if (sentence_->kind() != Sentence::Kind::kSequential) {
return Status::SemanticError(
"Sequential validator validates a SequentialSentences, but %ld is "
Expand Down
31 changes: 22 additions & 9 deletions src/graph/validator/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,25 @@
#include "graph/visitor/DeduceTypeVisitor.h"
#include "graph/visitor/EvaluableExprVisitor.h"
#include "parser/Sentence.h"

DEFINE_uint32(max_statements,
1024,
"threshold for maximun number of statements that can be validate");
namespace nebula {
namespace graph {

thread_local uint32_t Validator::maxStatements_ = 0;

Validator::Validator(Sentence* sentence, QueryContext* qctx)
: sentence_(DCHECK_NOTNULL(sentence)),
qctx_(DCHECK_NOTNULL(qctx)),
vctx_(DCHECK_NOTNULL(qctx->vctx())) {}

// Create validator according to sentence type.
std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryContext* context) {
if (++maxStatements_ > FLAGS_max_statements * 2) {
throw std::runtime_error(
fmt::format("the number of statements exceeds max_statements : {}", FLAGS_max_statements));
}
auto kind = sentence->kind();
switch (kind) {
case Sentence::Kind::kExplain:
Expand Down Expand Up @@ -273,22 +281,27 @@ std::unique_ptr<Validator> Validator::makeValidator(Sentence* sentence, QueryCon
Status Validator::validate(Sentence* sentence, QueryContext* qctx) {
DCHECK(sentence != nullptr);
DCHECK(qctx != nullptr);

// Check if space chosen from session. if chosen, add it to context.
auto session = qctx->rctx()->session();
if (session->space().id > kInvalidSpaceID) {
auto spaceInfo = session->space();
qctx->vctx()->switchToSpace(std::move(spaceInfo));
}
try {
auto validator = makeValidator(sentence, qctx);
NG_RETURN_IF_ERROR(validator->validate());

auto validator = makeValidator(sentence, qctx);
NG_RETURN_IF_ERROR(validator->validate());

auto root = validator->root();
if (!root) {
return Status::SemanticError("Get null plan from sequential validator");
auto root = validator->root();
if (!root) {
return Status::SemanticError("Get null plan from sequential validator");
}
qctx->plan()->setRoot(root);
// reset maxStatements
maxStatements_ = 0;
} catch (const std::exception& error) {
maxStatements_ = 0;
return Status::SemanticError(std::string(error.what()));
}
qctx->plan()->setRoot(root);
return Status::OK();
}

Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/Validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Validator {
std::set<std::string> userDefinedVarNameList_;
// vid's Type
Value::Type vidType_;
static thread_local uint32_t maxStatements_;
jievince marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace graph
Expand Down
Loading