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

add max allowed query size #2813

Merged
merged 6 commits into from
Sep 10, 2021
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
2 changes: 2 additions & 0 deletions conf/nebula-graphd.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# Whether to treat partial success as an error.
# This flag is only used for Read-only access, and Modify access always treats partial success as an error.
--accept_partial_success=false
# Maximum sentence length, unit byte
--max_allowed_query_size=4194304

########## networking ##########
# Comma separated Meta Server Addresses
Expand Down
2 changes: 2 additions & 0 deletions conf/nebula-graphd.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
# Whether to treat partial success as an error.
# This flag is only used for Read-only access, and Modify access always treats partial success as an error.
--accept_partial_success=false
# Maximum sentence length, unit byte
--max_allowed_query_size=4194304

########## networking ##########
# Comma separated Meta Server Addresses
Expand Down
1 change: 1 addition & 0 deletions src/graph/service/GraphFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DEFINE_string(auth_type,

DEFINE_string(cloud_http_url, "", "cloud http url including ip, port, url path");
DEFINE_uint32(max_allowed_statements, 512, "Max allowed sequential statements");
DEFINE_uint32(max_allowed_query_size, 4194304, "Max allowed sequential query size");

DEFINE_int64(max_allowed_connections,
std::numeric_limits<int64_t>::max(),
Expand Down
21 changes: 21 additions & 0 deletions src/graph/validator/test/QueryValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "graph/validator/test/ValidatorTestBase.h"

DECLARE_uint32(max_allowed_statements);
DECLARE_uint32(max_allowed_query_size);

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -1118,6 +1119,26 @@ TEST_F(QueryValidatorTest, TestMaxAllowedStatements) {
"exceeded");
}

TEST_F(QueryValidatorTest, TestMaxAllowedQuerySize) {
FLAGS_max_allowed_query_size = 256;
std::string query = "INSERT VERTEX person(name, age) VALUES ";
std::string value = "\"person_1\":(\"person_1\", 1),";
int count = (FLAGS_max_allowed_query_size - query.size()) / value.size();
std::string values;
values.reserve(FLAGS_max_allowed_query_size);
for (int i = 0; i < count; ++i) {
values.append(value);
}
values.erase(values.size() - 1);
query += values;
EXPECT_TRUE(checkResult(query));
query.append(",\"person_2\":(\"person_2\", 2);");
auto result = checkResult(query);
EXPECT_FALSE(result);
EXPECT_EQ(std::string(result.message()), "SyntaxError: Query is too large (282 > 256).");
nevermore3 marked this conversation as resolved.
Show resolved Hide resolved
FLAGS_max_allowed_query_size = 4194304;
}

TEST_F(QueryValidatorTest, TestMatch) {
{
std::string query =
Expand Down
9 changes: 7 additions & 2 deletions src/parser/GQLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "parser/GraphParser.hpp"
#include "parser/GraphScanner.h"

DECLARE_uint32(max_allowed_query_size);
namespace nebula {

class GQLParser {
Expand Down Expand Up @@ -39,8 +40,12 @@ class GQLParser {
}

StatusOr<std::unique_ptr<Sentence>> parse(std::string query) {
// Since GraphScanner needs a writable buffer, we have to copy the query
// string
// Since GraphScanner needs a writable buffer, we have to copy the query string
size_t querySize = query.size();
size_t maxAllowedQuerySize = static_cast<size_t>(FLAGS_max_allowed_query_size);
if (querySize > maxAllowedQuerySize) {
return Status::SyntaxError("Query is too large (%ld > %ld).", querySize, maxAllowedQuerySize);
}
buffer_ = std::move(query);
pos_ = &buffer_[0];
end_ = pos_ + buffer_.size();
Expand Down