persister cleanup (still broke but logic is there for when it isn't); also replace all the SOE BS for forwarding stl port with native object classes because i thought that may be part of the problem...

This commit is contained in:
DarthArgus
2016-12-10 23:17:06 +00:00
parent 688ab3fc9e
commit 8e94519082
450 changed files with 1287 additions and 1494 deletions
@@ -25,7 +25,7 @@ class NetworkId;
namespace DB
{
typedef stdset<Tag>::fwd TagSet;
typedef std::set<Tag> TagSet;
}
// ======================================================================
@@ -50,7 +50,7 @@ class DatabaseProcess : public MessageDispatch::Receiver
// getters:
GameServerConnection * getConnectionByProcess(const uint32 processId);
void getGameServerProcessIds(stdvector<uint32>::fwd &processIds) const;
void getGameServerProcessIds(std::vector<uint32> &processIds) const;
uint32 getProcessId(void);
DB::Server *getDBServer(void);
const std::string &getClusterName() const;
@@ -27,7 +27,7 @@ public:
void clearChunkCompleteQueue();
private:
typedef stdvector<std::pair<int, int> >::fwd ChunkCompleteQueueType;
typedef std::vector<std::pair<int, int> > ChunkCompleteQueueType;
ChunkCompleteQueueType * const m_chunkCompleteQueue;
private:
@@ -28,7 +28,7 @@ class ImmediateDeleteCustomPersistStep : public CustomPersistStep
void addObject (const NetworkId &deletedObject);
private:
stdset<NetworkId>::fwd *m_objects; // using set instead of vector to enforce uniqueness
std::set<NetworkId> *m_objects; // using set instead of vector to enforce uniqueness
private:
ImmediateDeleteCustomPersistStep &operator= (const ImmediateDeleteCustomPersistStep&); //disable
@@ -53,8 +53,8 @@ class LazyDeleter
private:
static LazyDeleter *ms_instance;
Thread *m_workerThread;
stdvector<NetworkId>::fwd *m_incomingObjects;
stddeque<NetworkId>::fwd *m_objectsToDelete;
std::vector<NetworkId> *m_incomingObjects;
std::deque<NetworkId> *m_objectsToDelete;
Mutex *m_objectListLock;
bool m_shutdown;
bool m_paused;
@@ -27,7 +27,7 @@ class GameServerConnection;
class MessageToManager
{
public:
typedef stdvector<MessageToPayload>::fwd MessageVector;
typedef std::vector<MessageToPayload> MessageVector;
public:
static void install();
@@ -5,6 +5,8 @@
//
// ======================================================================
#include <memory>
#include "serverDatabase/FirstServerDatabase.h"
#include "serverDatabase/Persister.h"
@@ -174,33 +176,15 @@ Persister::~Persister()
{
DEBUG_FATAL(taskQueue,("Call shutdown() before deleting Persister.\n"));
for (auto i=m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i) {
ServerSnapshotMap::iterator i;
for (i=m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i)
delete i->second;
i->second = nullptr;
}
for (auto i=m_newObjectSnapshots.begin(); i!=m_newObjectSnapshots.end(); ++i) {
for (i=m_newObjectSnapshots.begin(); i!=m_newObjectSnapshots.end(); ++i)
delete i->second;
i->second = nullptr;
}
for (auto i=m_savingCharacterSnapshots.begin(); i!=m_savingCharacterSnapshots.end(); ++i) {
delete *i;
*i = nullptr;
}
for (auto i=m_savingSnapshots.begin(); i!=m_savingSnapshots.end(); ++i) {
delete *i;
*i = nullptr;
}
m_currentSnapshots.clear();
m_newObjectSnapshots.clear();
m_objectSnapshotMap.clear();
m_savingCharacterSnapshots.clear();
m_savingSnapshots.clear();
m_messageSnapshot = nullptr;
m_commoditiesSnapshot = nullptr;
m_arbitraryGameDataSnapshot = nullptr;
@@ -235,18 +219,14 @@ void Persister::onFrameBarrierReached()
if (m_newCharacterTaskQueue->getNumPendingTasks() == 0)
{
ServerSnapshotMap delayedSaves;
for (ServerSnapshotMap::iterator i=m_newCharacterSnapshots.begin(); i!=m_newCharacterSnapshots.end(); ++i)
{
if (m_newCharacterLock.find(i->first)==m_newCharacterLock.end())
{
DEBUG_REPORT_LOG(ConfigServerDatabase::getReportSaveTimes(),("Starting new character save\n"));
if (i->second != nullptr) {
m_savingCharacterSnapshots.push_back(i->second);
m_newCharacterTaskQueue->asyncRequest(new TaskSaveSnapshot(i->second));
}
m_savingCharacterSnapshots.push_back(i->second);
m_newCharacterTaskQueue->asyncRequest(new TaskSaveSnapshot(i->second));
for (ObjectSnapshotMap::iterator obj=m_objectSnapshotMap.begin(); obj!=m_objectSnapshotMap.end();)
{
if (obj->second == i->second)
@@ -265,7 +245,8 @@ void Persister::onFrameBarrierReached()
}
// Check for whether it is time to save
FATAL(m_timeSinceLastSave > ConfigServerDatabase::getMaxTimewarp(),("Save was not completed within %i seconds. We may experience a \"time warp\"\n",ConfigServerDatabase::getMaxTimewarp()));
FATAL(m_timeSinceLastSave > ConfigServerDatabase::getMaxTimewarp(),("Save was not completed within %i seconds. Shutting down to avoid a longer timewarp.\n",ConfigServerDatabase::getMaxTimewarp()));
if (ConfigServerDatabase::getSaveAtModulus()!=-1)
{
@@ -353,19 +334,14 @@ void Persister::startSave(void)
ServerSnapshotMap::iterator i;
for (i=m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i)
{
if (i->second != nullptr) {
m_savingSnapshots.push_back(i->second);
taskQueue->asyncRequest(new TaskSaveSnapshot(i->second));
}
m_savingSnapshots.push_back(i->second);
taskQueue->asyncRequest(new TaskSaveSnapshot(i->second));
}
for (i=m_newObjectSnapshots.begin(); i!=m_newObjectSnapshots.end(); ++i)
{
if (i->second != nullptr) {
m_savingSnapshots.push_back(i->second);
taskQueue->asyncRequest(new TaskSaveSnapshot(i->second));
}
}
{
m_savingSnapshots.push_back(i->second);
taskQueue->asyncRequest(new TaskSaveSnapshot(i->second));
}
// nothing changed so send a complete message for the shutdown process
if( m_savingSnapshots.empty() )
@@ -619,94 +595,46 @@ void Persister::endBaselines(const NetworkId &objectId, uint32 serverId)
// ----------------------------------------------------------------------
void Persister::nukeOrphans() {
if (m_completedSnapshots.size() > 0) {
int completeCount = m_completedSnapshots.size();
int snapshotClassCount = (*m_completedSnapshots.begin())->getPendingCount();
WARNING(true, ("%i snapshots done, snapshot class reports %i currently allocated", completeCount, snapshotClassCount));
if (snapshotClassCount > 5) {
delmutex.lock();
for (auto i = m_completedSnapshots.begin(); i != m_completedSnapshots.end(); ++i) {
if (i != m_completedSnapshots.end() && *i != nullptr && !(*i)->getIsBeingSaved() && completeCount > 5) {
WARNING(true, ("Deleting orphaned snapshot"));
delete (*i);
*i = nullptr;
i = m_completedSnapshots.erase(i);
completeCount--;
} else {
break;
}
}
delmutex.unlock();
}
}
}
/**
* Called by TaskSaveSnapshot when it finishes.
*/
void Persister::saveCompleted(Snapshot *completedSnapshot)
{
nukeOrphans();
auto i=std::remove(m_savingSnapshots.begin(),m_savingSnapshots.end(),completedSnapshot);
SnapshotListType::iterator i=std::remove(m_savingSnapshots.begin(),m_savingSnapshots.end(),completedSnapshot);
if (i!=m_savingSnapshots.end())
{
m_savingSnapshots.erase(i, m_savingSnapshots.end());
if (m_savingSnapshots.empty() && ConfigServerDatabase::getReportSaveTimes())
{
}
if (m_savingSnapshots.empty()) {
if (ConfigServerDatabase::getReportSaveTimes()) {
int saveTime = Clock::timeMs() - m_saveStartTime;
++m_saveCount;
m_totalSaveTime += saveTime;
if (saveTime > m_maxSaveTime)
m_maxSaveTime = saveTime;
DEBUG_REPORT_LOG(true,("Save completed in %i. (Average %i, max %i)\n", saveTime, m_totalSaveTime/m_saveCount, m_maxSaveTime));
LOG("SaveTimes",("Save completed in %i. (Average %i, max %i)", saveTime, m_totalSaveTime/m_saveCount, m_maxSaveTime));
m_lastSaveTime = saveTime;
}
if (m_savingSnapshots.empty())
{
// message Central Server that the current save cycle is complete
GenericValueTypeMessage<int> const saveCompleteMessage("DatabaseSaveComplete", ++m_saveCounter);
DatabaseProcess::getInstance().sendToCentralServer(saveCompleteMessage, true);
LOG("Database",("Sending DatabaseSaveComplete network message to Central."));
}
{
// set the last save completion time (for the monitoring program)
time_t theTime = time(0);
m_lastSaveCompletionTime = ctime(&theTime);
}
// message Central Server that the current save cycle is complete
GenericValueTypeMessage<int> const saveCompleteMessage("DatabaseSaveComplete", ++m_saveCounter);
DatabaseProcess::getInstance().sendToCentralServer(saveCompleteMessage, true);
LOG("Database",("Sending DatabaseSaveComplete network message to Central."));
}
else
{
auto j=std::remove(m_savingCharacterSnapshots.begin(),m_savingCharacterSnapshots.end(),completedSnapshot);
if (j != m_savingCharacterSnapshots.end()) {
m_savingCharacterSnapshots.erase(j, m_savingCharacterSnapshots.end());
} else {
DEBUG_WARNING(true,("saveCompleted called w/o snap in m_savingSnapshots or m_savingCharacterSnapshots."));
}
}
bool locked = false;
do {
locked = delmutex.try_lock();
} while (!locked);
if (completedSnapshot != nullptr){
m_completedSnapshots.push_back(completedSnapshot);
// character snapshot deletions seem to work ok, but world and object snaps do not for deletion...wtf
SnapshotListType::iterator j=std::remove(m_savingCharacterSnapshots.begin(),m_savingCharacterSnapshots.end(),completedSnapshot);
if (j != m_savingCharacterSnapshots.end()) {
m_savingCharacterSnapshots.erase(j, m_savingCharacterSnapshots.end());
}
delmutex.unlock();
if (completedSnapshot != nullptr) {
delete completedSnapshot;
completedSnapshot = nullptr;
}
}
// ----------------------------------------------------------------------
@@ -16,8 +16,6 @@
#include <vector>
#include <set> //TODO: remove when we clean up newCharacterLock hack
#include <mutex>
#include "Unicode.h"
#include "serverNetworkMessages/MessageToPayload.h"
#include "sharedDatabaseInterface/DbModeQuery.h"
@@ -71,8 +69,6 @@ class Persister : public MessageDispatch::Receiver
void beginBaselines(const NetworkId &newObject) const;
void endBaselines(const NetworkId &newObject, uint32 serverId);
void nukeOrphans();
void saveCompleted (Snapshot *completedSnapshot);
void onNewCharacterSaved (uint32 stationId, const NetworkId &characterObject, const Unicode::String &characterName, const int templateId, bool special) const;
@@ -101,8 +97,6 @@ class Persister : public MessageDispatch::Receiver
DB::TaskQueue *m_newCharacterTaskQueue;
private:
std::mutex delmutex;
struct PendingCharacter
{
uint32 stationId;
@@ -122,11 +116,8 @@ class Persister : public MessageDispatch::Receiver
ServerSnapshotMap m_newCharacterSnapshots;
ObjectSnapshotMap m_objectSnapshotMap;
PendingCharactersType m_pendingCharacters;
SnapshotListType m_savingSnapshots;
SnapshotListType m_savingCharacterSnapshots;
SnapshotListType m_completedSnapshots;
NewCharacterLockType m_newCharacterLock;
CharactersToDeleteType * m_charactersToDeleteThisSaveCycle;
CharactersToDeleteType * m_charactersToDeleteNextSaveCycle;
@@ -192,7 +183,7 @@ class Persister : public MessageDispatch::Receiver
/**
* Misc game-specific persistence steps
*/
virtual void getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector<int8>::fwd const & packedDictionary)=0;
virtual void getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, std::vector<int8> const & packedDictionary)=0;
protected:
Persister();
@@ -51,7 +51,7 @@ public:
virtual void handleAddResourceTypeMessage (const AddResourceTypeMessage &message) =0;
virtual void handleBountyHunterTargetMessage (const BountyHunterTargetMessage &message) =0;
virtual void getWorldContainers (stdvector<NetworkId>::fwd &containers) const = 0;
virtual void getWorldContainers (std::vector<NetworkId> &containers) const = 0;
void handleDeltasMessage (NetworkId & objectId, const DeltasMessage &msg);
void handleBaselinesMessage (NetworkId & objectId, const BaselinesMessage &msg);
@@ -118,10 +118,10 @@ private:
virtual void decodeClientData(const NetworkId & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeParentClientData(const NetworkId & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual bool encodeParentClientData(const NetworkId & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeClientData(const NetworkId & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeServerData(const NetworkId & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeSharedData(const NetworkId & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeParentClientData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const = 0;
virtual bool encodeClientData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const = 0;
virtual bool encodeServerData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const = 0;
virtual bool encodeSharedData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const = 0;
private:
Snapshot(const Snapshot&); //disable
@@ -23,14 +23,14 @@
class WorldContainerLocator : public ObjectLocator
{
public:
WorldContainerLocator(const stdvector<NetworkId>::fwd &containers);
WorldContainerLocator(const std::vector<NetworkId> &containers);
virtual ~WorldContainerLocator();
public:
virtual bool locateObjects(DB::Session *session, const std::string &schema, int &objectsLocated);
private:
stdvector<NetworkId>::fwd * m_containers;
std::vector<NetworkId> * m_containers;
private:
WorldContainerLocator &operator=(const WorldContainerLocator&); //disable
@@ -29,7 +29,7 @@ struct BidRecord
// ======================================================================
typedef stdvector<BidRecord>::fwd BidList;
typedef std::vector<BidRecord> BidList;
// ======================================================================
@@ -36,7 +36,7 @@ struct LocationRecord
// ======================================================================
typedef stdvector<LocationRecord>::fwd LocationList;
typedef std::vector<LocationRecord> LocationList;
// ======================================================================