1
0
mirror of https://github.com/anope/anope.git synced 2026-07-07 23:23:13 +02:00

Fixed some 100% cpu bugs with the new SQL stuff, and fixed sqlite+db_sql_live

This commit is contained in:
Adam
2012-05-08 18:04:49 -04:00
parent 25586f3246
commit 820e4edc2b
7 changed files with 41 additions and 14 deletions
+4
View File
@@ -70,6 +70,7 @@ class CoreExport Serializable : public virtual Base
private:
std::list<Serializable *>::iterator s_iter;
Serialize::Data last_commit;
time_t last_commit_time;
protected:
Serializable();
@@ -89,6 +90,9 @@ class CoreExport Serializable : public virtual Base
bool IsCached();
void UpdateCache();
bool IsTSCached();
void UpdateTS();
virtual const Anope::string serialize_name() const = 0;
virtual Serialize::Data serialize() const = 0;
+3 -1
View File
@@ -109,7 +109,6 @@ class DBSQL : public Module, public Pipe
for (unsigned i = 0; i < create.size(); ++i)
this->RunBackground(create[i]);
SQLQuery insert = this->sql->BuildInsert(this->prefix + obj->serialize_name(), obj->id, data);
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
}
@@ -179,6 +178,9 @@ class DBSQL : public Module, public Pipe
void OnSerializableUpdate(Serializable *obj) anope_override
{
if (obj->IsTSCached())
return;
obj->UpdateTS();
this->updated_items.insert(obj);
this->Notify();
}
+6 -11
View File
@@ -59,9 +59,9 @@ class DBMySQL : public Module, public Pipe
{
SQLResult res = SQL->RunQuery(query);
if (!res.GetError().empty())
Log(LOG_DEBUG) << "SQlive got error " << res.GetError() << " for " + res.finished_query;
Log(LOG_DEBUG) << "SQL-live got error " << res.GetError() << " for " + res.finished_query;
else
Log(LOG_DEBUG) << "SQLive got " << res.Rows() << " rows for " << res.finished_query;
Log(LOG_DEBUG) << "SQL-live got " << res.Rows() << " rows for " << res.finished_query;
return res;
}
throw SQLException("No SQL!");
@@ -95,11 +95,6 @@ class DBMySQL : public Module, public Pipe
continue;
obj->UpdateCache();
static std::set<Serializable *> working_objects; // XXX
if (working_objects.count(obj))
continue;
working_objects.insert(obj);
const Serialize::Data &data = obj->serialize();
std::vector<SQLQuery> create = this->SQL->CreateTable(this->prefix + obj->serialize_name(), data);
@@ -112,8 +107,6 @@ class DBMySQL : public Module, public Pipe
SerializeType *stype = SerializeType::Find(obj->serialize_name());
if (stype)
stype->objects.erase(obj->id);
working_objects.erase(obj);
}
}
@@ -198,8 +191,7 @@ class DBMySQL : public Module, public Pipe
if (!this->CheckInit() || obj->GetTimestamp() == Anope::CurTime)
return;
SQLQuery query("SELECT * FROM `" + this->prefix + obj->GetName() + "` WHERE (`timestamp` > FROM_UNIXTIME(@ts@) OR `timestamp` IS NULL)");
query.setValue("ts", obj->GetTimestamp());
SQLQuery query("SELECT * FROM `" + this->prefix + obj->GetName() + "` WHERE (`timestamp` > " + this->SQL->FromUnixtime(obj->GetTimestamp()) + " OR `timestamp` IS NULL)");
obj->UpdateTimestamp();
@@ -263,6 +255,9 @@ class DBMySQL : public Module, public Pipe
void OnSerializableUpdate(Serializable *obj) anope_override
{
if (obj->IsTSCached())
return;
obj->UpdateTS();
this->updated_items.insert(obj);
this->Notify();
}
+7
View File
@@ -135,6 +135,8 @@ class MySQLService : public SQLProvider
bool CheckConnection();
Anope::string BuildQuery(const SQLQuery &q);
Anope::string FromUnixtime(time_t);
};
/** The SQL thread used to execute queries
@@ -481,6 +483,11 @@ Anope::string MySQLService::BuildQuery(const SQLQuery &q)
return real_query;
}
Anope::string MySQLService::FromUnixtime(time_t t)
{
return "FROM_UNIXTIME(" + stringify(t) + ")";
}
void DispatcherThread::Run()
{
this->Lock();
+7
View File
@@ -53,6 +53,8 @@ class SQLiteService : public SQLProvider
SQLQuery GetTables(const Anope::string &prefix);
Anope::string BuildQuery(const SQLQuery &q);
Anope::string FromUnixtime(time_t);
};
class ModuleSQLite : public Module
@@ -297,5 +299,10 @@ Anope::string SQLiteService::BuildQuery(const SQLQuery &q)
return real_query;
}
Anope::string SQLiteService::FromUnixtime(time_t t)
{
return "datetime('" + stringify(t) + "', 'unixepoch')";
}
MODULE_INIT(ModuleSQLite)
+2
View File
@@ -132,5 +132,7 @@ class SQLProvider : public Service
virtual SQLQuery BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data) = 0;
virtual SQLQuery GetTables(const Anope::string &prefix) = 0;
virtual Anope::string FromUnixtime(time_t) = 0;
};
+12 -2
View File
@@ -70,7 +70,7 @@ unsigned stringstream::getMax() const
return this->_max;
}
Serializable::Serializable() : id(0)
Serializable::Serializable() : last_commit_time(0), id(0)
{
if (serializable_items == NULL)
serializable_items = new std::list<Serializable *>();
@@ -82,7 +82,7 @@ Serializable::Serializable() : id(0)
FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
Serializable::Serializable(const Serializable &) : id(0)
Serializable::Serializable(const Serializable &) : last_commit_time(0), id(0)
{
serializable_items->push_back(this);
this->s_iter = serializable_items->end();
@@ -126,6 +126,16 @@ void Serializable::UpdateCache()
this->last_commit = this->serialize();
}
bool Serializable::IsTSCached()
{
return this->last_commit_time == Anope::CurTime;
}
void Serializable::UpdateTS()
{
this->last_commit_time = Anope::CurTime;
}
const std::list<Serializable *> &Serializable::GetItems()
{
return *serializable_items;