mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:21:16 +02:00
Merge pull request #12503 from Atlante45/feat/backups-integration
timing CR for content archives
This commit is contained in:
commit
9c546ce43d
3 changed files with 17 additions and 17 deletions
|
@ -447,7 +447,7 @@ void AssetServer::replayRequests() {
|
||||||
RequestQueue queue;
|
RequestQueue queue;
|
||||||
{
|
{
|
||||||
QMutexLocker lock { &_queuedRequestsMutex };
|
QMutexLocker lock { &_queuedRequestsMutex };
|
||||||
qSwap(queue, _queuedRequests);
|
std::swap(queue, _queuedRequests);
|
||||||
_isQueueingRequests = false;
|
_isQueueingRequests = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,13 @@
|
||||||
#include <MappingRequest.h>
|
#include <MappingRequest.h>
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
|
|
||||||
static const QString ASSETS_DIR = "/assets/";
|
|
||||||
static const QString MAPPINGS_FILE = "mappings.json";
|
|
||||||
static const QString ZIP_ASSETS_FOLDER = "files";
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static const QString ASSETS_DIR { "/assets/" };
|
||||||
|
static const QString MAPPINGS_FILE { "mappings.json" };
|
||||||
|
static const QString ZIP_ASSETS_FOLDER { "files" };
|
||||||
|
static const chrono::minutes MAX_REFRESH_TIME { 5 };
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(asset_backup)
|
Q_DECLARE_LOGGING_CATEGORY(asset_backup)
|
||||||
Q_LOGGING_CATEGORY(asset_backup, "hifi.asset-backup");
|
Q_LOGGING_CATEGORY(asset_backup, "hifi.asset-backup");
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ void AssetsBackupHandler::setupRefreshTimer() {
|
||||||
QObject::connect(&_mappingsRefreshTimer, &QTimer::timeout, this, &AssetsBackupHandler::refreshMappings);
|
QObject::connect(&_mappingsRefreshTimer, &QTimer::timeout, this, &AssetsBackupHandler::refreshMappings);
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
auto nodeList = DependencyManager::get<LimitedNodeList>();
|
||||||
QObject::connect(nodeList.data(), &LimitedNodeList::nodeAdded, this, [this](SharedNodePointer node) {
|
QObject::connect(nodeList.data(), &LimitedNodeList::nodeActivated, this, [this](SharedNodePointer node) {
|
||||||
if (node->getType() == NodeType::AssetServer) {
|
if (node->getType() == NodeType::AssetServer) {
|
||||||
// run immediately for the first time.
|
// run immediately for the first time.
|
||||||
_mappingsRefreshTimer.start(0);
|
_mappingsRefreshTimer.start(0);
|
||||||
|
@ -188,7 +189,7 @@ void AssetsBackupHandler::loadBackup(const QString& backupName, QuaZip& zip) {
|
||||||
|
|
||||||
QuaZipFile zipFile { &zip };
|
QuaZipFile zipFile { &zip };
|
||||||
if (!zipFile.open(QFile::ReadOnly)) {
|
if (!zipFile.open(QFile::ReadOnly)) {
|
||||||
qCCritical(asset_backup) << "Could not unzip backup file for load:" << backupName;
|
qCCritical(asset_backup) << "Could not unzip backup file for load:" << MAPPINGS_FILE;
|
||||||
qCCritical(asset_backup) << " Error:" << zip.getZipError();
|
qCCritical(asset_backup) << " Error:" << zip.getZipError();
|
||||||
backup.corruptedBackup = true;
|
backup.corruptedBackup = true;
|
||||||
return;
|
return;
|
||||||
|
@ -197,7 +198,7 @@ void AssetsBackupHandler::loadBackup(const QString& backupName, QuaZip& zip) {
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
auto document = QJsonDocument::fromJson(zipFile.readAll(), &error);
|
auto document = QJsonDocument::fromJson(zipFile.readAll(), &error);
|
||||||
if (document.isNull() || !document.isObject()) {
|
if (document.isNull() || !document.isObject()) {
|
||||||
qCCritical(asset_backup) << "Could not parse backup file to JSON object for load:" << backupName;
|
qCCritical(asset_backup) << "Could not parse backup file to JSON object for load:" << MAPPINGS_FILE;
|
||||||
qCCritical(asset_backup) << " Error:" << error.errorString();
|
qCCritical(asset_backup) << " Error:" << error.errorString();
|
||||||
backup.corruptedBackup = true;
|
backup.corruptedBackup = true;
|
||||||
return;
|
return;
|
||||||
|
@ -232,13 +233,12 @@ void AssetsBackupHandler::createBackup(const QString& backupName, QuaZip& zip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastMappingsRefresh == 0) {
|
if (_lastMappingsRefresh.time_since_epoch().count() == 0) {
|
||||||
qCWarning(asset_backup) << "Current mappings not yet loaded.";
|
qCWarning(asset_backup) << "Current mappings not yet loaded.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr quint64 MAX_REFRESH_TIME = 15 * 60 * 1000 * 1000;
|
if ((p_high_resolution_clock::now() - _lastMappingsRefresh) > MAX_REFRESH_TIME) {
|
||||||
if (usecTimestampNow() - _lastMappingsRefresh > MAX_REFRESH_TIME) {
|
|
||||||
qCWarning(asset_backup) << "Backing up asset mappings that might be stale.";
|
qCWarning(asset_backup) << "Backing up asset mappings that might be stale.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,14 +275,13 @@ void AssetsBackupHandler::recoverBackup(const QString& backupName, QuaZip& zip)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastMappingsRefresh == 0) {
|
if (_lastMappingsRefresh.time_since_epoch().count() == 0) {
|
||||||
qCWarning(asset_backup) << "Current mappings not yet loaded.";
|
qCWarning(asset_backup) << "Current mappings not yet loaded.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr quint64 MAX_REFRESH_TIME = 15 * 60 * 1000 * 1000;
|
if ((p_high_resolution_clock::now() - _lastMappingsRefresh) > MAX_REFRESH_TIME) {
|
||||||
if (usecTimestampNow() - _lastMappingsRefresh > MAX_REFRESH_TIME) {
|
qCWarning(asset_backup) << "Recovering while current asset mappings might be stale.";
|
||||||
qCWarning(asset_backup) << "Current asset mappings that might be stale.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& backup) {
|
auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& backup) {
|
||||||
|
@ -412,7 +411,7 @@ void AssetsBackupHandler::refreshMappings() {
|
||||||
_currentMappings.insert({ mapping.first, mapping.second.hash });
|
_currentMappings.insert({ mapping.first, mapping.second.hash });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_lastMappingsRefresh = usecTimestampNow();
|
_lastMappingsRefresh = p_high_resolution_clock::now();
|
||||||
|
|
||||||
downloadMissingFiles(_currentMappings);
|
downloadMissingFiles(_currentMappings);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <AssetUtils.h>
|
#include <AssetUtils.h>
|
||||||
#include <ReceivedMessage.h>
|
#include <ReceivedMessage.h>
|
||||||
|
#include <PortableHighResolutionClock.h>
|
||||||
|
|
||||||
#include "BackupHandler.h"
|
#include "BackupHandler.h"
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ private:
|
||||||
QString _assetsDirectory;
|
QString _assetsDirectory;
|
||||||
|
|
||||||
QTimer _mappingsRefreshTimer;
|
QTimer _mappingsRefreshTimer;
|
||||||
quint64 _lastMappingsRefresh { 0 };
|
p_high_resolution_clock::time_point _lastMappingsRefresh;
|
||||||
AssetUtils::Mappings _currentMappings;
|
AssetUtils::Mappings _currentMappings;
|
||||||
|
|
||||||
struct AssetServerBackup {
|
struct AssetServerBackup {
|
||||||
|
|
Loading…
Reference in a new issue