diff --git a/src/common/expression/test/AggregateExpressionBenchmark.cpp b/src/common/expression/test/AggregateExpressionBenchmark.cpp index 2e7f32fa7cb..f79cc2fc106 100644 --- a/src/common/expression/test/AggregateExpressionBenchmark.cpp +++ b/src/common/expression/test/AggregateExpressionBenchmark.cpp @@ -5,8 +5,6 @@ #include -#include - #include "common/base/ObjectPool.h" #include "common/expression/AggregateExpression.h" #include "common/expression/ConstantExpression.h" diff --git a/src/common/fs/FileUtils.cpp b/src/common/fs/FileUtils.cpp index f5293de8303..b1183d25055 100644 --- a/src/common/fs/FileUtils.cpp +++ b/src/common/fs/FileUtils.cpp @@ -92,8 +92,8 @@ StatusOr FileUtils::readLink(const char* path) { } StatusOr FileUtils::realPath(const char* path) { - char* buffer = ::realpath(path, NULL); - if (buffer == NULL) { + char* buffer = ::realpath(path, nullptr); + if (buffer == nullptr) { return Status::Error("realpath %s: %s", path, ::strerror(errno)); } std::string truePath(buffer); diff --git a/src/common/memory/MemoryUtils.cpp b/src/common/memory/MemoryUtils.cpp index 7e0bb7db7cc..ede9599c230 100644 --- a/src/common/memory/MemoryUtils.cpp +++ b/src/common/memory/MemoryUtils.cpp @@ -5,13 +5,10 @@ #include "common/memory/MemoryUtils.h" -#include #include #include -#include #include -#include #include "common/fs/FileUtils.h" @@ -42,7 +39,7 @@ StatusOr MemoryUtils::hitsHighWatermark() { uint64_t cacheSize = 0; for (; iter.valid(); ++iter) { auto& sm = iter.matched(); - cacheSize += std::stoul(sm[2].str(), NULL); + cacheSize += std::stoul(sm[2].str(), nullptr); } std::string limitPath = @@ -64,7 +61,7 @@ StatusOr MemoryUtils::hitsHighWatermark() { std::vector memorySize; for (; iter.valid(); ++iter) { auto& sm = iter.matched(); - memorySize.emplace_back(std::stoul(sm[2].str(), NULL) << 10); + memorySize.emplace_back(std::stoul(sm[2].str(), nullptr) << 10); } std::sort(memorySize.begin(), memorySize.end()); if (memorySize.size() >= 2u) { diff --git a/src/common/network/NetworkUtils.cpp b/src/common/network/NetworkUtils.cpp index 5891ebef09c..937d2f34085 100644 --- a/src/common/network/NetworkUtils.cpp +++ b/src/common/network/NetworkUtils.cpp @@ -112,7 +112,7 @@ std::unordered_set NetworkUtils::getPortsInUse() { fs::FileUtils::FileLineIterator iter("/proc/net/tcp", ®ex); while (iter.valid()) { auto& sm = iter.matched(); - inUse.emplace(std::stoul(sm[1].str(), NULL, 16)); + inUse.emplace(std::stoul(sm[1].str(), nullptr, 16)); ++iter; } } @@ -120,7 +120,7 @@ std::unordered_set NetworkUtils::getPortsInUse() { fs::FileUtils::FileLineIterator iter("/proc/net/tcp6", ®ex); while (iter.valid()) { auto& sm = iter.matched(); - inUse.emplace(std::stoul(sm[1].str(), NULL, 16)); + inUse.emplace(std::stoul(sm[1].str(), nullptr, 16)); ++iter; } } @@ -128,7 +128,7 @@ std::unordered_set NetworkUtils::getPortsInUse() { fs::FileUtils::FileLineIterator iter("/proc/net/udp", ®ex); while (iter.valid()) { auto& sm = iter.matched(); - inUse.emplace(std::stoul(sm[1].str(), NULL, 16)); + inUse.emplace(std::stoul(sm[1].str(), nullptr, 16)); ++iter; } } @@ -136,7 +136,7 @@ std::unordered_set NetworkUtils::getPortsInUse() { fs::FileUtils::FileLineIterator iter("/proc/net/udp6", ®ex); while (iter.valid()) { auto& sm = iter.matched(); - inUse.emplace(std::stoul(sm[1].str(), NULL, 16)); + inUse.emplace(std::stoul(sm[1].str(), nullptr, 16)); ++iter; } } @@ -144,7 +144,7 @@ std::unordered_set NetworkUtils::getPortsInUse() { fs::FileUtils::FileLineIterator iter("/proc/net/raw", ®ex); while (iter.valid()) { auto& sm = iter.matched(); - inUse.emplace(std::stoul(sm[1].str(), NULL, 16)); + inUse.emplace(std::stoul(sm[1].str(), nullptr, 16)); ++iter; } } @@ -152,7 +152,7 @@ std::unordered_set NetworkUtils::getPortsInUse() { fs::FileUtils::FileLineIterator iter("/proc/net/raw6", ®ex); while (iter.valid()) { auto& sm = iter.matched(); - inUse.emplace(std::stoul(sm[1].str(), NULL, 16)); + inUse.emplace(std::stoul(sm[1].str(), nullptr, 16)); ++iter; } } @@ -209,7 +209,7 @@ StatusOr> NetworkUtils::resolveHost(const std::string& hos continue; } - auto address = ((struct sockaddr_in*)rp->ai_addr)->sin_addr.s_addr; + auto address = (reinterpret_cast(rp->ai_addr))->sin_addr.s_addr; // We need to match the integer byte order generated by ipv4ToInt, // so we need to convert here. addrs.emplace_back(intToIPv4(htonl(std::move(address))), port); diff --git a/src/common/time/test/WallClockBenchmark.cpp b/src/common/time/test/WallClockBenchmark.cpp index 87c1b0b5f04..9bae3a0c371 100644 --- a/src/common/time/test/WallClockBenchmark.cpp +++ b/src/common/time/test/WallClockBenchmark.cpp @@ -16,7 +16,7 @@ using nebula::time::WallClock; BENCHMARK(gettimeofday_get_msec, iters) { for (uint32_t i = 0; i < iters; i++) { struct timeval tp; - gettimeofday(&tp, NULL); + gettimeofday(&tp, nullptr); auto ts = tp.tv_sec * 1000 + tp.tv_usec / 1000; folly::doNotOptimizeAway(ts); } @@ -46,7 +46,7 @@ BENCHMARK_DRAW_LINE(); BENCHMARK(gettimeofday_get_sec, iters) { for (uint32_t i = 0; i < iters; i++) { struct timeval tp; - gettimeofday(&tp, NULL); + gettimeofday(&tp, nullptr); auto ts = tp.tv_sec; folly::doNotOptimizeAway(ts); } diff --git a/src/graph/service/GraphFlags.h b/src/graph/service/GraphFlags.h index f92ff0a2965..7719e0dd6e2 100644 --- a/src/graph/service/GraphFlags.h +++ b/src/graph/service/GraphFlags.h @@ -45,7 +45,7 @@ DECLARE_uint32(failed_login_attempts); // The deault value is 0. A value of 0 disables the option. DECLARE_uint32(password_lock_time_in_secs); -// optimizer +// Optimizer DECLARE_bool(enable_optimizer); DECLARE_int64(max_allowed_connections); diff --git a/src/graph/service/GraphServer.cpp b/src/graph/service/GraphServer.cpp index c9254d35295..897133a905e 100644 --- a/src/graph/service/GraphServer.cpp +++ b/src/graph/service/GraphServer.cpp @@ -40,6 +40,7 @@ bool GraphServer::start() { return false; } + // Init worker id for snowflake generating unique id nebula::Snowflake::initWorkerId(interface->metaClient_.get()); graphThread_ = std::make_unique([&] { @@ -90,6 +91,7 @@ void GraphServer::notifyStop() { } } +// Stop the server. void GraphServer::stop() { if (serverStatus_.load() == ServiceStatus::STATUS_STOPPED) { LOG(INFO) << "The graph server has been stopped"; diff --git a/src/graph/service/GraphServer.h b/src/graph/service/GraphServer.h index 671c0720605..6c2b2696dde 100644 --- a/src/graph/service/GraphServer.h +++ b/src/graph/service/GraphServer.h @@ -24,7 +24,7 @@ class GraphServer { void stop(); - // used for signal handler to set an internal stop flag + // Used for signal handler to set an internal stop flag void notifyStop(); void waitUntilStop(); diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index eddeddf1030..a89fc66c7a1 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -49,7 +49,7 @@ Status GraphService::init(std::shared_ptr ioExecuto metaClient_ = std::make_unique(ioExecutor, std::move(addrs.value()), options); - // load data try 3 time + // Load data try 3 time bool loadDataOk = metaClient_->waitForMetadReady(3); if (!loadDataOk) { // Resort to retrying in the background diff --git a/src/graph/service/PermissionCheck.cpp b/src/graph/service/PermissionCheck.cpp index d39f88019eb..4dc28ee1dcf 100644 --- a/src/graph/service/PermissionCheck.cpp +++ b/src/graph/service/PermissionCheck.cpp @@ -28,11 +28,10 @@ namespace graph { * Special operation : kShow, kChangePassword */ -// static -Status PermissionCheck::permissionCheck(ClientSession *session, - Sentence *sentence, - ValidateContext *vctx, - GraphSpaceID targetSpace) { +/* static */ Status PermissionCheck::permissionCheck(ClientSession *session, + Sentence *sentence, + ValidateContext *vctx, + GraphSpaceID targetSpace) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -177,7 +176,7 @@ Status PermissionCheck::permissionCheck(ClientSession *session, case Sentence::Kind::kShowMetaLeader: case Sentence::Kind::kShowHosts: { /** - * all roles can be show for above operations. + * All roles can be show for above operations. */ return Status::OK(); } @@ -218,7 +217,7 @@ Status PermissionCheck::permissionCheck(ClientSession *session, return Status::OK(); } case Sentence::Kind::kExplain: - // everyone could explain + // Everyone could explain return Status::OK(); case Sentence::Kind::kSequential: { // No permission checking for sequential sentence. diff --git a/src/graph/service/PermissionManager.cpp b/src/graph/service/PermissionManager.cpp index ab13091089e..08dd566aa38 100644 --- a/src/graph/service/PermissionManager.cpp +++ b/src/graph/service/PermissionManager.cpp @@ -10,8 +10,7 @@ namespace nebula { namespace graph { -// static -Status PermissionManager::canReadSpace(ClientSession *session, GraphSpaceID spaceId) { +/* static */ Status PermissionManager::canReadSpace(ClientSession *session, GraphSpaceID spaceId) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -35,8 +34,8 @@ Status PermissionManager::canReadSpace(ClientSession *session, GraphSpaceID spac return Status::PermissionError("No permission to read space."); } -// static -Status PermissionManager::canReadSchemaOrData(ClientSession *session, ValidateContext *vctx) { +/* static */ Status PermissionManager::canReadSchemaOrData(ClientSession *session, + ValidateContext *vctx) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -60,8 +59,7 @@ Status PermissionManager::canReadSchemaOrData(ClientSession *session, ValidateCo return Status::PermissionError("No permission to read schema/data."); } -// static -Status PermissionManager::canWriteSpace(ClientSession *session) { +/* static */ Status PermissionManager::canWriteSpace(ClientSession *session) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -71,8 +69,8 @@ Status PermissionManager::canWriteSpace(ClientSession *session) { return Status::PermissionError("No permission to write space."); } -// static -Status PermissionManager::canWriteSchema(ClientSession *session, ValidateContext *vctx) { +/* static */ Status PermissionManager::canWriteSchema(ClientSession *session, + ValidateContext *vctx) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -100,8 +98,7 @@ Status PermissionManager::canWriteSchema(ClientSession *session, ValidateContext return Status::PermissionError("No permission to write schema."); } -// static -Status PermissionManager::canWriteUser(ClientSession *session) { +/* static */ Status PermissionManager::canWriteUser(ClientSession *session) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -116,8 +113,8 @@ Status PermissionManager::canWriteUser(ClientSession *session) { } } -// static -Status PermissionManager::canReadUser(ClientSession *session, const std::string &targetUser) { +/* static */ Status PermissionManager::canReadUser(ClientSession *session, + const std::string &targetUser) { if (!FLAGS_enable_authorize) { return Status::OK(); } @@ -180,10 +177,9 @@ Status PermissionManager::canWriteRole(ClientSession *session, targetUser.c_str()); } -// static -Status PermissionManager::canWriteData(ClientSession *session, - ValidateContext *vctx, - bool isAdminJob) { +/* static */ Status PermissionManager::canWriteData(ClientSession *session, + ValidateContext *vctx, + bool isAdminJob) { if (!FLAGS_enable_authorize) { return Status::OK(); } diff --git a/src/graph/service/PermissionManager.h b/src/graph/service/PermissionManager.h index 8c013990e38..ebfea701fa3 100644 --- a/src/graph/service/PermissionManager.h +++ b/src/graph/service/PermissionManager.h @@ -16,6 +16,7 @@ namespace nebula { namespace graph { +// This module is responsible for checking the permission of the user class PermissionManager final { public: PermissionManager() = delete; diff --git a/src/graph/service/QueryEngine.cpp b/src/graph/service/QueryEngine.cpp index d3f4f54e609..477ad18a5f1 100644 --- a/src/graph/service/QueryEngine.cpp +++ b/src/graph/service/QueryEngine.cpp @@ -34,6 +34,7 @@ Status QueryEngine::init(std::shared_ptr ioExecutor PlannersRegister::registerPlanners(); + // Set default optimizer rules std::vector rulesets{&opt::RuleSet::DefaultRules()}; if (FLAGS_enable_optimizer) { rulesets.emplace_back(&opt::RuleSet::QueryRules()); @@ -43,6 +44,7 @@ Status QueryEngine::init(std::shared_ptr ioExecutor return setupMemoryMonitorThread(); } +// Create query context and query instance and execute it void QueryEngine::execute(RequestContextPtr rctx) { auto qctx = std::make_unique(std::move(rctx), schemaManager_.get(), diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index c418dbd1f8d..e3e43aa6433 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -44,11 +44,14 @@ void QueryInstance::execute() { return; } + // Sentence is explain query, finish if (!explainOrContinue()) { onFinish(); return; } + // The execution engine converts the physical execution plan generated by the Planner into a + // series of Executors through the Scheduler to drive the execution of the Executors. scheduler_->schedule() .thenValue([this](Status s) { if (s.ok()) { @@ -67,6 +70,7 @@ Status QueryInstance::validateAndOptimize() { auto *rctx = qctx()->rctx(); auto &spaceName = rctx->session()->space().name; VLOG(1) << "Parsing query: " << rctx->query(); + // Result of parsing, get the parsing tree auto result = GQLParser(qctx()).parse(rctx->query()); NG_RETURN_IF_ERROR(result); sentence_ = std::move(result).value(); @@ -85,7 +89,9 @@ Status QueryInstance::validateAndOptimize() { } } + // Validate the query, if failed, return NG_RETURN_IF_ERROR(Validator::validate(sentence_.get(), qctx())); + // Optimize the query, and get the execution plan NG_RETURN_IF_ERROR(findBestPlan()); stats::StatsManager::addValue(kOptimizerLatencyUs, *(qctx_->plan()->optimizeTimeInUs())); if (FLAGS_enable_space_level_metrics && spaceName != "") { @@ -214,6 +220,7 @@ void QueryInstance::addSlowQueryStats(uint64_t latency, const std::string &space } } +// Get result from query context and fill the response void QueryInstance::fillRespData(ExecutionResponse *resp) { auto ectx = DCHECK_NOTNULL(qctx_->ectx()); auto plan = DCHECK_NOTNULL(qctx_->plan()); @@ -223,7 +230,7 @@ void QueryInstance::fillRespData(ExecutionResponse *resp) { auto &&value = ectx->moveValue(name); if (!value.isDataSet()) return; - // fill dataset + // Fill dataset auto result = value.moveDataSet(); if (!result.colNames.empty()) { resp->data = std::make_unique(std::move(result)); @@ -234,6 +241,7 @@ void QueryInstance::fillRespData(ExecutionResponse *resp) { } } +// The entry point of the optimizer Status QueryInstance::findBestPlan() { auto plan = qctx_->plan(); SCOPED_TIMER(plan->optimizeTimeInUs()); diff --git a/src/graph/service/QueryInstance.h b/src/graph/service/QueryInstance.h index a702b41b7d9..5588999a4bb 100644 --- a/src/graph/service/QueryInstance.h +++ b/src/graph/service/QueryInstance.h @@ -29,6 +29,7 @@ class QueryInstance final : public boost::noncopyable, public cpp::NonMovable { QueryInstance(std::unique_ptr qctx, opt::Optimizer* optimizer); ~QueryInstance() = default; + // Entrance of the Validate, Optimize, Schedule, Execute process void execute(); QueryContext* qctx() const { @@ -51,7 +52,7 @@ class QueryInstance final : public boost::noncopyable, public cpp::NonMovable { void onError(Status); Status validateAndOptimize(); - // return true if continue to execute + // Return true if continue to execute bool explainOrContinue(); void addSlowQueryStats(uint64_t latency, const std::string& spaceName) const; void fillRespData(ExecutionResponse* resp); diff --git a/src/graph/service/RequestContext.h b/src/graph/service/RequestContext.h index ca0eb571ae7..2028401f7e7 100644 --- a/src/graph/service/RequestContext.h +++ b/src/graph/service/RequestContext.h @@ -34,7 +34,7 @@ class RequestContext final : public boost::noncopyable, public cpp::NonMovable { RequestContext() = default; ~RequestContext() { if (session_ != nullptr) { - // keep the session active + // Keep the session active session_->charge(); } } @@ -58,7 +58,7 @@ class RequestContext final : public boost::noncopyable, public cpp::NonMovable { void setSession(std::shared_ptr session) { session_ = std::move(session); if (session_ != nullptr) { - // keep the session active + // Keep the session active session_->charge(); } }