Fix filename collision of string cache between shards on the same host

ryzomclassic-develop
kaetemi 5 years ago committed by Jan Boon
parent 6c6a83bc5d
commit c7b27c8d70

@ -643,7 +643,7 @@ TInterfaceState autoLogin (const string &cookie, const string &fsaddr, bool firs
NetMngr.setDataBase (IngameDbMngr.getNodePtr()); NetMngr.setDataBase (IngameDbMngr.getNodePtr());
// init the string manager cache. // init the string manager cache.
STRING_MANAGER::CStringManagerClient::instance()->initCache(UsedFSAddr, ClientCfg.LanguageCode); STRING_MANAGER::CStringManagerClient::instance()->initCache(ClientCfg.LanguageCode);
} }
} }
else else

@ -1149,6 +1149,9 @@ void CFarTP::disconnectFromPreviousShard()
} }
else else
{ {
// flush the server string cache
STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
// String manager: remove all waiting callbacks and removers // String manager: remove all waiting callbacks and removers
// (if some interface stuff has not received its string yet, its remover will get useless) // (if some interface stuff has not received its string yet, its remover will get useless)
STRING_MANAGER::CStringManagerClient::release( false ); STRING_MANAGER::CStringManagerClient::release( false );
@ -1204,7 +1207,7 @@ void CFarTP::connectToNewShard()
} }
// Reinit the string manager cache. // Reinit the string manager cache.
STRING_MANAGER::CStringManagerClient::instance()->initCache(FSAddr, ClientCfg.LanguageCode); STRING_MANAGER::CStringManagerClient::instance()->initCache(ClientCfg.LanguageCode);
// reset the chat mode // reset the chat mode
ChatMngr.resetChatMode(); ChatMngr.resetChatMode();

@ -2317,8 +2317,9 @@ void impulseReloadCache(NLMISC::CBitMemStream &impulse)
{ {
uint32 timestamp;; uint32 timestamp;;
impulse.serial(timestamp); impulse.serial(timestamp);
nlwarning("TODO_SHARD_ID %u", (unsigned int)timestamp);
if (PermanentlyBanned) return; if (PermanentlyBanned) return;
STRING_MANAGER::CStringManagerClient::instance()->loadCache(timestamp); STRING_MANAGER::CStringManagerClient::instance()->loadCache(timestamp, 1999); // TODO_SHARD_ID
} }
//----------------------------------------------- //-----------------------------------------------

@ -243,8 +243,8 @@ void releaseMainLoopReselect()
// Pause any user played music // Pause any user played music
MusicPlayer.pause(); MusicPlayer.pause();
// only really needed at exit // flush the server string cache
// --STRING_MANAGER::CStringManagerClient::instance()->flushStringCache(); STRING_MANAGER::CStringManagerClient::instance()->flushStringCache();
// Remove all entities. // Remove all entities.
if (Driver) if (Driver)

@ -99,22 +99,28 @@ namespace STRING_MANAGER
} }
} }
void CStringManagerClient::initCache(const std::string &languageCode)
void CStringManagerClient::initCache(const std::string &shardId, const std::string &languageCode)
{ {
H_AUTO( CStringManagerClient_initCache ) H_AUTO( CStringManagerClient_initLanguage )
_ShardId = shardId; m_LanguageCode = languageCode;
_LanguageCode = languageCode;
// to be inited, shard id and language code must be filled // clear all current data.
if (!_ShardId.empty() && !_LanguageCode.empty()) _ReceivedStrings.clear();
_CacheInited = true; _ReceivedDynStrings.clear();
else _CacheStringToSave.clear();
_CacheInited = false; // NB : we keep the waiting strings and dyn strings
// insert the empty string.
_ReceivedStrings.insert(make_pair((uint)EmptyStringId, ucstring()));
// to be inited, language code must be filled
_CacheInited = !m_LanguageCode.empty();
_CacheLoaded = false;
_CacheFilename.clear();
} }
void CStringManagerClient::loadCache(uint32 timestamp) void CStringManagerClient::loadCache(uint32 timestamp, uint32 shardId)
{ {
H_AUTO( CStringManagerClient_loadCache ) H_AUTO( CStringManagerClient_loadCache )
@ -122,7 +128,8 @@ namespace STRING_MANAGER
{ {
try try
{ {
_CacheFilename = std::string("save/") + _ShardId.substr(0, _ShardId.find(":")) + ".string_cache"; std::string clientApp = ClientCfg.ConfigFile.getVar("Application").asString(0);
_CacheFilename = std::string("save/") + clientApp + "_" + toString(shardId) + "_" + m_LanguageCode + ".string_cache";
nlinfo("SM : Try to open the string cache : %s", _CacheFilename.c_str()); nlinfo("SM : Try to open the string cache : %s", _CacheFilename.c_str());
@ -157,6 +164,7 @@ namespace STRING_MANAGER
// clear all current data. // clear all current data.
_ReceivedStrings.clear(); _ReceivedStrings.clear();
_ReceivedDynStrings.clear(); _ReceivedDynStrings.clear();
_CacheStringToSave.clear();
// NB : we keep the waiting strings and dyn strings // NB : we keep the waiting strings and dyn strings
// insert the empty string. // insert the empty string.
@ -528,7 +536,7 @@ restartLoop:
void CStringManagerClient::flushStringCache() void CStringManagerClient::flushStringCache()
{ {
if(!_CacheStringToSave.empty()) if (!_CacheStringToSave.empty() && !_CacheFilename.empty())
{ {
NLMISC::COFile file(_CacheFilename, true); NLMISC::COFile file(_CacheFilename, true);
for(uint i=0;i<_CacheStringToSave.size();i++) for(uint i=0;i<_CacheStringToSave.size();i++)

@ -48,14 +48,14 @@ public:
/** Prepare the string manager to use a persistent string cache. /** Prepare the string manager to use a persistent string cache.
* There is one cache file for each language and for each encountered shard. * There is one cache file for each language and for each encountered shard.
*/ */
void initCache(const std::string &shardId, const std::string &languageCode); void initCache(const std::string &languageCode);
/** Clear the current string table and load the content of the cache file. /** Clear the current string table and load the content of the cache file.
* This method is called after receiving the impulse RELOAD_CACHE from * This method is called after receiving the impulse RELOAD_CACHE from
* IOS. * IOS.
* If the received timestamp and the file timestamp differ, the file cache * If the received timestamp and the file timestamp differ, the file cache
* is reseted. * is reseted.
*/ */
void loadCache(uint32 timestamp); void loadCache(uint32 timestamp, uint32 shardId);
bool isCacheLoaded() {return _CacheLoaded;}; bool isCacheLoaded() {return _CacheLoaded;};
// Force the cache to be saved // Force the cache to be saved
void flushStringCache(); void flushStringCache();
@ -228,10 +228,8 @@ private:
//\name Cache management //\name Cache management
/// Flag for cache management initialisation done. /// Flag for cache management initialisation done.
bool _CacheInited; bool _CacheInited;
/// Shard id is used to identify the cache file to use.
std::string _ShardId;
/// Language code is used to identify the cache file to use. /// Language code is used to identify the cache file to use.
std::string _LanguageCode; std::string m_LanguageCode;
/// Timestamp (unix date) of the corrently loaded cache file. /// Timestamp (unix date) of the corrently loaded cache file.
uint32 _Timestamp; uint32 _Timestamp;
/// Fullpath name of the current cache file. /// Fullpath name of the current cache file.

@ -1020,6 +1020,9 @@ void CStringManager::updateUserLanguage( uint32 userId, TServiceId frontEndId, c
NLMISC::CBitMemStream bmsOut; NLMISC::CBitMemStream bmsOut;
GenericXmlMsgHeaderMngr.pushNameToStream( "STRING_MANAGER:RELOAD_CACHE", bmsOut); GenericXmlMsgHeaderMngr.pushNameToStream( "STRING_MANAGER:RELOAD_CACHE", bmsOut);
bmsOut.serial(timestamp); bmsOut.serial(timestamp);
uint32 shardId = IService::getInstance()->getShardId();
bmsOut.serial(shardId);
// send the message to Front End // send the message to Front End
NLNET::CMessage msgout( "IMPULSION_UID" ); NLNET::CMessage msgout( "IMPULSION_UID" );

Loading…
Cancel
Save