From 53be04c39c54ea3aa481dceaa63d410e208e5a61 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 9 Mar 2020 15:51:11 -0500 Subject: [PATCH] Don't lock tables by default; move tables around in schema; add peq-dump.sh script --- common/database/database_dump_service.cpp | 46 +++++++++++++++++----- common/database/database_dump_service.h | 27 +++++++------ common/database_schema.h | 17 ++++---- utils/sql/peq-dump/peq-dump.sh | 47 +++++++++++++++++++++++ world/world_server_command_handler.cpp | 6 ++- 5 files changed, 112 insertions(+), 31 deletions(-) create mode 100755 utils/sql/peq-dump/peq-dump.sh diff --git a/common/database/database_dump_service.cpp b/common/database/database_dump_service.cpp index f7a339c84..7610f3759 100644 --- a/common/database/database_dump_service.cpp +++ b/common/database/database_dump_service.cpp @@ -255,6 +255,10 @@ void DatabaseDumpService::Dump() return; } + if (IsDumpDropTableSyntaxOnly()) { + SetDumpOutputToConsole(true); + } + if (IsDumpOutputToConsole()) { LogSys.SilenceConsoleLogging(); } @@ -278,7 +282,7 @@ void DatabaseDumpService::Dump() options += " --no-data"; } - if (IsDumpNoTableLock()) { + if (!IsDumpTableLock()) { options += " --skip-lock-tables"; } @@ -336,9 +340,22 @@ void DatabaseDumpService::Dump() FileUtil::mkdir(GetSetDumpPath()); } - std::string execution_result = execute(execute_command, IsDumpOutputToConsole()); - if (!execution_result.empty()) { - std::cout << execution_result; + if (IsDumpDropTableSyntaxOnly()) { + std::vector tables = SplitString(tables_to_dump, ' '); + + for (auto &table : tables) { + std::cout << "DROP TABLE `" << table << "`;" << std::endl; + } + + if (tables_to_dump.empty()) { + std::cerr << "No tables were specified" << std::endl; + } + } + else { + std::string execution_result = execute(execute_command, IsDumpOutputToConsole()); + if (!execution_result.empty()) { + std::cout << execution_result; + } } if (!tables_to_dump.empty()) { @@ -439,14 +456,15 @@ void DatabaseDumpService::SetDumpAllTables(bool dump_all_tables) { DatabaseDumpService::dump_all_tables = dump_all_tables; } -bool DatabaseDumpService::IsDumpNoTableLock() const + +bool DatabaseDumpService::IsDumpTableLock() const { - return dump_no_table_lock; + return dump_table_lock; } -void DatabaseDumpService::SetDumpNoTableLock(bool dump_no_table_lock) +void DatabaseDumpService::SetDumpTableLock(bool dump_table_lock) { - DatabaseDumpService::dump_no_table_lock = dump_no_table_lock; + DatabaseDumpService::dump_table_lock = dump_table_lock; } bool DatabaseDumpService::IsDumpWithCompression() const @@ -497,4 +515,14 @@ bool DatabaseDumpService::IsDumpOutputToConsole() const void DatabaseDumpService::SetDumpOutputToConsole(bool dump_output_to_console) { DatabaseDumpService::dump_output_to_console = dump_output_to_console; -} \ No newline at end of file +} + +bool DatabaseDumpService::IsDumpDropTableSyntaxOnly() const +{ + return dump_drop_table_syntax_only; +} + +void DatabaseDumpService::SetDumpDropTableSyntaxOnly(bool dump_drop_table_syntax_only) +{ + DatabaseDumpService::dump_drop_table_syntax_only = dump_drop_table_syntax_only; +} diff --git a/common/database/database_dump_service.h b/common/database/database_dump_service.h index eb87520da..20f57e85c 100644 --- a/common/database/database_dump_service.h +++ b/common/database/database_dump_service.h @@ -37,8 +37,8 @@ public: void SetDumpPlayerTables(bool dump_player_tables); bool IsDumpLoginServerTables() const; void SetDumpLoginServerTables(bool dump_login_server_tables); - bool IsDumpNoTableLock() const; - void SetDumpNoTableLock(bool dump_no_table_lock); + bool IsDumpTableLock() const; + void SetDumpTableLock(bool dump_table_lock); bool IsDumpWithCompression() const; void SetDumpWithCompression(bool dump_with_compression); const std::string &GetDumpPath() const; @@ -49,18 +49,21 @@ public: void SetDumpQueryServerTables(bool dump_query_server_tables); bool IsDumpOutputToConsole() const; void SetDumpOutputToConsole(bool dump_output_to_console); + bool IsDumpDropTableSyntaxOnly() const; + void SetDumpDropTableSyntaxOnly(bool dump_drop_table_syntax_only); private: - bool dump_all_tables = false; - bool dump_system_tables = false; - bool dump_content_tables = false; - bool dump_player_tables = false; - bool dump_query_server_tables = false; - bool dump_login_server_tables = false; - bool dump_with_no_data = false; - bool dump_no_table_lock = false; - bool dump_with_compression = false; - bool dump_output_to_console = false; + bool dump_all_tables = false; + bool dump_system_tables = false; + bool dump_content_tables = false; + bool dump_player_tables = false; + bool dump_query_server_tables = false; + bool dump_login_server_tables = false; + bool dump_with_no_data = false; + bool dump_table_lock = false; + bool dump_with_compression = false; + bool dump_output_to_console = false; + bool dump_drop_table_syntax_only = false; std::string dump_path; std::string dump_file_name; diff --git a/common/database_schema.h b/common/database_schema.h index 5502441d0..40c9c39f1 100644 --- a/common/database_schema.h +++ b/common/database_schema.h @@ -85,7 +85,8 @@ namespace DatabaseSchema { } /** - * Gets all player and meta-data tables + * @description Gets all player and meta-data tables + * @note These tables have no content in the PEQ daily dump * * @return */ @@ -98,6 +99,8 @@ namespace DatabaseSchema { "account_rewards", "adventure_details", "adventure_stats", + "bugs", + "bug_reports", "buyer", "char_recipe_list", "character_activities", @@ -129,6 +132,8 @@ namespace DatabaseSchema { "character_tribute", "completed_tasks", "data_buckets", + "discovered_items", + "eventlog", "faction_values", "friends", "guild_bank", @@ -141,9 +146,12 @@ namespace DatabaseSchema { "inventory_snapshots", "keyring", "mail", + "petitions", "player_titlesets", "quest_globals", + "saylink", "sharedbank", + "reports", "timers", "titles", "trader", @@ -255,13 +263,9 @@ namespace DatabaseSchema { { return { "banned_ips", - "bugs", - "bug_reports", "command_settings", "db_str", - "discovered_items", "eqtime", - "eventlog", "gm_ips", "hackers", "ip_exemptions", @@ -271,12 +275,9 @@ namespace DatabaseSchema { "logsys_categories", "name_filter", "perl_event_export_settings", - "petitions", "profanity_list", - "reports", "rule_sets", "rule_values", - "saylink", "variables", }; } diff --git a/utils/sql/peq-dump/peq-dump.sh b/utils/sql/peq-dump/peq-dump.sh new file mode 100755 index 000000000..afcb63212 --- /dev/null +++ b/utils/sql/peq-dump/peq-dump.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +world_path="" + +if [ -d "bin" ] +then + world_path="bin/" +fi + +world_bin="${world_path}world" + +echo "World path is [$world_path] bin is [$world_bin]" + +# Run from the context of server directory +# +# --content-tables +# --login-tables +# --player-tables +# --system-tables +# --query-serv-tables + +############################################# +# dump +############################################# + +dump_path=/tmp/peq-dump/ + +mkdir -p ${dump_path} + +############################################# +# generate "drop_" table files +############################################# +bash -c "${world_bin} database:dump --content-tables --drop-table-syntax-only --dump-output-to-console > ${dump_path}drop_tables_content.sql" +bash -c "${world_bin} database:dump --login-tables --drop-table-syntax-only --dump-output-to-console > ${dump_path}drop_tables_login.sql" +bash -c "${world_bin} database:dump --player-tables --drop-table-syntax-only --dump-output-to-console > ${dump_path}drop_tables_player.sql" +bash -c "${world_bin} database:dump --system-tables --drop-table-syntax-only --dump-output-to-console > ${dump_path}drop_tables_system.sql" +bash -c "${world_bin} database:dump --query-serv-tables --drop-table-syntax-only --dump-output-to-console > ${dump_path}drop_tables_queryserv.sql" + +############################################# +# generate "create_" table files +############################################# +bash -c "${world_bin} database:dump --content-tables --dump-output-to-console > ${dump_path}create_tables_content.sql" +bash -c "${world_bin} database:dump --login-tables --table-structure-only --dump-output-to-console > ${dump_path}create_tables_login.sql" +bash -c "${world_bin} database:dump --player-tables --table-structure-only --dump-output-to-console > ${dump_path}create_tables_player.sql" +bash -c "${world_bin} database:dump --system-tables --dump-output-to-console > ${dump_path}create_tables_system.sql" +bash -c "${world_bin} database:dump --query-serv-tables --table-structure-only --dump-output-to-console > ${dump_path}create_tables_queryserv.sql" + diff --git a/world/world_server_command_handler.cpp b/world/world_server_command_handler.cpp index 32e794800..5ccbf167c 100644 --- a/world/world_server_command_handler.cpp +++ b/world/world_server_command_handler.cpp @@ -227,9 +227,10 @@ namespace WorldserverCommandHandler { "--system-tables", "--query-serv-tables", "--table-structure-only", - "--no-table-lock", + "--table-lock", "--dump-path=", "--dump-output-to-console", + "--drop-table-syntax-only", "--compress" }; @@ -256,9 +257,10 @@ namespace WorldserverCommandHandler { database_dump_service->SetDumpWithNoData(cmd[{"-c", "--table-structure-only"}]); database_dump_service->SetDumpQueryServerTables(cmd[{"--query-serv-tables"}]); database_dump_service->SetDumpAllTables(dump_all); - database_dump_service->SetDumpNoTableLock(cmd[{"--no-table-lock"}]); + database_dump_service->SetDumpTableLock(cmd[{"--table-lock"}]); database_dump_service->SetDumpWithCompression(cmd[{"--compress"}]); database_dump_service->SetDumpOutputToConsole(cmd[{"--dump-output-to-console"}]); + database_dump_service->SetDumpDropTableSyntaxOnly(cmd[{"--drop-table-syntax-only"}]); /** * Dump