mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-26 03:03:19 +02:00
Rename backup supervisor
This commit is contained in:
parent
4482f9c83c
commit
d8d05fe045
4 changed files with 36 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// BackupSupervisor.cpp
|
// AssetsBackupHandler.cpp
|
||||||
// domain-server/src
|
// domain-server/src
|
||||||
//
|
//
|
||||||
// Created by Clement Brisset on 1/12/18.
|
// Created by Clement Brisset on 1/12/18.
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "BackupSupervisor.h"
|
#include "AssetsBackupHandler.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
|
@ -31,7 +31,7 @@ using namespace std;
|
||||||
Q_DECLARE_LOGGING_CATEGORY(backup_supervisor)
|
Q_DECLARE_LOGGING_CATEGORY(backup_supervisor)
|
||||||
Q_LOGGING_CATEGORY(backup_supervisor, "hifi.backup-supervisor");
|
Q_LOGGING_CATEGORY(backup_supervisor, "hifi.backup-supervisor");
|
||||||
|
|
||||||
BackupSupervisor::BackupSupervisor(const QString& backupDirectory) :
|
AssetsBackupHandler::AssetsBackupHandler(const QString& backupDirectory) :
|
||||||
_assetsDirectory(backupDirectory + ASSETS_DIR)
|
_assetsDirectory(backupDirectory + ASSETS_DIR)
|
||||||
{
|
{
|
||||||
// Make sure the asset directory exists.
|
// Make sure the asset directory exists.
|
||||||
|
@ -41,7 +41,7 @@ BackupSupervisor::BackupSupervisor(const QString& backupDirectory) :
|
||||||
|
|
||||||
_mappingsRefreshTimer.setTimerType(Qt::CoarseTimer);
|
_mappingsRefreshTimer.setTimerType(Qt::CoarseTimer);
|
||||||
_mappingsRefreshTimer.setSingleShot(true);
|
_mappingsRefreshTimer.setSingleShot(true);
|
||||||
QObject::connect(&_mappingsRefreshTimer, &QTimer::timeout, this, &BackupSupervisor::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::nodeAdded, this, [this](SharedNodePointer node) {
|
||||||
|
@ -53,7 +53,7 @@ BackupSupervisor::BackupSupervisor(const QString& backupDirectory) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BackupSupervisor::refreshAssetsOnDisk() {
|
void AssetsBackupHandler::refreshAssetsOnDisk() {
|
||||||
QDir assetsDir { _assetsDirectory };
|
QDir assetsDir { _assetsDirectory };
|
||||||
auto assetNames = assetsDir.entryList(QDir::Files);
|
auto assetNames = assetsDir.entryList(QDir::Files);
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void BackupSupervisor::refreshAssetsOnDisk() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::refreshAssetsInBackups() {
|
void AssetsBackupHandler::refreshAssetsInBackups() {
|
||||||
_assetsInBackups.clear();
|
_assetsInBackups.clear();
|
||||||
for (const auto& backup : _backups) {
|
for (const auto& backup : _backups) {
|
||||||
for (const auto& mapping : backup.mappings) {
|
for (const auto& mapping : backup.mappings) {
|
||||||
|
@ -73,7 +73,7 @@ void BackupSupervisor::refreshAssetsInBackups() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::checkForMissingAssets() {
|
void AssetsBackupHandler::checkForMissingAssets() {
|
||||||
vector<AssetUtils::AssetHash> missingAssets;
|
vector<AssetUtils::AssetHash> missingAssets;
|
||||||
set_difference(begin(_assetsInBackups), end(_assetsInBackups),
|
set_difference(begin(_assetsInBackups), end(_assetsInBackups),
|
||||||
begin(_assetsOnDisk), end(_assetsOnDisk),
|
begin(_assetsOnDisk), end(_assetsOnDisk),
|
||||||
|
@ -83,7 +83,7 @@ void BackupSupervisor::checkForMissingAssets() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::checkForAssetsToDelete() {
|
void AssetsBackupHandler::checkForAssetsToDelete() {
|
||||||
vector<AssetUtils::AssetHash> deprecatedAssets;
|
vector<AssetUtils::AssetHash> deprecatedAssets;
|
||||||
set_difference(begin(_assetsOnDisk), end(_assetsOnDisk),
|
set_difference(begin(_assetsOnDisk), end(_assetsOnDisk),
|
||||||
begin(_assetsInBackups), end(_assetsInBackups),
|
begin(_assetsInBackups), end(_assetsInBackups),
|
||||||
|
@ -101,7 +101,7 @@ void BackupSupervisor::checkForAssetsToDelete() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::loadBackup(QuaZip& zip) {
|
void AssetsBackupHandler::loadBackup(QuaZip& zip) {
|
||||||
_backups.push_back({ zip.getZipName(), {}, false });
|
_backups.push_back({ zip.getZipName(), {}, false });
|
||||||
auto& backup = _backups.back();
|
auto& backup = _backups.back();
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ void BackupSupervisor::loadBackup(QuaZip& zip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::createBackup(QuaZip& zip) {
|
void AssetsBackupHandler::createBackup(QuaZip& zip) {
|
||||||
if (operationInProgress()) {
|
if (operationInProgress()) {
|
||||||
qCWarning(backup_supervisor) << "There is already an operation in progress.";
|
qCWarning(backup_supervisor) << "There is already an operation in progress.";
|
||||||
return;
|
return;
|
||||||
|
@ -192,7 +192,7 @@ void BackupSupervisor::createBackup(QuaZip& zip) {
|
||||||
_backups.push_back(backup);
|
_backups.push_back(backup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::recoverBackup(QuaZip& zip) {
|
void AssetsBackupHandler::recoverBackup(QuaZip& zip) {
|
||||||
if (operationInProgress()) {
|
if (operationInProgress()) {
|
||||||
qCWarning(backup_supervisor) << "There is already a backup/restore in progress.";
|
qCWarning(backup_supervisor) << "There is already a backup/restore in progress.";
|
||||||
return;
|
return;
|
||||||
|
@ -225,7 +225,7 @@ void BackupSupervisor::recoverBackup(QuaZip& zip) {
|
||||||
restoreAllAssets();
|
restoreAllAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::deleteBackup(QuaZip& zip) {
|
void AssetsBackupHandler::deleteBackup(QuaZip& zip) {
|
||||||
if (operationInProgress()) {
|
if (operationInProgress()) {
|
||||||
qCWarning(backup_supervisor) << "There is a backup/restore in progress.";
|
qCWarning(backup_supervisor) << "There is a backup/restore in progress.";
|
||||||
return;
|
return;
|
||||||
|
@ -243,7 +243,7 @@ void BackupSupervisor::deleteBackup(QuaZip& zip) {
|
||||||
checkForAssetsToDelete();
|
checkForAssetsToDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::consolidateBackup(QuaZip& zip) {
|
void AssetsBackupHandler::consolidateBackup(QuaZip& zip) {
|
||||||
if (operationInProgress()) {
|
if (operationInProgress()) {
|
||||||
qCWarning(backup_supervisor) << "There is a backup/restore in progress.";
|
qCWarning(backup_supervisor) << "There is a backup/restore in progress.";
|
||||||
return;
|
return;
|
||||||
|
@ -285,7 +285,7 @@ void BackupSupervisor::consolidateBackup(QuaZip& zip) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::refreshMappings() {
|
void AssetsBackupHandler::refreshMappings() {
|
||||||
auto assetClient = DependencyManager::get<AssetClient>();
|
auto assetClient = DependencyManager::get<AssetClient>();
|
||||||
auto request = assetClient->createGetAllMappingsRequest();
|
auto request = assetClient->createGetAllMappingsRequest();
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ void BackupSupervisor::refreshMappings() {
|
||||||
request->start();
|
request->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::downloadMissingFiles(const AssetUtils::Mappings& mappings) {
|
void AssetsBackupHandler::downloadMissingFiles(const AssetUtils::Mappings& mappings) {
|
||||||
auto wasEmpty = _assetsLeftToRequest.empty();
|
auto wasEmpty = _assetsLeftToRequest.empty();
|
||||||
|
|
||||||
for (const auto& mapping : mappings) {
|
for (const auto& mapping : mappings) {
|
||||||
|
@ -330,7 +330,7 @@ void BackupSupervisor::downloadMissingFiles(const AssetUtils::Mappings& mappings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::downloadNextMissingFile() {
|
void AssetsBackupHandler::downloadNextMissingFile() {
|
||||||
if (_assetsLeftToRequest.empty()) {
|
if (_assetsLeftToRequest.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ void BackupSupervisor::downloadNextMissingFile() {
|
||||||
assetRequest->start();
|
assetRequest->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BackupSupervisor::writeAssetFile(const AssetUtils::AssetHash& hash, const QByteArray& data) {
|
bool AssetsBackupHandler::writeAssetFile(const AssetUtils::AssetHash& hash, const QByteArray& data) {
|
||||||
QDir assetsDir { _assetsDirectory };
|
QDir assetsDir { _assetsDirectory };
|
||||||
QFile file { assetsDir.filePath(hash) };
|
QFile file { assetsDir.filePath(hash) };
|
||||||
if (!file.open(QFile::WriteOnly)) {
|
if (!file.open(QFile::WriteOnly)) {
|
||||||
|
@ -380,7 +380,7 @@ bool BackupSupervisor::writeAssetFile(const AssetUtils::AssetHash& hash, const Q
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::computeServerStateDifference(const AssetUtils::Mappings& currentMappings,
|
void AssetsBackupHandler::computeServerStateDifference(const AssetUtils::Mappings& currentMappings,
|
||||||
const AssetUtils::Mappings& newMappings) {
|
const AssetUtils::Mappings& newMappings) {
|
||||||
_mappingsLeftToSet.reserve((int)newMappings.size());
|
_mappingsLeftToSet.reserve((int)newMappings.size());
|
||||||
_assetsLeftToUpload.reserve((int)newMappings.size());
|
_assetsLeftToUpload.reserve((int)newMappings.size());
|
||||||
|
@ -415,11 +415,11 @@ void BackupSupervisor::computeServerStateDifference(const AssetUtils::Mappings&
|
||||||
qCDebug(backup_supervisor) << "Assets to upload:" << _assetsLeftToUpload.size();
|
qCDebug(backup_supervisor) << "Assets to upload:" << _assetsLeftToUpload.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::restoreAllAssets() {
|
void AssetsBackupHandler::restoreAllAssets() {
|
||||||
restoreNextAsset();
|
restoreNextAsset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::restoreNextAsset() {
|
void AssetsBackupHandler::restoreNextAsset() {
|
||||||
if (_assetsLeftToUpload.empty()) {
|
if (_assetsLeftToUpload.empty()) {
|
||||||
updateMappings();
|
updateMappings();
|
||||||
return;
|
return;
|
||||||
|
@ -447,7 +447,7 @@ void BackupSupervisor::restoreNextAsset() {
|
||||||
request->start();
|
request->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::updateMappings() {
|
void AssetsBackupHandler::updateMappings() {
|
||||||
auto assetClient = DependencyManager::get<AssetClient>();
|
auto assetClient = DependencyManager::get<AssetClient>();
|
||||||
for (const auto& mapping : _mappingsLeftToSet) {
|
for (const auto& mapping : _mappingsLeftToSet) {
|
||||||
auto request = assetClient->createSetMappingRequest(mapping.first, mapping.second);
|
auto request = assetClient->createSetMappingRequest(mapping.first, mapping.second);
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// BackupSupervisor.h
|
// AssetsBackupHandler.h
|
||||||
// domain-server/src
|
// domain-server/src
|
||||||
//
|
//
|
||||||
// Created by Clement Brisset on 1/12/18.
|
// Created by Clement Brisset on 1/12/18.
|
||||||
|
@ -9,8 +9,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef hifi_BackupSupervisor_h
|
#ifndef hifi_AssetsBackupHandler_h
|
||||||
#define hifi_BackupSupervisor_h
|
#define hifi_AssetsBackupHandler_h
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -28,17 +28,11 @@
|
||||||
|
|
||||||
class QuaZip;
|
class QuaZip;
|
||||||
|
|
||||||
struct AssetServerBackup {
|
class AssetsBackupHandler : public QObject, public BackupHandlerInterface {
|
||||||
QString filePath;
|
|
||||||
AssetUtils::Mappings mappings;
|
|
||||||
bool corruptedBackup;
|
|
||||||
};
|
|
||||||
|
|
||||||
class BackupSupervisor : public QObject, public BackupHandlerInterface {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BackupSupervisor(const QString& backupDirectory);
|
AssetsBackupHandler(const QString& backupDirectory);
|
||||||
|
|
||||||
void loadBackup(QuaZip& zip);
|
void loadBackup(QuaZip& zip);
|
||||||
void createBackup(QuaZip& zip);
|
void createBackup(QuaZip& zip);
|
||||||
|
@ -75,6 +69,12 @@ private:
|
||||||
quint64 _lastMappingsRefresh { 0 };
|
quint64 _lastMappingsRefresh { 0 };
|
||||||
AssetUtils::Mappings _currentMappings;
|
AssetUtils::Mappings _currentMappings;
|
||||||
|
|
||||||
|
struct AssetServerBackup {
|
||||||
|
QString filePath;
|
||||||
|
AssetUtils::Mappings mappings;
|
||||||
|
bool corruptedBackup;
|
||||||
|
};
|
||||||
|
|
||||||
bool _operationInProgress { false };
|
bool _operationInProgress { false };
|
||||||
|
|
||||||
// Internal storage for backups on disk
|
// Internal storage for backups on disk
|
||||||
|
@ -93,4 +93,4 @@ private:
|
||||||
int _mappingRequestsInFlight { 0 };
|
int _mappingRequestsInFlight { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* hifi_BackupSupervisor_h */
|
#endif /* hifi_AssetsBackupHandler_h */
|
|
@ -45,7 +45,7 @@
|
||||||
#include <Trace.h>
|
#include <Trace.h>
|
||||||
#include <StatTracker.h>
|
#include <StatTracker.h>
|
||||||
|
|
||||||
#include "BackupSupervisor.h"
|
#include "AssetsBackupHandler.h"
|
||||||
#include "DomainServerNodeData.h"
|
#include "DomainServerNodeData.h"
|
||||||
#include "NodeConnectionData.h"
|
#include "NodeConnectionData.h"
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
|
|
||||||
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), _settingsManager.settingsResponseObjectForType("6")["entity_server_settings"].toObject()));
|
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), _settingsManager.settingsResponseObjectForType("6")["entity_server_settings"].toObject()));
|
||||||
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));
|
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));
|
||||||
_contentManager->addBackupHandler(BackupHandlerPointer(new BackupSupervisor(getContentBackupDir())));
|
_contentManager->addBackupHandler(BackupHandlerPointer(new AssetsBackupHandler(getContentBackupDir())));
|
||||||
_contentManager->initialize(true);
|
_contentManager->initialize(true);
|
||||||
|
|
||||||
qDebug() << "Existing backups:";
|
qDebug() << "Existing backups:";
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <HTTPSConnection.h>
|
#include <HTTPSConnection.h>
|
||||||
#include <LimitedNodeList.h>
|
#include <LimitedNodeList.h>
|
||||||
|
|
||||||
#include "BackupSupervisor.h"
|
#include "AssetsBackupHandler.h"
|
||||||
#include "DomainGatekeeper.h"
|
#include "DomainGatekeeper.h"
|
||||||
#include "DomainMetadata.h"
|
#include "DomainMetadata.h"
|
||||||
#include "DomainServerSettingsManager.h"
|
#include "DomainServerSettingsManager.h"
|
||||||
|
|
Loading…
Reference in a new issue