diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 3de4c5fd3f..c73e8e1d34 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -6,7 +6,6 @@ setup_hifi_project(Core Gui Network Script Quick WebSockets) if (APPLE) set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "@executable_path/../Frameworks") endif () -set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "/testing/") setup_memory_debugger() diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 6704786c36..05d070606a 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -1044,12 +1044,13 @@ void OctreeServer::readConfiguration() { // If persist filename does not exist, let's see if there is one beside the application binary // If there is, let's copy it over to our target persist directory QDir persistPath { _persistFilePath }; - _persistAbsoluteFilePath = persistPath.absolutePath(); if (persistPath.isRelative()) { // if the domain settings passed us a relative path, make an absolute path that is relative to the // default data directory _persistAbsoluteFilePath = QDir(PathUtils::getAppDataFilePath("entities/")).absoluteFilePath(_persistFilePath); + } else { + _persistAbsoluteFilePath = persistPath.absolutePath(); } qDebug() << "persistFilePath=" << _persistFilePath; @@ -1174,6 +1175,11 @@ void OctreeServer::domainSettingsRequestComplete() { } void OctreeServer::handleOctreeDataFileReply(QSharedPointer message) { + if (_state != OctreeServerState::WaitingForOctreeDataNegotation) { + qCWarning(octree_server) << "Server received ocree data file reply but is not currently negotiating."; + return; + } + bool includesNewData; message->readPrimitive(&includesNewData); QByteArray replaceData; @@ -1188,8 +1194,7 @@ void OctreeServer::handleOctreeDataFileReply(QSharedPointer mes if (OctreeUtils::readOctreeDataInfoFromFile(_persistAbsoluteFilePath, &data)) { if (data.id.isNull()) { qCDebug(octree_server) << "Current octree data has a null id, updating"; - data.id = QUuid::createUuid(); - data.version = 0; + data.resetIdAndVersion(); QFile file(_persistAbsoluteFilePath); if (file.open(QIODevice::WriteOnly)) { @@ -1202,17 +1207,17 @@ void OctreeServer::handleOctreeDataFileReply(QSharedPointer mes } } } + + _state = OctreeServerState::Running; beginRunning(replaceData); } void OctreeServer::beginRunning(QByteArray replaceData) { - if (_state == OctreeServerState::Running) { - qCWarning(octree_server) << "Server is already running"; + if (_state != OctreeServerState::Running) { + qCWarning(octree_server) << "Server is not running"; return; } - _state = OctreeServerState::Running; - auto nodeList = DependencyManager::get(); // we need to ask the DS about agents so we can ping/reply with them diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index 6f77920ee0..eab71647e3 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -149,8 +149,6 @@ private slots: void domainSettingsRequestComplete(); void handleOctreeQueryPacket(QSharedPointer message, SharedNodePointer senderNode); void handleOctreeDataNackPacket(QSharedPointer message, SharedNodePointer senderNode); - //void handleOctreeFileReplacement(QSharedPointer message); - //void handleOctreeFileReplacementFromURL(QSharedPointer message); void handleOctreeDataFileReply(QSharedPointer message); void removeSendThread(); diff --git a/domain-server/src/DomainContentBackupManager.cpp b/domain-server/src/DomainContentBackupManager.cpp index 0eca10f8af..4f544d7011 100644 --- a/domain-server/src/DomainContentBackupManager.cpp +++ b/domain-server/src/DomainContentBackupManager.cpp @@ -279,23 +279,9 @@ void DomainContentBackupManager::backup() { qDebug() << "Created backup: " << fileName; - removeOldBackupVersions(rule); + rule.lastBackupSeconds = nowSeconds; - if (rule.maxBackupVersions > 0) { - // Execute backup - auto result = true; - if (result) { - qCDebug(domain_server) << "DONE backing up persist file..."; - rule.lastBackupSeconds = nowSeconds; - } else { - qCDebug(domain_server) << "ERROR in backing up persist file..."; - perror("ERROR in backing up persist file"); - } - } else { - qCDebug(domain_server) << "This backup rule" << rule.name << " has Max Rolled Backup Versions less than 1 [" - << rule.maxBackupVersions << "]." - << " There are no backups to be done..."; - } + removeOldBackupVersions(rule); } else { qCDebug(domain_server) << "Backup not needed for this rule [" << rule.name << "]..."; } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index edb3fe77dd..8f0e26375e 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -289,7 +289,6 @@ DomainServer::DomainServer(int argc, char* argv[]) : } } - qDebug() << "Starting persist thread"; if (QDir(getEntitiesDirPath()).mkpath(".")) { qCDebug(domain_server) << "Created entities data directory"; } @@ -1785,7 +1784,8 @@ void DomainServer::processOctreeDataRequestMessage(QSharedPointerreadPrimitive(&remoteHasExistingData); if (remoteHasExistingData) { - auto idData = message->read(16); + constexpr size_t UUID_SIZE_BYTES = 16; + auto idData = message->read(UUID_SIZE_BYTES); id = QUuid::fromRfc4122(idData); message->readPrimitive(&version); qCDebug(domain_server) << "Entity server does have existing data: ID(" << id << ") DataVersion(" << version << ")"; @@ -1794,7 +1794,6 @@ void DomainServer::processOctreeDataRequestMessage(QSharedPointer(); - limitedNodeList->eachMatchingNode([](const SharedNodePointer& node) { - return node->getType() == NodeType::EntityServer && node->getActiveSocket(); - }, [&octreeFile, limitedNodeList](const SharedNodePointer& octreeNode) { - // setup a packet to send to this octree server with the new octree file data - auto octreeFilePacketList = NLPacketList::create(PacketType::OctreeFileReplacement, QByteArray(), true, true); - octreeFilePacketList->write(octreeFile); - - qDebug() << "Sending an octree file replacement of" << octreeFile.size() << "bytes to" << octreeNode; - - limitedNodeList->sendPacketList(std::move(octreeFilePacketList), *octreeNode); - }); } void DomainServer::handleOctreeFileReplacementFromURLRequest(QSharedPointer message) { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c031c0e8d4..bc44bb4cf0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6247,7 +6247,6 @@ bool Application::askToReplaceDomainContent(const QString& url) { }, [&urlData, limitedNodeList, &domainHandler](const SharedNodePointer& octreeNode) { auto octreeFilePacket = NLPacket::create(PacketType::OctreeFileReplacementFromUrl, urlData.size(), true); octreeFilePacket->write(urlData); - qDebug() << "WRiting url data: " << urlData; limitedNodeList->sendPacket(std::move(octreeFilePacket), domainHandler.getSockAddr()); }); auto addressManager = DependencyManager::get(); diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 4f96a6d072..f632bcf140 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2244,7 +2244,7 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer if (! entityDescription.contains("Entities")) { entityDescription["Entities"] = QVariantList(); } - entityDescription["DataVersion"] = ++_persistDataVersion; + entityDescription["DataVersion"] = _persistDataVersion; entityDescription["Id"] = _persistID; QScriptEngine scriptEngine; RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues, diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index 228779dbba..bea036add3 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -1,4 +1,3 @@ set(TARGET_NAME octree) -include_directories(system /usr/local/Cellar/qt5/5.9.1/include) setup_hifi_library() link_hifi_libraries(shared networking) diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 23352a548c..d62cbad765 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -1757,19 +1757,6 @@ bool Octree::readJSONFromStream(uint64_t streamLength, QDataStream& inputStream, QVariant asVariant = asDocument.toVariant(); QVariantMap asMap = asVariant.toMap(); bool success = readFromMap(asMap); - /* - if (success) { - if (asMap.contains("DataVersion") && asMap.contains("Id")) { - bool versionOk; - auto dataVersion = asMap["DataVersion"].toLongLong(&versionOk); - if (versionOk) { - auto id = asMap["Id"].toUuid(); - _persistDataVersion = dataVersion; - _persistID = id; - } - } - } - */ delete[] rawData; return success; } diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 1b9495717b..8954e53f8b 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -341,6 +341,8 @@ public: virtual quint64 getAverageLoggingTime() const { return 0; } virtual quint64 getAverageFilterTime() const { return 0; } + void incrementPersistDataVersion() { _persistDataVersion++; } + signals: void importSize(float x, float y, float z); void importProgress(int progress); diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index d51bd540bc..a669b7d3bb 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -311,6 +311,7 @@ void OctreePersistThread::persist() { backup(); // handle backup if requested qCDebug(octree) << "persist operation DONE with backup..."; + _tree->incrementPersistDataVersion(); // create our "lock" file to indicate we're saving. QString lockFileName = _filename + ".lock"; diff --git a/libraries/octree/src/OctreeUtils.cpp b/libraries/octree/src/OctreeUtils.cpp index e068e83b23..85ea3beb86 100644 --- a/libraries/octree/src/OctreeUtils.cpp +++ b/libraries/octree/src/OctreeUtils.cpp @@ -80,6 +80,9 @@ float getOrthographicAccuracySize(float octreeSizeScale, int boundaryLevelAdjust return (smallestSize * MAX_VISIBILITY_DISTANCE_FOR_UNIT_ELEMENT) / boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale); } +// Reads octree file and parses it into a QJsonDocument. Handles both gzipped and non-gzipped files. +// Returns true if the file was successfully opened and parsed, otherwise false. +// Example failures: file does not exist, gzipped file cannot be unzipped, invalid JSON. bool OctreeUtils::readOctreeFile(QString path, QJsonDocument* doc) { QFile file(path); if (!file.open(QIODevice::ReadOnly)) { @@ -129,6 +132,8 @@ bool OctreeUtils::readOctreeDataInfoFromData(QByteArray data, OctreeUtils::RawOc return readOctreeDataInfoFromJSON(root, octreeData); } +// Reads octree file and parses it into a RawOctreeData object. +// Returns false if readOctreeFile fails. bool OctreeUtils::readOctreeDataInfoFromFile(QString path, OctreeUtils::RawOctreeData* octreeData) { QJsonDocument doc; if (!OctreeUtils::readOctreeFile(path, &doc)) { @@ -163,4 +168,9 @@ QByteArray OctreeUtils::RawOctreeData::toGzippedByteArray() { } return gzData; +} + +void OctreeUtils::RawOctreeData::resetIdAndVersion() { + id = QUuid::createUuid(); + version = OctreeUtils::INITIAL_VERSION; } \ No newline at end of file diff --git a/libraries/octree/src/OctreeUtils.h b/libraries/octree/src/OctreeUtils.h index 18b0d27883..6fb0e62bcb 100644 --- a/libraries/octree/src/OctreeUtils.h +++ b/libraries/octree/src/OctreeUtils.h @@ -22,14 +22,18 @@ class QJsonDocument; namespace OctreeUtils { +using Version = int64_t; +constexpr Version INITIAL_VERSION = 0; + // RawOctreeData is an intermediate format between JSON and a fully deserialized Octree. class RawOctreeData { public: QUuid id { QUuid() }; - int64_t version { -1 }; + Version version { -1 }; QJsonArray octreeData; + void resetIdAndVersion(); QByteArray toByteArray(); QByteArray toGzippedByteArray(); };