mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:36:45 +02:00
Simplify BackupHandler pattern
This commit is contained in:
parent
84761c003d
commit
ce93b9a1f4
5 changed files with 22 additions and 65 deletions
|
@ -18,68 +18,22 @@
|
||||||
|
|
||||||
#include <quazip5/quazip.h>
|
#include <quazip5/quazip.h>
|
||||||
|
|
||||||
class BackupHandler {
|
class BackupHandlerInterface {
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
virtual ~BackupHandlerInterface() = default;
|
||||||
BackupHandler(T* x) : _self(new Model<T>(x)) {}
|
|
||||||
|
|
||||||
void loadBackup(QuaZip& zip) {
|
virtual void loadBackup(QuaZip& zip) = 0;
|
||||||
_self->loadBackup(zip);
|
virtual void createBackup(QuaZip& zip) = 0;
|
||||||
}
|
virtual void recoverBackup(QuaZip& zip) = 0;
|
||||||
void createBackup(QuaZip& zip) {
|
virtual void deleteBackup(QuaZip& zip) = 0;
|
||||||
_self->createBackup(zip);
|
virtual void consolidateBackup(QuaZip& zip) = 0;
|
||||||
}
|
|
||||||
void recoverBackup(QuaZip& zip) {
|
|
||||||
_self->recoverBackup(zip);
|
|
||||||
}
|
|
||||||
void deleteBackup(QuaZip& zip) {
|
|
||||||
_self->deleteBackup(zip);
|
|
||||||
}
|
|
||||||
void consolidateBackup(QuaZip& zip) {
|
|
||||||
_self->consolidateBackup(zip);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Concept {
|
|
||||||
virtual ~Concept() = default;
|
|
||||||
|
|
||||||
virtual void loadBackup(QuaZip& zip) = 0;
|
|
||||||
virtual void createBackup(QuaZip& zip) = 0;
|
|
||||||
virtual void recoverBackup(QuaZip& zip) = 0;
|
|
||||||
virtual void deleteBackup(QuaZip& zip) = 0;
|
|
||||||
virtual void consolidateBackup(QuaZip& zip) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct Model : Concept {
|
|
||||||
Model(T* x) : data(x) {}
|
|
||||||
|
|
||||||
void loadBackup(QuaZip& zip) override {
|
|
||||||
data->loadBackup(zip);
|
|
||||||
}
|
|
||||||
void createBackup(QuaZip& zip) override {
|
|
||||||
data->createBackup(zip);
|
|
||||||
}
|
|
||||||
void recoverBackup(QuaZip& zip) override {
|
|
||||||
data->recoverBackup(zip);
|
|
||||||
}
|
|
||||||
void deleteBackup(QuaZip& zip) override {
|
|
||||||
data->deleteBackup(zip);
|
|
||||||
}
|
|
||||||
void consolidateBackup(QuaZip& zip) override {
|
|
||||||
data->consolidateBackup(zip);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<T> data;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<Concept> _self;
|
|
||||||
};
|
};
|
||||||
|
using BackupHandlerPointer = std::unique_ptr<BackupHandlerInterface>;
|
||||||
|
|
||||||
#include <quazip5/quazipfile.h>
|
#include <quazip5/quazipfile.h>
|
||||||
#include <OctreeUtils.h>
|
#include <OctreeUtils.h>
|
||||||
|
|
||||||
class EntitiesBackupHandler {
|
class EntitiesBackupHandler : public BackupHandlerInterface {
|
||||||
public:
|
public:
|
||||||
EntitiesBackupHandler(QString entitiesFilePath, QString entitiesReplacementFilePath) :
|
EntitiesBackupHandler(QString entitiesFilePath, QString entitiesReplacementFilePath) :
|
||||||
_entitiesFilePath(entitiesFilePath),
|
_entitiesFilePath(entitiesFilePath),
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include <ReceivedMessage.h>
|
#include <ReceivedMessage.h>
|
||||||
|
|
||||||
|
#include "BackupHandler.h"
|
||||||
|
|
||||||
class QuaZip;
|
class QuaZip;
|
||||||
|
|
||||||
struct AssetServerBackup {
|
struct AssetServerBackup {
|
||||||
|
@ -32,7 +34,7 @@ struct AssetServerBackup {
|
||||||
bool corruptedBackup;
|
bool corruptedBackup;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BackupSupervisor : public QObject {
|
class BackupSupervisor : public QObject, public BackupHandlerInterface {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -39,7 +39,8 @@ static const QString DATETIME_FORMAT { "yyyy-MM-dd_HH-mm-ss" };
|
||||||
static const QString DATETIME_FORMAT_RE { "\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}" };
|
static const QString DATETIME_FORMAT_RE { "\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}" };
|
||||||
static const QString AUTOMATIC_BACKUP_PREFIX { "autobackup-" };
|
static const QString AUTOMATIC_BACKUP_PREFIX { "autobackup-" };
|
||||||
static const QString MANUAL_BACKUP_PREFIX { "backup-" };
|
static const QString MANUAL_BACKUP_PREFIX { "backup-" };
|
||||||
void DomainContentBackupManager::addBackupHandler(BackupHandler handler) {
|
|
||||||
|
void DomainContentBackupManager::addBackupHandler(BackupHandlerPointer handler) {
|
||||||
_backupHandlers.push_back(std::move(handler));
|
_backupHandlers.push_back(std::move(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +239,7 @@ void DomainContentBackupManager::recoverFromBackup(MiniPromise::Promise promise,
|
||||||
success = false;
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
for (auto& handler : _backupHandlers) {
|
for (auto& handler : _backupHandlers) {
|
||||||
handler.recoverBackup(zip);
|
handler->recoverBackup(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Successfully recovered from " << backupName;
|
qDebug() << "Successfully recovered from " << backupName;
|
||||||
|
@ -339,7 +340,7 @@ void DomainContentBackupManager::load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& handler : _backupHandlers) {
|
for (auto& handler : _backupHandlers) {
|
||||||
handler.loadBackup(zip);
|
handler->loadBackup(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
zip.close();
|
zip.close();
|
||||||
|
@ -402,7 +403,7 @@ void DomainContentBackupManager::consolidate(QString fileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& handler : _backupHandlers) {
|
for (auto& handler : _backupHandlers) {
|
||||||
handler.consolidateBackup(zip);
|
handler->consolidateBackup(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
zip.close();
|
zip.close();
|
||||||
|
@ -437,7 +438,7 @@ std::pair<bool, QString> DomainContentBackupManager::createBackup(const QString&
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& handler : _backupHandlers) {
|
for (auto& handler : _backupHandlers) {
|
||||||
handler.createBackup(zip);
|
handler->createBackup(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
zip.close();
|
zip.close();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
||||||
bool debugTimestampNow = false);
|
bool debugTimestampNow = false);
|
||||||
|
|
||||||
void addBackupHandler(BackupHandler handler);
|
void addBackupHandler(BackupHandlerPointer handler);
|
||||||
std::vector<BackupItemInfo> getAllBackups();
|
std::vector<BackupItemInfo> getAllBackups();
|
||||||
|
|
||||||
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
||||||
|
@ -82,7 +82,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString _backupDirectory;
|
const QString _backupDirectory;
|
||||||
std::vector<BackupHandler> _backupHandlers;
|
std::vector<BackupHandlerPointer> _backupHandlers;
|
||||||
int _persistInterval { 0 };
|
int _persistInterval { 0 };
|
||||||
|
|
||||||
int64_t _lastCheck { 0 };
|
int64_t _lastCheck { 0 };
|
||||||
|
|
|
@ -296,8 +296,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
maybeHandleReplacementEntityFile();
|
maybeHandleReplacementEntityFile();
|
||||||
|
|
||||||
_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(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath()));
|
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));
|
||||||
_contentManager->addBackupHandler(new BackupSupervisor(getContentBackupDir()));
|
_contentManager->addBackupHandler(BackupHandlerPointer(new BackupSupervisor(getContentBackupDir())));
|
||||||
_contentManager->initialize(true);
|
_contentManager->initialize(true);
|
||||||
|
|
||||||
qDebug() << "Existing backups:";
|
qDebug() << "Existing backups:";
|
||||||
|
|
Loading…
Reference in a new issue