From 5632852890803561e9d22d69946813975f70b02e Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Tue, 17 Mar 2020 11:06:43 +0100 Subject: [PATCH] Reduce number of errors in production log Summary: Currently, when starting Memgraph with the production package (DEB/RPM), Memgraph always outputs an error for not being able to replace an existing query module (`example.so` with `example.c`). This diff introduces a precheck so that the error message is correct - so that Memgraph doesn't try to replace an `.so` file with a `.c` file before verifying that the `.c` file is a valid query module (which it obviously isn't). Also, I have moved the source of the example into a subdirectory so that it isn't even considered while loading modules. Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2724 --- query_modules/CMakeLists.txt | 2 +- src/query/procedure/module.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/query_modules/CMakeLists.txt b/query_modules/CMakeLists.txt index 022eb8710..7a474a66a 100644 --- a/query_modules/CMakeLists.txt +++ b/query_modules/CMakeLists.txt @@ -25,7 +25,7 @@ install(PROGRAMS $ DESTINATION lib/memgraph/query_modules RENAME example.so) # Also install the source of the example, so user can read it. -install(FILES example.c DESTINATION lib/memgraph/query_modules) +install(FILES example.c DESTINATION lib/memgraph/query_modules/src) # Install the Python example install(FILES example.py DESTINATION lib/memgraph/query_modules RENAME py_example.py) diff --git a/src/query/procedure/module.cpp b/src/query/procedure/module.cpp index 4d0ed6772..899517f41 100644 --- a/src/query/procedure/module.cpp +++ b/src/query/procedure/module.cpp @@ -403,6 +403,10 @@ ModuleRegistry::ModuleRegistry() { bool ModuleRegistry::LoadModuleLibrary(std::filesystem::path path) { std::unique_lock guard(lock_); std::string module_name(path.stem()); + if (path.extension() != ".so" && path.extension() != ".py") { + LOG(WARNING) << "Unknown query module file " << path; + return false; + } if (modules_.find(module_name) != modules_.end()) { LOG(ERROR) << "Unable to overwrite an already loaded module " << path; return false; @@ -418,7 +422,8 @@ bool ModuleRegistry::LoadModuleLibrary(std::filesystem::path path) { if (!loaded) return false; modules_[module_name] = std::move(module); } else { - LOG(ERROR) << "Unknown query module file " << path; + LOG(FATAL) << "Unknown query module extension '" << path.extension() + << "' from file " << path; return false; } return true;