mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Expose the latest uptime snapshot on the database interface (#7840)
cmdGetServerStats reached through Servatrice_DatabaseInterface for checkSql and getLatestUptimeSnapshot, a concrete-only method. Move the UptimeSnapshot record to Server_DatabaseInterface with an invalid default for non-SQL stores, mark the Servatrice implementation as an override, and let the command ask the injected interface. The statement, its bind value and the invalid-snapshot response are unchanged.
This commit is contained in:
parent
03adbd9787
commit
7719ff021c
4 changed files with 22 additions and 15 deletions
|
|
@ -425,6 +425,24 @@ public:
|
||||||
virtual int getNextReplayId() = 0;
|
virtual int getNextReplayId() = 0;
|
||||||
virtual int getActiveUserCount(QString connectionType = QString()) = 0;
|
virtual int getActiveUserCount(QString connectionType = QString()) = 0;
|
||||||
|
|
||||||
|
/** @brief Snapshot recorded by the server's periodic status update into the uptime table. */
|
||||||
|
struct UptimeSnapshot
|
||||||
|
{
|
||||||
|
bool valid = false;
|
||||||
|
quint64 usersCount = 0;
|
||||||
|
quint64 modsCount = 0;
|
||||||
|
quint64 gamesCount = 0;
|
||||||
|
quint64 txBytes = 0;
|
||||||
|
quint64 rxBytes = 0;
|
||||||
|
quint64 uptimeSecs = 0;
|
||||||
|
quint64 timest = 0;
|
||||||
|
};
|
||||||
|
/** @brief Freshest uptime snapshot of one server; an invalid snapshot when none exists. */
|
||||||
|
virtual UptimeSnapshot getLatestUptimeSnapshot(int /* serverId */)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
virtual void clearSessionTables()
|
virtual void clearSessionTables()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3008,7 +3008,7 @@ QList<ServerInfo_ModeratorLogin> Servatrice_DatabaseInterface::getModeratorLastL
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
Servatrice_DatabaseInterface::UptimeSnapshot Servatrice_DatabaseInterface::getLatestUptimeSnapshot(int serverId)
|
Server_DatabaseInterface::UptimeSnapshot Servatrice_DatabaseInterface::getLatestUptimeSnapshot(int serverId)
|
||||||
{
|
{
|
||||||
UptimeSnapshot snapshot;
|
UptimeSnapshot snapshot;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -257,18 +257,7 @@ public:
|
||||||
|
|
||||||
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
// Uptime snapshot as recorded by Servatrice::statusUpdate() into the
|
||||||
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
// {prefix}_uptime table. valid is false when no snapshot exists yet.
|
||||||
struct UptimeSnapshot
|
UptimeSnapshot getLatestUptimeSnapshot(int serverId) override;
|
||||||
{
|
|
||||||
bool valid = false;
|
|
||||||
quint64 usersCount = 0;
|
|
||||||
quint64 modsCount = 0;
|
|
||||||
quint64 gamesCount = 0;
|
|
||||||
quint64 txBytes = 0;
|
|
||||||
quint64 rxBytes = 0;
|
|
||||||
quint64 uptimeSecs = 0;
|
|
||||||
quint64 timest = 0;
|
|
||||||
};
|
|
||||||
UptimeSnapshot getLatestUptimeSnapshot(int serverId);
|
|
||||||
bool removeUserAvatar(const QString &userName);
|
bool removeUserAvatar(const QString &userName);
|
||||||
|
|
||||||
// Outcome of removeUserBanner(), so the caller can tell a missing user apart
|
// Outcome of removeUserBanner(), so the caller can tell a missing user apart
|
||||||
|
|
|
||||||
|
|
@ -2186,13 +2186,13 @@ Response::ResponseCode AbstractServerSocketInterface::cmdReportUserInfo(const Co
|
||||||
Response::ResponseCode AbstractServerSocketInterface::cmdGetServerStats(const Command_GetServerStats & /*cmd */,
|
Response::ResponseCode AbstractServerSocketInterface::cmdGetServerStats(const Command_GetServerStats & /*cmd */,
|
||||||
ResponseContainer &rc)
|
ResponseContainer &rc)
|
||||||
{
|
{
|
||||||
if (!sqlInterface->checkSql()) {
|
if (!databaseInterface->checkSql()) {
|
||||||
return Response::RespInternalError;
|
return Response::RespInternalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Servatrice::statusUpdate() periodically snapshots server health into the
|
// Servatrice::statusUpdate() periodically snapshots server health into the
|
||||||
// uptime table. Serve the freshest snapshot for this server.
|
// uptime table. Serve the freshest snapshot for this server.
|
||||||
const auto snapshot = sqlInterface->getLatestUptimeSnapshot(servatrice->getServerID());
|
const auto snapshot = databaseInterface->getLatestUptimeSnapshot(servatrice->getServerID());
|
||||||
if (!snapshot.valid) {
|
if (!snapshot.valid) {
|
||||||
// No snapshot yet (fresh server, or statusUpdate() has not ticked).
|
// No snapshot yet (fresh server, or statusUpdate() has not ticked).
|
||||||
return Response::RespInternalError;
|
return Response::RespInternalError;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue