From 55161e18c8fb3ea8633e23bb974e22336d47ea81 Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Mon, 31 Jul 2023 19:58:57 -0500 Subject: [PATCH] [Databuckets] Improvements to distributed cache, reload commands (#3519) * [Databuckets] Improvements to distributed cache, reload commands * Add to reload_types --- common/servertalk.h | 1 + world/eqemu_api_world_data_service.cpp | 1 + world/zoneserver.cpp | 1 + zone/client.cpp | 13 +++++++++- zone/data_bucket.cpp | 36 ++++++++++++++++---------- zone/data_bucket.h | 1 + zone/gm_commands/reload.cpp | 5 ++++ zone/worldserver.cpp | 6 +++++ 8 files changed, 49 insertions(+), 15 deletions(-) diff --git a/common/servertalk.h b/common/servertalk.h index 7a4edca88..36d730815 100644 --- a/common/servertalk.h +++ b/common/servertalk.h @@ -249,6 +249,7 @@ #define ServerOP_ReloadZonePoints 0x4122 #define ServerOP_ReloadDzTemplates 0x4123 #define ServerOP_ReloadZoneData 0x4124 +#define ServerOP_ReloadDataBucketsCache 0x4125 #define ServerOP_CZDialogueWindow 0x4500 #define ServerOP_CZLDoNUpdate 0x4501 diff --git a/world/eqemu_api_world_data_service.cpp b/world/eqemu_api_world_data_service.cpp index 1fff092c8..9ef402383 100644 --- a/world/eqemu_api_world_data_service.cpp +++ b/world/eqemu_api_world_data_service.cpp @@ -138,6 +138,7 @@ std::vector reload_types = { Reload{.command = "alternate_currencies", .opcode = ServerOP_ReloadAlternateCurrencies, .desc = "Alternate Currencies"}, Reload{.command = "blocked_spells", .opcode = ServerOP_ReloadBlockedSpells, .desc = "Blocked Spells"}, Reload{.command = "commands", .opcode = ServerOP_ReloadCommands, .desc = "Commands"}, + Reload{.command = "data_buckets_cache", .opcode = ServerOP_ReloadDataBucketsCache, .desc = "Data Buckets Cache"}, Reload{.command = "doors", .opcode = ServerOP_ReloadDoors, .desc = "Doors"}, Reload{.command = "dztemplates", .opcode = ServerOP_ReloadDzTemplates, .desc = "Dynamic Zone Templates"}, Reload{.command = "ground_spawns", .opcode = ServerOP_ReloadGroundSpawns, .desc = "Ground Spawns"}, diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index d1e1d45a1..8ccc26cb4 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -1343,6 +1343,7 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { case ServerOP_ReloadBlockedSpells: case ServerOP_ReloadCommands: case ServerOP_ReloadDoors: + case ServerOP_ReloadDataBucketsCache: case ServerOP_ReloadGroundSpawns: case ServerOP_ReloadLevelEXPMods: case ServerOP_ReloadMerchants: diff --git a/zone/client.cpp b/zone/client.cpp index 9e128a164..4c39d4c88 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -8883,7 +8883,8 @@ void Client::ShowDevToolsMenu() menu_reload_two += Saylink::Silent("#reload commands", "Commands"); menu_reload_two += " | " + Saylink::Silent("#reload content_flags", "Content Flags"); - menu_reload_three += Saylink::Silent("#reload doors", "Doors"); + menu_reload_three += Saylink::Silent("#reload data_buckets_cache", "Databuckets"); + menu_reload_three += " | " + Saylink::Silent("#reload doors", "Doors"); menu_reload_three += " | " + Saylink::Silent("#reload ground_spawns", "Ground Spawns"); menu_reload_four += Saylink::Silent("#reload logs", "Level Based Experience Modifiers"); @@ -10837,6 +10838,16 @@ void Client::SendReloadCommandMessages() { ).c_str() ); + auto data_buckets_link = Saylink::Silent("#reload data_buckets_cache"); + + Message( + Chat::White, + fmt::format( + "Usage: {} - Reloads data buckets cache globally", + data_buckets_link + ).c_str() + ); + auto dztemplates_link = Saylink::Silent("#reload dztemplates"); Message(Chat::White, fmt::format("Usage: {} - Reloads Dynamic Zone Templates globally", dztemplates_link).c_str()); diff --git a/zone/data_bucket.cpp b/zone/data_bucket.cpp index c7e98acfd..9e026d8b4 100644 --- a/zone/data_bucket.cpp +++ b/zone/data_bucket.cpp @@ -551,6 +551,8 @@ void DataBucket::HandleWorldMessage(ServerPacket *p) // delete if (n.update_action == DataBucketCacheUpdateAction::Delete) { + DeleteFromMissesCache(n.e); + g_data_bucket_cache.erase( std::remove_if( g_data_bucket_cache.begin(), @@ -577,23 +579,23 @@ void DataBucket::HandleWorldMessage(ServerPacket *p) // update bool has_key = false; - for (auto &ce: g_data_bucket_cache) { - int64 time_delta = ce.updated_time - n.updated_time; - if (ce.updated_time >= n.updated_time) { - LogDataBuckets( - "Attempted to update older cache key [{}] rejecting old time [{}] new time [{}] delta [{}] cache_size [{}]", - ce.e.key_, - ce.updated_time, - n.updated_time, - time_delta, - g_data_bucket_cache.size() - ); - return; - } - // update cache if (ce.e.id == n.e.id) { + // reject old updates + int64 time_delta = ce.updated_time - n.updated_time; + if (ce.updated_time >= n.updated_time) { + LogDataBuckets( + "Attempted to update older cache key [{}] rejecting old time [{}] new time [{}] delta [{}] cache_size [{}]", + ce.e.key_, + ce.updated_time, + n.updated_time, + time_delta, + g_data_bucket_cache.size() + ); + return; + } + DeleteFromMissesCache(n.e); LogDataBuckets( @@ -663,3 +665,9 @@ void DataBucket::DeleteFromMissesCache(DataBucketsRepository::DataBuckets e) g_data_bucket_cache.size() ); } + +void DataBucket::ClearCache() +{ + g_data_bucket_cache.clear(); + LogInfo("Cleared data buckets cache"); +} diff --git a/zone/data_bucket.h b/zone/data_bucket.h index 74dba4df0..4ae270e44 100644 --- a/zone/data_bucket.h +++ b/zone/data_bucket.h @@ -88,6 +88,7 @@ public: static bool SendDataBucketCacheUpdate(const DataBucketCacheEntry &e); static void HandleWorldMessage(ServerPacket *p); static void DeleteFromMissesCache(DataBucketsRepository::DataBuckets e); + static void ClearCache(); }; #endif //EQEMU_DATABUCKET_H diff --git a/zone/gm_commands/reload.cpp b/zone/gm_commands/reload.cpp index 97e55d7cb..41e3a80f5 100644 --- a/zone/gm_commands/reload.cpp +++ b/zone/gm_commands/reload.cpp @@ -18,6 +18,7 @@ void command_reload(Client *c, const Seperator *sep) bool is_blocked_spells = !strcasecmp(sep->arg[1], "blocked_spells"); bool is_commands = !strcasecmp(sep->arg[1], "commands"); bool is_content_flags = !strcasecmp(sep->arg[1], "content_flags"); + bool is_data_buckets = !strcasecmp(sep->arg[1], "data_buckets_cache"); bool is_doors = !strcasecmp(sep->arg[1], "doors"); bool is_dztemplates = !strcasecmp(sep->arg[1], "dztemplates"); bool is_ground_spawns = !strcasecmp(sep->arg[1], "ground_spawns"); @@ -46,6 +47,7 @@ void command_reload(Client *c, const Seperator *sep) !is_blocked_spells && !is_commands && !is_content_flags && + !is_data_buckets && !is_doors && !is_dztemplates && !is_ground_spawns && @@ -92,6 +94,9 @@ void command_reload(Client *c, const Seperator *sep) } else if (is_doors) { c->Message(Chat::White, "Attempting to reload Doors globally."); pack = new ServerPacket(ServerOP_ReloadDoors, 0); + } else if (is_data_buckets) { + c->Message(Chat::White, "Attempting to flush data buckets cache globally."); + pack = new ServerPacket(ServerOP_ReloadDataBucketsCache, 0); } else if (is_dztemplates) { c->Message(Chat::White, "Attempting to reload Dynamic Zone Templates globally."); pack = new ServerPacket(ServerOP_ReloadDzTemplates, 0); diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index a512ffddf..6a3ee3289 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -2004,6 +2004,12 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) RuleManager::Instance()->LoadRules(&database, RuleManager::Instance()->GetActiveRuleset(), true); break; } + case ServerOP_ReloadDataBucketsCache: + { + zone->SendReloadMessage("Data buckets cache"); + DataBucket::ClearCache(); + break; + } case ServerOP_ReloadDoors: case ServerOP_ReloadGroundSpawns: case ServerOP_ReloadObjects: