Skip to content

Commit

Permalink
improve: disable save async by default (#2298)
Browse files Browse the repository at this point in the history
Due to reports of system crashes and various concurrency issues,
asynchronous saving will be disabled by default as a precautionary
measure. We encourage the community's continued support by reporting any
instances of crashes or bugs. This will assist us in enhancing and
ensuring the feature's reliability for production use. Until these
issues are fully resolved, asynchronous saving will remain disabled.
  • Loading branch information
dudantas authored Feb 22, 2024
1 parent 530595a commit 6c54d56
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 40 deletions.
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ maxAllowedOnADummy = 1

-- Save interval per time
-- NOTE: toggleSaveInterval: true = enable the save interval, false = disable the save interval
-- NOTE: toggleSaveAsync = true, will enable save async (experimental), not recommended for use in production
-- NOTE: saveIntervalType: "minute", "second" or "hour"
-- NOTE: toggleSaveIntervalCleanMap: true = enable the clean map, false = disable the clean map
-- NOTE: saveIntervalTime: time based on what was set in "saveIntervalType"
toggleSaveAsync = false
toggleSaveInterval = true
saveIntervalType = "hour"
toggleSaveIntervalCleanMap = true
Expand Down
40 changes: 0 additions & 40 deletions data-canary/scripts/globalevents/save_interval.lua

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ enum ConfigKey_t : uint16_t {
TOGGLE_MAP_CUSTOM,
TOGGLE_MOUNT_IN_PZ,
TOGGLE_RECEIVE_REWARD,
TOGGLE_SAVE_ASYNC,
TOGGLE_SAVE_INTERVAL_CLEAN_MAP,
TOGGLE_SAVE_INTERVAL,
TOGGLE_SERVER_IS_RETRO,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, TOGGLE_IMBUEMENT_SHRINE_STORAGE, "toggleImbuementShrineStorage", true);
loadBoolConfig(L, TOGGLE_MOUNT_IN_PZ, "toggleMountInProtectionZone", false);
loadBoolConfig(L, TOGGLE_RECEIVE_REWARD, "toggleReceiveReward", false);
loadBoolConfig(L, TOGGLE_SAVE_ASYNC, "toggleSaveAsync", false);
loadBoolConfig(L, TOGGLE_SAVE_INTERVAL_CLEAN_MAP, "toggleSaveIntervalCleanMap", false);
loadBoolConfig(L, TOGGLE_SAVE_INTERVAL, "toggleSaveInterval", false);
loadBoolConfig(L, TOGGLE_SERVER_IS_RETRO, "toggleServerIsRetroPVP", false);
Expand Down
14 changes: 14 additions & 0 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ void SaveManager::scheduleAll() {
auto scheduledAt = std::chrono::steady_clock::now();
m_scheduledAt = scheduledAt;

// Disable save async if the config is set to false
if (!g_configManager().getBoolean(TOGGLE_SAVE_ASYNC, __FUNCTION__)) {
saveAll();
return;
}

threadPool.addLoad([this, scheduledAt]() {
if (m_scheduledAt.load() != scheduledAt) {
logger.warn("Skipping save for server because another save has been scheduled.");
Expand All @@ -50,6 +56,14 @@ void SaveManager::schedulePlayer(std::weak_ptr<Player> playerPtr) {
logger.debug("Skipping save for player because player is no longer online.");
return;
}

// Disable save async if the config is set to false
if (!g_configManager().getBoolean(TOGGLE_SAVE_ASYNC, __FUNCTION__)) {
logger.debug("Saving player {}.", playerToSave->getName());
doSavePlayer(playerToSave);
return;
}

logger.debug("Scheduling player {} for saving.", playerToSave->getName());
auto scheduledAt = std::chrono::steady_clock::now();
m_playerMap[playerToSave->getGUID()] = scheduledAt;
Expand Down

0 comments on commit 6c54d56

Please sign in to comment.