fix db bug; cleanup; better destructors

This commit is contained in:
DarthArgus
2016-12-08 17:23:03 +00:00
parent eab175813d
commit a353c128c3
4 changed files with 50 additions and 30 deletions
@@ -174,15 +174,33 @@ Persister::~Persister()
{
DEBUG_FATAL(taskQueue,("Call shutdown() before deleting Persister.\n"));
ServerSnapshotMap::iterator i;
for (i=m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i)
for (auto i=m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i) {
delete i->second;
for (i=m_newObjectSnapshots.begin(); i!=m_newObjectSnapshots.end(); ++i)
i->second = nullptr;
}
for (auto 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;
@@ -599,12 +617,14 @@ void Persister::endBaselines(const NetworkId &objectId, uint32 serverId)
void Persister::saveCompleted(Snapshot *completedSnapshot)
{
if (completedSnapshot) {
delete completedSnapshot;
completedSnapshot = nullptr;
}
SnapshotListType::iterator i=std::remove(m_savingSnapshots.begin(),m_savingSnapshots.end(),completedSnapshot);
if (i!=m_savingSnapshots.end())
{
delete completedSnapshot;
completedSnapshot = nullptr;
m_savingSnapshots.erase(i, m_savingSnapshots.end());
if (m_savingSnapshots.empty() && ConfigServerDatabase::getReportSaveTimes())
{
@@ -637,10 +657,8 @@ void Persister::saveCompleted(Snapshot *completedSnapshot)
{
SnapshotListType::iterator j=std::remove(m_savingCharacterSnapshots.begin(),m_savingCharacterSnapshots.end(),completedSnapshot);
DEBUG_FATAL(i==m_savingCharacterSnapshots.end(),("Programmer bug: SaveCompleted() called with a snapshot that wasn't in m_savingSnapshots or m_savingCharacterSnapshots."));
delete completedSnapshot;
completedSnapshot = nullptr;
m_savingCharacterSnapshots.erase(j, m_savingCharacterSnapshots.end());
m_savingCharacterSnapshots.erase(j, m_savingCharacterSnapshots.end());
DEBUG_REPORT_LOG(ConfigServerDatabase::getReportSaveTimes(),("New character save completed\n"));
}
}
@@ -64,16 +64,14 @@ bool ObjvarBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::
{
break;
}
IndexKey key(row->object_id.getValue(), row->name_id.getValue());
ObjvarValue value;
value.m_type=row->type.getValue();
// The string is stored in the database as utf8, so a wide-to-narrow is appropriate
value.m_value=Unicode::wideToNarrow(row->value.getValue());
value.m_detached=false;
IndexKey key(row->object_id.getValue(), row->name_id.getValue());
ObjvarValue value;
value.m_type=row->type.getValue();
// The string is stored in the database as utf8, so a wide-to-narrow is appropriate
value.m_value=Unicode::wideToNarrow(row->value.getValue());
m_data.insert(std::make_pair(key,value));
}
}
@@ -199,7 +197,7 @@ bool ObjvarBuffer::save(DB::Session *session)
// ----------------------------------------------------------------------
void ObjvarBuffer::getObjvarsForObject(const NetworkId objectId, std::vector<DynamicVariableList::MapType::Command> commands) const
void ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector<DynamicVariableList::MapType::Command> &commands) const
{
DynamicVariableList::MapType::Command c;
@@ -258,7 +256,7 @@ void ObjvarBuffer::getObjvarsForObject(const NetworkId objectId, std::vector<Dyn
// ----------------------------------------------------------------------
void ObjvarBuffer::updateObjvars(const NetworkId objectId, const std::vector<DynamicVariableList::MapType::Command> commands)
void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vector<DynamicVariableList::MapType::Command> &commands)
{
bool override=false; // flag that we're dealing with the gold data override case (storing an objvar change in the live database, on an object that came from the gold database)
if (ConfigServerDatabase::getEnableGoldDatabase() && objectId < ConfigServerDatabase::getMaxGoldNetworkId())
@@ -314,8 +312,9 @@ void ObjvarBuffer::updateObjvars(const NetworkId objectId, const std::vector<Dyn
}
row->second.m_type = i->value.getType();
row->second.m_detached = true;
row->second.m_detached = true; //why the fuck even store it at this point?
}
break;
}
@@ -332,9 +331,12 @@ void ObjvarBuffer::updateObjvars(const NetworkId objectId, const std::vector<Dyn
void ObjvarBuffer::removeObject(const NetworkId &object)
{
DataType::iterator i=m_data.lower_bound(IndexKey(object,0));
while (i!=m_data.end() && i->first.m_objectId==object)
while (i!=m_data.end())
{
i = m_data.erase(i);
if (i->first.m_objectId==object)
i = m_data.erase(i);
else
++i;
}
}
@@ -49,18 +49,18 @@ public:
virtual bool save(DB::Session *session);
virtual void removeObject(const NetworkId &object);
DBSchema::ObjectVariableRow *findRowByIndex(const NetworkId objectId, const std::string &name);
DBSchema::ObjectVariableRow *findRowByIndex(const NetworkId &objectId, const std::string &name);
void updateObjvars(const NetworkId objectId, const std::vector<DynamicVariableList::MapType::Command> commands);
void getObjvarsForObject(const NetworkId objectId, std::vector<DynamicVariableList::MapType::Command> commands) const;
void updateObjvars(const NetworkId &objectId, const std::vector<DynamicVariableList::MapType::Command> &commands);
void getObjvarsForObject(const NetworkId &objectId, std::vector<DynamicVariableList::MapType::Command> &commands) const;
private:
struct IndexKey
{
NetworkId m_objectId;
const NetworkId m_objectId;
int m_nameId;
IndexKey(const NetworkId objectId, int nameId);
IndexKey(const NetworkId &objectId, int nameId);
bool operator==(const IndexKey &rhs) const;
bool operator<(const IndexKey &rhs) const;
};
@@ -92,7 +92,7 @@ public:
// ======================================================================
inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId objectId, int nameId) : m_objectId(objectId), m_nameId(nameId)
inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId &objectId, int nameId) : m_objectId(objectId), m_nameId(nameId)
{
}
@@ -119,7 +119,7 @@ public:
void newMissionObject (NetworkId const & objectId);
void newPlanetObject (NetworkId const & objectId);
void newPlayerObject (NetworkId const & objectId);
void newPlayerQuestObject (NetworkId const & objectId);
void newPlayerQuestObject (NetworkId const & objectId);
void newRegionCircleObject (NetworkId const & objectId);
void newRegionObject (NetworkId const & objectId);
void newRegionRectangleObject (NetworkId const & objectId);