Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
21944b9
feat(metadata-db): Replace YAML config with env vars and CLI args (re…
junhaoliao Jul 31, 2025
bbce2fc
fix lint
junhaoliao Jul 31, 2025
849b6b4
fix lint
junhaoliao Aug 1, 2025
5806785
fix typo
junhaoliao Aug 1, 2025
144f74a
remove trailing space
junhaoliao Aug 1, 2025
eece9aa
remove trailing spaces
junhaoliao Aug 1, 2025
6d534b3
Apply rabbit suggestion on - docs/src/user-guide/core-unstructured/cl…
junhaoliao Aug 1, 2025
0cd45e3
rabbit suggestion - Update docs/src/user-guide/core-unstructured/clp.md
junhaoliao Aug 1, 2025
cb43f62
Remove unused `using std::exception` - Apply suggestion from @gibber9809
junhaoliao Aug 1, 2025
8ea2f0a
Docs - Apply suggestion from @gibber9809
junhaoliao Aug 1, 2025
90353c1
Remove trailing comma in arg list - Apply suggestion from @gibber9809
junhaoliao Aug 1, 2025
d4c17f4
refactor: Change add_command_line_options from static to instance met…
junhaoliao Aug 1, 2025
d3d2146
fix lint
junhaoliao Aug 1, 2025
a0687a5
test: Add credential reading from environment in validation tests
junhaoliao Aug 1, 2025
1bc0502
refactor: Introduce constants for minimum and maximum port values in …
junhaoliao Aug 1, 2025
690e035
lint: Remove GlobalMetadataDBConfig.cpp exception from lint configura…
junhaoliao Aug 1, 2025
e3a24b0
refactor: Improve error message formatting for database port range va…
junhaoliao Aug 1, 2025
de68007
refactor: Update minimum port value in GlobalMetadataDBConfig to 1
junhaoliao Aug 1, 2025
d21506b
Merge branch 'main' into db-params
junhaoliao Aug 1, 2025
1647e0b
Remove redundant spaces in arg list - Apply suggestion from @coderabb…
junhaoliao Aug 3, 2025
04923b8
Use fmt for log messages - Update components/core/src/clp/GlobalMetad…
junhaoliao Aug 3, 2025
aedebe1
perform mysql db type check before further parsing from env
junhaoliao Aug 3, 2025
5dc87d1
refactor: Skip credential reading for SQLite database type
junhaoliao Aug 3, 2025
968221c
rename read_credentials_from_env -> read_credentials_from_env_if_needed
junhaoliao Aug 3, 2025
cae4ce5
early return
junhaoliao Aug 3, 2025
aedca2b
reorder m_metadata_table_prefix
junhaoliao Aug 3, 2025
9c63298
docs: add exception detail to validate method documentation
junhaoliao Aug 3, 2025
47fb5d2
refactor: enhance validation for SQLite database parameters
junhaoliao Aug 3, 2025
54e3483
move consts to anonymous namespace; use consts for metadata db type s…
junhaoliao Aug 4, 2025
e39e1d7
update SQLite validation to check for default values
junhaoliao Aug 4, 2025
7b39750
update tests
junhaoliao Aug 4, 2025
2ba751d
lint
junhaoliao Aug 4, 2025
87cc885
Merge branch 'main' into db-params
junhaoliao Aug 5, 2025
1aa27fe
docs - Update docs/src/user-guide/core-unstructured/clp.md
junhaoliao Aug 6, 2025
dc0c899
refactor(core): make metadata DB password optional
junhaoliao Aug 6, 2025
a4fd245
test(core): add more unit tests for SQLite database configuration val…
junhaoliao Aug 6, 2025
ea9765f
test(core): add additional validation tests for GlobalMetadataDBConfig
junhaoliao Aug 6, 2025
06bc482
refactor(core): Change the return type of parse_args function from va…
junhaoliao Aug 6, 2025
eba4952
Merge branch 'main' into db-params
junhaoliao Aug 6, 2025
b06d71a
Docs - Update components/core/src/clp/GlobalMetadataDBConfig.cpp
junhaoliao Aug 7, 2025
e647fcf
Exception message - Apply suggestions from code review
junhaoliao Aug 7, 2025
ba0c2c5
Docs - Apply suggestions from code review
junhaoliao Aug 7, 2025
3745ca2
Docs - Apply suggestions from code review
junhaoliao Aug 7, 2025
fe3115c
style - Apply suggestions from code review
junhaoliao Aug 7, 2025
015f583
style - Apply suggestions from code review
junhaoliao Aug 7, 2025
67f2d49
style - Apply suggestions from code review
junhaoliao Aug 7, 2025
bec5805
Use `.at()` to access array - Apply suggestions from code review
junhaoliao Aug 7, 2025
aab68bf
build(core): remove CLP_NEED_YAMLCPP from set_clp_tests_dependencies
junhaoliao Aug 7, 2025
6279484
style(core): suppress clang-format and fix style
junhaoliao Aug 7, 2025
230629e
Move table_prefix variable declaration to minimize scope
junhaoliao Aug 7, 2025
dfde4fa
remove default values from metadata DB config descriptions
junhaoliao Aug 7, 2025
ae6d1e0
refactor(core): move global metadata DB config constants
junhaoliao Aug 7, 2025
667dce6
Move GlobalMetadataDBConfig initialization to constructor
junhaoliao Aug 7, 2025
57cf478
suppress clang-format; use string() instead of string_view::data() fo…
junhaoliao Aug 7, 2025
0f6ca85
Update GlobalMetadataDBConfig to use optional<string> for username an…
junhaoliao Aug 7, 2025
8df0d2f
update CLP database initialization documentation to remove default va…
junhaoliao Aug 7, 2025
f07d036
fix compile issue
junhaoliao Aug 7, 2025
3e7637c
Merge branch 'main' into db-params
junhaoliao Aug 7, 2025
7f52c1f
fit clang-tidy issues in test-GlobalMetadataDBConfig.cpp
junhaoliao Aug 8, 2025
8f6aaf9
fit clang-tidy issues in GlobalMetadataDBConfig.cpp
junhaoliao Aug 8, 2025
e154899
Docs - Apply suggestions from code review
junhaoliao Aug 11, 2025
85e00ce
rename to improve clarity of database connection functions
junhaoliao Aug 11, 2025
4e829ff
Change mysql-only options desc prefix - Apply suggestions from code r…
junhaoliao Aug 11, 2025
8c0ff24
Reformat - Apply suggestions from code review
junhaoliao Aug 11, 2025
ba9a0ac
Docs - Apply suggestions from code review
junhaoliao Aug 11, 2025
91fe771
Use init list for declartion - Apply suggestions from code review
junhaoliao Aug 11, 2025
179df88
Improve exception messages - Apply suggestions from code review
junhaoliao Aug 11, 2025
d7e6afb
Avoid inline comment & add rationale for lint suppression - Apply sug…
junhaoliao Aug 11, 2025
04c30ea
Use NOLINTNEXTLINE comment to suppress the concurrency-mt-unsafe warning
junhaoliao Aug 11, 2025
9648484
refactor: Move GlobalMetadataDBConfig default values to class scope
junhaoliao Aug 11, 2025
1b9d318
revert indentation change
junhaoliao Aug 11, 2025
c9834f3
remove redundant exception handling for metadata DB config validation
junhaoliao Aug 11, 2025
4971191
move global metadata DB config constants back into cpp
junhaoliao Aug 11, 2025
edb6810
revert indent change and suppress clang-format
junhaoliao Aug 11, 2025
20c61a6
add a default case to the get_metadata_db_type switch statement
junhaoliao Aug 11, 2025
71ed500
remove redudant namespace scope - Apply suggestions from code review
junhaoliao Aug 11, 2025
e3eecde
ensure MySQL credentials are provided for global metadata DB
junhaoliao Aug 11, 2025
b8cbe0a
docs: add exception documentation to function comments
junhaoliao Aug 11, 2025
7d1a273
test(core): rename test argc & argv to PascalCase
junhaoliao Aug 11, 2025
baf993f
lint
junhaoliao Aug 11, 2025
399e1bd
remove unnecessary const_cast in test-GlobalMetadataDBConfig
junhaoliao Aug 11, 2025
a686b54
add missing braces for MySQL case in switch statements
junhaoliao Aug 11, 2025
b2ad166
lint
junhaoliao Aug 11, 2025
e0a6ecc
Use `.value()` to get optional value instead of dereference - Apply s…
junhaoliao Aug 11, 2025
ea08810
Use `.value()` to get optional value instead of dereference - Apply s…
junhaoliao Aug 11, 2025
e14eb39
remove exception handling for metadata database config validation
junhaoliao Aug 11, 2025
a03cf80
test: DRY unset_env_var
junhaoliao Aug 11, 2025
dbe94d3
avoid inline comments
junhaoliao Aug 11, 2025
9cf11c3
lint
junhaoliao Aug 11, 2025
510bf1e
Merge branch 'main' into db-params
junhaoliao Aug 11, 2025
26f9a56
fix(core): improve global metadata DB config validation
junhaoliao Aug 11, 2025
b886c33
use constant strings for mysql and sqlite
junhaoliao Aug 11, 2025
2c10dbb
Use if-initializer syntax to simplify null checks for environment var…
junhaoliao Aug 11, 2025
69b99da
fix(core): update MySQL db type reference in global metadata DB config
junhaoliao Aug 11, 2025
9d5c7ab
test(core): refactor GlobalMetadataDBConfig tests
junhaoliao Aug 11, 2025
5156dc9
refactor: rename MySQL-related variables and options
junhaoliao Aug 11, 2025
f2855e4
Merge branch 'main' into db-params
junhaoliao Aug 11, 2025
9600944
refactor: rename MySQL-related variables as `mysql` rather than `mySql`
junhaoliao Aug 11, 2025
00b22b8
refactor: rename command line argument arrays with `argv`
junhaoliao Aug 11, 2025
b368802
rename `argV`/`argC` back to `argv` / `argc`
junhaoliao Aug 11, 2025
e524ed7
Extract config -> global metadata DB creation into utility function; …
kirkrodrigues Aug 13, 2025
9807fb2
IndexManager: Refactor error handling and add missing parameters to d…
kirkrodrigues Aug 13, 2025
4a2790e
test-GlobalMetadataDBConfig: Use existing constants rather than dupli…
kirkrodrigues Aug 13, 2025
ab36b4d
Refactor docs.
kirkrodrigues Aug 13, 2025
2cb4751
Fix docs error.
kirkrodrigues Aug 13, 2025
602436b
Fix clang-tidy errors I introduced.
kirkrodrigues Aug 13, 2025
e93131b
Remove unnecessary default value.
kirkrodrigues Aug 13, 2025
87c3524
Fix pre-existing clang-tidy issues.
kirkrodrigues Aug 13, 2025
7ccf42e
Fix unit tests failure.
kirkrodrigues Aug 13, 2025
f605611
Document return correctly.
kirkrodrigues Aug 13, 2025
32b06fe
Doc tweaks.
kirkrodrigues Aug 13, 2025
e2ca0b8
Apply suggestions from code review
kirkrodrigues Aug 13, 2025
e7fd723
Wrap to 100 chars.
kirkrodrigues Aug 13, 2025
0ac028e
Merge remote-tracking branch 'origin/main' into db-params
junhaoliao Aug 13, 2025
5267b9f
Update components/core/src/clp/clp/compression.cpp
kirkrodrigues Aug 13, 2025
a54eae2
Merge branch 'main' into db-params
davidlion Aug 14, 2025
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
4 changes: 3 additions & 1 deletion components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ set(SOURCE_FILES_unitTest
src/clp/FileReader.hpp
src/clp/FileWriter.cpp
src/clp/FileWriter.hpp
src/clp/global_metadata_db_utils.hpp
src/clp/global_metadata_db_utils.cpp
src/clp/GlobalMetadataDB.hpp
src/clp/GlobalMetadataDBConfig.cpp
src/clp/GlobalMetadataDBConfig.hpp
Expand Down Expand Up @@ -708,6 +710,7 @@ set(SOURCE_FILES_unitTest
tests/test-ffi_KeyValuePairLogEvent.cpp
tests/test-ffi_SchemaTree.cpp
tests/test-FileDescriptorReader.cpp
tests/test-GlobalMetadataDBConfig.cpp
tests/test-GrepCore.cpp
tests/test-hash_utils.cpp
tests/test-ir_encoding_methods.cpp
Expand Down Expand Up @@ -766,7 +769,6 @@ if(CLP_BUILD_TESTING)
${STD_FS_LIBS}
clp::regex_utils
clp::string_utils
yaml-cpp
Comment thread
kirkrodrigues marked this conversation as resolved.
ystdlib::containers
ystdlib::error_handling
${LIBLZMA_LIBRARIES}
Expand Down
1 change: 0 additions & 1 deletion components/core/cmake/Options/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function(set_clp_tests_dependencies)
CLP_NEED_SIMDJSON
CLP_NEED_SPDLOG
CLP_NEED_SQLITE
CLP_NEED_YAMLCPP
CLP_NEED_YSTDLIB
CLP_NEED_ZSTD
)
Expand Down
10 changes: 0 additions & 10 deletions components/core/config/metadata-db.yml

This file was deleted.

249 changes: 162 additions & 87 deletions components/core/src/clp/GlobalMetadataDBConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,110 +1,185 @@
#include "GlobalMetadataDBConfig.hpp"

#include <cstdlib>
#include <istream>
#include <stdexcept>
#include <string>
#include <string_view>

#include <boost/program_options/options_description.hpp>
#include <boost/program_options/value_semantic.hpp>
#include <fmt/core.h>
#include <yaml-cpp/yaml.h>

using std::exception;
#include "GlobalMySQLMetadataDB.hpp"
#include "type_utils.hpp"
Comment thread
junhaoliao marked this conversation as resolved.

using std::invalid_argument;
using std::string;

static exception get_yaml_missing_key_exception(string const& key_name) {
throw invalid_argument(fmt::format("Missing key '{}'", key_name));
namespace {
// Constants
constexpr clp::GlobalMetadataDBConfig::MetadataDBType cDefaultMetadataDbType{
clp::GlobalMetadataDBConfig::MetadataDBType::SQLite
};
constexpr std::string_view cDefaultMetadataDbHost{"127.0.0.1"};
constexpr int cDefaultMetadataDbPort{3306};
constexpr std::string_view cDefaultMetadataDbName{"clp-db"};
constexpr std::string_view cDefaultMetadataTablePrefix{"clp_"};
constexpr int cMinPort{1};
constexpr int cMaxPort{65'535};
} // namespace

namespace clp {
auto operator>>(std::istream& in, GlobalMetadataDBConfig::MetadataDBType& metadata_db_type)
-> std::istream& {
string db_type_string;
in >> db_type_string;

for (size_t i = 0; i < GlobalMetadataDBConfig::cMetadataDBTypeNames.size(); ++i) {
if (GlobalMetadataDBConfig::cMetadataDBTypeNames.at(i) == db_type_string) {
metadata_db_type = static_cast<GlobalMetadataDBConfig::MetadataDBType>(i);
return in;
}
}

throw invalid_argument(fmt::format("Unknown database type: {}", db_type_string));
}
Comment on lines +38 to 46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Optional: replace linear scan with a small lookup map.

Not critical given two types, but a map avoids iteration and reads more declaratively.

-    for (size_t i = 0; i < GlobalMetadataDBConfig::cMetadataDBTypeNames.size(); ++i) {
-        if (GlobalMetadataDBConfig::cMetadataDBTypeNames.at(i) == db_type_string) {
-            metadata_db_type = static_cast<GlobalMetadataDBConfig::MetadataDBType>(i);
-            return in;
-        }
-    }
+    static const std::unordered_map<std::string, GlobalMetadataDBConfig::MetadataDBType> kMap{
+        {std::string(GlobalMetadataDBConfig::cMetadataDBTypeNames[enum_to_underlying_type(GlobalMetadataDBConfig::MetadataDBType::SQLite)]),
+         GlobalMetadataDBConfig::MetadataDBType::SQLite},
+        {std::string(GlobalMetadataDBConfig::cMetadataDBTypeNames[enum_to_underlying_type(GlobalMetadataDBConfig::MetadataDBType::MySQL)]),
+         GlobalMetadataDBConfig::MetadataDBType::MySQL},
+    };
+    if (auto it = kMap.find(db_type_string); it != kMap.end()) {
+        metadata_db_type = it->second;
+        return in;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (size_t i = 0; i < GlobalMetadataDBConfig::cMetadataDBTypeNames.size(); ++i) {
if (GlobalMetadataDBConfig::cMetadataDBTypeNames.at(i) == db_type_string) {
metadata_db_type = static_cast<GlobalMetadataDBConfig::MetadataDBType>(i);
return in;
}
}
throw invalid_argument(fmt::format("Unknown database type: {}", db_type_string));
}
static const std::unordered_map<std::string, GlobalMetadataDBConfig::MetadataDBType> kMap{
{std::string(GlobalMetadataDBConfig::cMetadataDBTypeNames[enum_to_underlying_type(GlobalMetadataDBConfig::MetadataDBType::SQLite)]),
GlobalMetadataDBConfig::MetadataDBType::SQLite},
{std::string(GlobalMetadataDBConfig::cMetadataDBTypeNames[enum_to_underlying_type(GlobalMetadataDBConfig::MetadataDBType::MySQL)]),
GlobalMetadataDBConfig::MetadataDBType::MySQL},
};
if (auto it = kMap.find(db_type_string); it != kMap.end()) {
metadata_db_type = it->second;
return in;
}
throw invalid_argument(fmt::format("Unknown database type: {}", db_type_string));
}
🤖 Prompt for AI Agents
In components/core/src/clp/GlobalMetadataDBConfig.cpp around lines 37 to 45, the
code currently does a linear scan over cMetadataDBTypeNames to map
db_type_string to MetadataDBType; replace that loop with a small static lookup
(e.g., a static const std::unordered_map<std::string,
GlobalMetadataDBConfig::MetadataDBType> initialized from cMetadataDBTypeNames),
then use map.find(db_type_string) to set metadata_db_type and return in; if not
found, throw the same invalid_argument(fmt::format(...)). Add #include
<unordered_map> and ensure the map is initialized once (static const) to avoid
repeated construction.


static exception
get_yaml_unconvertable_value_exception(string const& key_name, string const& destination_type) {
throw invalid_argument(
fmt::format("'{}' could not be converted to type '{}'", key_name, destination_type)
);
GlobalMetadataDBConfig::GlobalMetadataDBConfig(
boost::program_options::options_description& options_description
) {
std::string_view const cMetadataDbTypeMysqlOptDescPrefix{fmt::format(
"(--db-type={} only)",
cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::MySQL)]
)};

// clang-format off
options_description.add_options()
Comment thread
haiqi96 marked this conversation as resolved.
Comment thread
kirkrodrigues marked this conversation as resolved.
(
"db-type",
boost::program_options::value<MetadataDBType>(&m_metadata_db_type)
->default_value(
cDefaultMetadataDbType,
string(
cMetadataDBTypeNames[
enum_to_underlying_type(cDefaultMetadataDbType)
]
)
),
fmt::format(
"Database type [{} | {}]",
cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::SQLite)],
cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::MySQL)]
).c_str()
)
(
"db-host",
boost::program_options::value<string>(&m_metadata_db_host)
->default_value(string(cDefaultMetadataDbHost)),
fmt::format(
"{} Database host",
cMetadataDbTypeMysqlOptDescPrefix
).c_str()
)
(
"db-port",
boost::program_options::value<int>(&m_metadata_db_port)
->default_value(cDefaultMetadataDbPort),
fmt::format(
"{} Database port",
cMetadataDbTypeMysqlOptDescPrefix
).c_str()
)
(
"db-name",
boost::program_options::value<string>(&m_metadata_db_name)
->default_value(string(cDefaultMetadataDbName)),
fmt::format(
"{} Database name",
cMetadataDbTypeMysqlOptDescPrefix
).c_str()
)
(
"db-table-prefix",
boost::program_options::value<string>(&m_metadata_table_prefix)
->default_value(string(cDefaultMetadataTablePrefix)),
fmt::format(
"{} Database table prefix",
cMetadataDbTypeMysqlOptDescPrefix
).c_str()
);
// clang-format on
}

namespace clp {
void GlobalMetadataDBConfig::parse_config_file(string const& config_file_path) {
YAML::Node config = YAML::LoadFile(config_file_path);
auto GlobalMetadataDBConfig::read_credentials_from_env_if_needed() -> void {
if (MetadataDBType::SQLite == m_metadata_db_type) {
// SQLite doesn't require extra parameters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Minor: Inconsistent comment style with contraction

For consistency with professional documentation style, consider using "does not" instead of "doesn't" in the comments.

-        // SQLite doesn't require extra parameters.
+        // SQLite does not require extra parameters.

Also applies to: 135-135

🤖 Prompt for AI Agents
In components/core/src/clp/GlobalMetadataDBConfig.cpp around lines 116 and 135,
the comment uses the contraction "doesn't"; replace it with the expanded form
"does not" in both places to maintain consistent, professional comment style.

return;
}
Comment on lines +114 to +118

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Minor wording consistency in comments.

Prefer “does not” over “doesn't” for consistency.

-        // SQLite doesn't require extra parameters.
+        // SQLite does not require extra parameters.

(Apply in both locations.)

Also applies to: 131-134

🤖 Prompt for AI Agents
In components/core/src/clp/GlobalMetadataDBConfig.cpp around lines 110-114 and
131-134, update the comment wording to use “does not” instead of the contraction
“doesn't” for consistency; modify both comment instances so they read “SQLite
does not require extra parameters.” (No code logic changes needed, only replace
the contraction in those comment lines.)


Comment on lines +114 to 119

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consistency nit: prefer “does not” over “doesn't” in comments.

Keep comment tone consistent throughout the file.

-        // SQLite doesn't require extra parameters.
+        // SQLite does not require extra parameters.

(Apply similarly at Line 134.)

Also applies to: 132-147

🤖 Prompt for AI Agents
components/core/src/clp/GlobalMetadataDBConfig.cpp lines 115-120 (and similarly
at line 134 and the range 132-147): comments use the contraction "doesn't" —
update these comments to use "does not" for consistent tone across the file;
scan nearby comment lines in the given ranges and replace any other contractions
to match the preferred style.

if (!config["type"]) {
throw get_yaml_missing_key_exception("type");
// Silence the check since this class won't be used in a multithreaded context.
// NOLINTNEXTLINE(concurrency-mt-unsafe)
if (auto const* db_username{std::getenv("CLP_DB_USER")}; nullptr != db_username) {
m_metadata_db_username.emplace(db_username);
}

auto db_type_string = config["type"].as<string>();
if ("sqlite" == db_type_string) {
m_metadata_db_type = MetadataDBType::SQLite;
} else if ("mysql" == db_type_string) {
m_metadata_db_type = MetadataDBType::MySQL;
// Silence the check since this class won't be used in a multithreaded context.
// NOLINTNEXTLINE(concurrency-mt-unsafe)
if (auto const* db_password{std::getenv("CLP_DB_PASS")}; nullptr != db_password) {
m_metadata_db_password.emplace(db_password);
}
}

if (!config["host"]) {
throw get_yaml_missing_key_exception("host");
}
try {
m_metadata_db_host = config["host"].as<string>();
} catch (YAML::BadConversion& e) {
throw get_yaml_unconvertable_value_exception("host", "string");
}
if (m_metadata_db_host.empty()) {
throw invalid_argument("Database 'host' not specified or empty.");
}
auto GlobalMetadataDBConfig::validate() const -> void {
if (m_metadata_db_type == MetadataDBType::SQLite) {
// SQLite doesn't require extra parameters.
if (cDefaultMetadataDbHost != m_metadata_db_host
|| cDefaultMetadataDbPort != m_metadata_db_port
|| cDefaultMetadataDbName != m_metadata_db_name
|| cDefaultMetadataTablePrefix != m_metadata_table_prefix
|| m_metadata_db_username.has_value() || m_metadata_db_password.has_value())
{
throw invalid_argument(
fmt::format(
"MySQL-specific parameters cannot be used with --db-type={}."
" Please remove them or set '--db-type={}'.",
cMetadataDBTypeNames[enum_to_underlying_type(m_metadata_db_type)],
cMetadataDBTypeNames[enum_to_underlying_type(MetadataDBType::MySQL)]
)
);
}
return;
}

if (!config["port"]) {
throw get_yaml_missing_key_exception("port");
}
try {
m_metadata_db_port = config["port"].as<int>();
} catch (YAML::BadConversion& e) {
throw get_yaml_unconvertable_value_exception("port", "int");
}
if (m_metadata_db_port < 0) {
throw invalid_argument("Database 'port' cannot be negative.");
}
if (m_metadata_db_host.empty()) {
throw invalid_argument("Database '--db-host' is empty.");
}

if (!config["name"]) {
throw get_yaml_missing_key_exception("name");
}
try {
m_metadata_db_name = config["name"].as<string>();
} catch (YAML::BadConversion& e) {
throw get_yaml_unconvertable_value_exception("name", "string");
}
if (m_metadata_db_name.empty()) {
throw invalid_argument("Database 'name' not specified or empty.");
}
if (cMinPort > m_metadata_db_port || cMaxPort < m_metadata_db_port) {
throw invalid_argument(
fmt::format(
"Database '--db-port' is out of range [{}, {}]: {}",
cMinPort,
cMaxPort,
m_metadata_db_port
)
);
}

if (!config["username"]) {
throw get_yaml_missing_key_exception("username");
}
try {
m_metadata_db_username = config["username"].as<string>();
} catch (YAML::BadConversion& e) {
throw get_yaml_unconvertable_value_exception("username", "string");
}
if (m_metadata_db_username.empty()) {
throw invalid_argument("Database 'username' not specified or empty.");
}
if (m_metadata_db_name.empty()) {
throw invalid_argument("Database '--db-name' is empty.");
}

if (!config["password"]) {
throw get_yaml_missing_key_exception("password");
}
try {
m_metadata_db_password = config["password"].as<string>();
} catch (YAML::BadConversion& e) {
throw get_yaml_unconvertable_value_exception("password", "string");
}
if (m_metadata_db_password.empty()) {
throw invalid_argument("Database 'password' not specified or empty.");
}
if (m_metadata_table_prefix.empty()) {
throw invalid_argument("Database '--db-table_prefix' is empty.");
}

if (!config["table_prefix"]) {
throw get_yaml_missing_key_exception("table_prefix");
}
try {
m_metadata_table_prefix = config["table_prefix"].as<string>();
} catch (YAML::BadConversion& e) {
throw get_yaml_unconvertable_value_exception("table_prefix", "string");
}
if (m_metadata_table_prefix.empty()) {
throw invalid_argument("Database 'table_prefix' not specified or empty.");
}
} else {
throw invalid_argument("Unknown type");
if (false == m_metadata_db_username.has_value()) {
throw invalid_argument("Environment variable 'CLP_DB_USER' not set.");
}

if (false == m_metadata_db_password.has_value()) {
throw invalid_argument("Environment variable 'CLP_DB_PASS' not set.");
}
}
} // namespace clp
Loading
Loading