This commit is contained in:
DarthArgus
2016-12-10 04:16:07 +00:00
parent 3a62cb8b86
commit 76d08c50da
4 changed files with 76 additions and 44 deletions
@@ -619,12 +619,44 @@ 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);
if (i!=m_savingSnapshots.end())
{
@@ -658,7 +690,6 @@ void Persister::saveCompleted(Snapshot *completedSnapshot)
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 {
@@ -666,38 +697,16 @@ void Persister::saveCompleted(Snapshot *completedSnapshot)
}
}
bool locked = false;
do {
locked = delmutex.try_lock();
} while (!locked);
if (completedSnapshot != nullptr){
m_completedSnapshots.push_back(completedSnapshot);
}
if (m_completedSnapshots.size() > 0) {
int completeCount = 0;
int snapshotClassCount = (*m_completedSnapshots.begin())->getPendingCount();
for (auto i = m_completedSnapshots.begin(); i != m_completedSnapshots.end(); ++i) {
if (*i != nullptr) {
++completeCount;
DEBUG_WARNING(true, ("m_completedSnapshots has %i snapshots inside, snapshot class reports %i currently allocated", completeCount, snapshotClassCount));
} else {
i = m_completedSnapshots.erase(i);
}
}
if (completeCount > snapshotClassCount) {
for (auto i = m_completedSnapshots.begin(); i != m_completedSnapshots.end(); ++i) {
if (*i != nullptr && completeCount > snapshotClassCount) {
WARNING(true, ("Deleting orphaned snapshots, discrepancy of %i", (completeCount-snapshotClassCount)));
delete (*i);
*i = nullptr;
i = m_completedSnapshots.erase(i);
completeCount--;
} else {
break;
}
}
}
}
delmutex.unlock();
}
// ----------------------------------------------------------------------
@@ -16,6 +16,8 @@
#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"
@@ -69,6 +71,8 @@ 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;
@@ -97,6 +101,8 @@ class Persister : public MessageDispatch::Receiver
DB::TaskQueue *m_newCharacterTaskQueue;
private:
std::mutex delmutex;
struct PendingCharacter
{
uint32 stationId;
@@ -69,31 +69,42 @@ bool Snapshot::saveToDB(DB::Session *session)
{
NOT_NULL(session);
m_isBeingSaved = true;
CustomStepListType::iterator step;
for (step=m_customStepList.begin(); step !=m_customStepList.end(); ++step)
{
NOT_NULL(*step);
if (!(*step)->beforePersist(session))
if (!(*step)->beforePersist(session)) {
m_isBeingSaved = false;
return false;
}
}
if (m_timestamp!=0)
if (! saveTimestamp(session))
if (! saveTimestamp(session)) {
m_isBeingSaved = false;
return false;
}
for (BufferListType::iterator buffer=m_bufferList.begin(); buffer!=m_bufferList.end(); ++buffer)
{
if (! (*buffer)->save(session))
if (! (*buffer)->save(session)) {
m_isBeingSaved = false;
return false;
}
}
for (step=m_customStepList.begin(); step !=m_customStepList.end(); ++step)
{
NOT_NULL(*step);
if (!(*step)->afterPersist(session))
if (!(*step)->afterPersist(session)){
m_isBeingSaved = false;
return false;
}
}
m_isBeingSaved = false;
return true;
}
// ----------------------------------------------------------------------
@@ -45,7 +45,7 @@ public:
virtual ~Snapshot();
virtual void handleUpdateObjectPosition(const UpdateObjectPositionMessage &msg) =0;
virtual void handleDeleteMessage (const NetworkId &objectID, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason) =0;
virtual void handleDeleteMessage (const NetworkId objectID, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason) =0;
virtual void handleMessageTo (const MessageToPayload &data) =0;
virtual void handleMessageToAck (const MessageToId &messageId) =0;
virtual void handleAddResourceTypeMessage (const AddResourceTypeMessage &message) =0;
@@ -63,7 +63,7 @@ public:
void takeTimestamp();
virtual void newObject (NetworkId const & objectId, int templateId, Tag typeId) =0;
virtual void newObject (NetworkId const objectId, int templateId, Tag typeId) =0;
// virtual void addObjectIdForLoad (NetworkId objectId)=0; //TODO: the load list could be moved into Snapshot, intead of being in the derived class
void addLocator (ObjectLocator *newLocator);
@@ -98,12 +98,13 @@ public:
bool saveTimestamp (DB::Session *session);
private:
bool m_isBeingSaved;
bool m_useGoldDatabase;
DB::ModeQuery::Mode m_mode;
int m_timestamp;
public:
bool m_isBeingSaved;
bool getIsBeingSaved();
static int getCreationCount() { return ms_creationCount; }
static int getDeletionCount() { return ms_deletionCount; }
static int getPendingCount() { return ms_creationCount - ms_deletionCount; }
@@ -112,15 +113,15 @@ private:
static int ms_deletionCount;
protected:
virtual void decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeServerData(NetworkId const objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeSharedData(NetworkId const objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeClientData(NetworkId const objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual void decodeParentClientData(NetworkId const objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline) = 0;
virtual bool encodeParentClientData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeClientData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeServerData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeSharedData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeParentClientData(NetworkId const objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeClientData(NetworkId const objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeServerData(NetworkId const objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
virtual bool encodeSharedData(NetworkId const objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const = 0;
private:
Snapshot(const Snapshot&); //disable
@@ -129,6 +130,11 @@ private:
// ----------------------------------------------------------------------
inline bool Snapshot::getIsBeingSaved()
{
return m_isBeingSaved;
}
inline void Snapshot::setUniverseAuthHack()
{
m_universeAuthorityHack=true;