From b13c4c2055a431df1b6ef6d6ca05952d99a49ac5 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 10 Feb 2025 22:52:53 +0000 Subject: [PATCH] add option --force-assets to load oar. this will force replace of assets in region cache (will also try to upload but service will most likely refuse). avoid using unless trying to do some recovery --- OpenSim/Framework/Util.cs | 2 +- .../World/Archiver/ArchiveReadRequest.cs | 86 +++++++++++++------ 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 32de9b43af..a54c379bc6 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -3480,7 +3480,7 @@ namespace OpenSim.Framework finally { Interlocked.Decrement(ref numRunningThreadFuncs); - activeThreads.TryRemove(threadFuncNum, out ThreadInfo dummy); + activeThreads.TryRemove(threadFuncNum, out _); if (loggingEnabled && threadInfo.LogThread) m_log.Debug($"Exit threadfunc {threadFuncNum} ({FormatDuration(threadInfo.Elapsed())}"); callback = null; diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs index bdfbecc0b0..a46f4a900e 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs @@ -117,6 +117,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver /// Should we ignore any assets when reloading the archive? /// protected bool m_skipAssets; + /// + /// Should we replace assets in cache and even try to upload existent ones? + /// + protected bool m_ForceAssetsCache; /// /// Displacement added to each object as it is added to the world @@ -175,6 +179,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver private readonly IGroupsModule m_groupsModule; private readonly IAssetService m_assetService = null; + private readonly IAssetCache m_assetCache = null; private UUID m_defaultUser; @@ -213,6 +218,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_mergeParcels = options.ContainsKey("merge-parcels"); m_noObjects = options.ContainsKey("no-objects"); m_skipAssets = options.ContainsKey("skipAssets"); + m_ForceAssetsCache = options.ContainsKey("forceAssets"); + if(m_ForceAssetsCache) + m_skipAssets = false; m_requestId = requestId; m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero; m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f; @@ -261,6 +269,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_groupsModule = m_rootScene.RequestModuleInterface(); m_assetService = m_rootScene.AssetService; + m_assetCache = m_rootScene.RequestModuleInterface (); } public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary options) @@ -269,6 +278,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver m_loadPath = null; m_loadStream = loadStream; m_skipAssets = options.ContainsKey("skipAssets"); + m_ForceAssetsCache = options.ContainsKey("forceAssets"); + if(m_ForceAssetsCache) + m_skipAssets = false; m_merge = options.ContainsKey("merge"); m_mergeReplaceObjects = options.ContainsKey("mReplaceObjects"); m_requestId = requestId; @@ -330,40 +342,57 @@ namespace OpenSim.Region.CoreModules.World.Archiver failedAssetRestores++; } - bool[] exits = m_assetService.AssetsExist(ids.ToArray()); - ids.Clear(); - - if (exits is null) + if(m_ForceAssetsCache && m_assetCache != null) { - m_log.Error("[ARCHIVER]: asset service AssetsExists failed"); - failedAssetRestores += uuids.Count; - return; - } - - if (exits.Length != uuids.Count) - { - m_log.Error("[ARCHIVER]: asset service AssetsExists return size mismatch"); - failedAssetRestores += uuids.Count; - return; - } - - for (int i = 0; i < uuids.Count; ++i) - { - if (exits[i]) + for (int i = 0; i < uuids.Count; ++i) { - ++skipedAssetRestores; - } - else - { - if (TryUploadAsset(uuids[i],types[i], datas[i])) + if (TryUploadAsset(uuids[i],types[i], datas[i], m_assetCache)) successfulAssetRestores++; else failedAssetRestores++; + + int tot = successfulAssetRestores + failedAssetRestores + skipedAssetRestores; + if (tot % 250 == 0) + m_log.Debug("[ARCHIVER]: done " + tot + "; uploaded: " + successfulAssetRestores + " failed: "+ failedAssetRestores + " assets..."); + } + } + else + { + bool[] exits = m_assetService.AssetsExist(ids.ToArray()); + ids.Clear(); + + if (exits is null) + { + m_log.Error("[ARCHIVER]: asset service AssetsExists failed"); + failedAssetRestores += uuids.Count; + return; } - int tot = successfulAssetRestores + failedAssetRestores + skipedAssetRestores; - if (tot % 250 == 0) - m_log.Debug("[ARCHIVER]: done " + tot + "; uploaded: " + successfulAssetRestores + " skipped: " + skipedAssetRestores + " failed: "+ failedAssetRestores + " assets..."); + if (exits.Length != uuids.Count) + { + m_log.Error("[ARCHIVER]: asset service AssetsExists return size mismatch"); + failedAssetRestores += uuids.Count; + return; + } + + for (int i = 0; i < uuids.Count; ++i) + { + if (exits[i]) + { + ++skipedAssetRestores; + } + else + { + if (TryUploadAsset(uuids[i],types[i], datas[i])) + successfulAssetRestores++; + else + failedAssetRestores++; + } + + int tot = successfulAssetRestores + failedAssetRestores + skipedAssetRestores; + if (tot % 250 == 0) + m_log.Debug("[ARCHIVER]: done " + tot + "; uploaded: " + successfulAssetRestores + " failed: "+ failedAssetRestores + " assets..."); + } } } @@ -1028,7 +1057,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver } } - private bool TryUploadAsset(UUID assetID, sbyte assetType, byte[] data) + private bool TryUploadAsset(UUID assetID, sbyte assetType, byte[] data, IAssetCache forceCache = null) { if (assetType == (sbyte)AssetType.Unknown) { @@ -1054,6 +1083,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver }; m_assetService.Store(asset); + forceCache?.Cache(asset,true); return true; // not right }