test(net10): add Flotsam cache format regression and migration guidance

This commit is contained in:
OpenGenesis (MPL 2.0) committed 2026-11-04 17:52:46 +01:00
1 parent 9c1f2fa465
commit 2c316582a6
3 files changed
+142

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
# Flotsam Asset Cache: .NET 10 format migration
The Generation 1 Flotsam simulator-side **file cache** previously used `BinaryFormatter` to persist `AssetBase`. `BinaryFormatter` cannot be used on .NET 10. This made old cache entries unreadable and attempted writes fail.
The fix implements a bounded, versioned `FLC1` disk-cache format with a SHA-256 payload checksum, preserving asset metadata and binary payload without reconstructing arbitrary object graphs. It intentionally **does not read the old BinaryFormatter format**. On encountering an obsolete entry, the simulator removes **that cache file only** and re-fetches it through the configured authoritative asset service (for example ROBUST FSAssets).
This is **not** a database or asset-store migration. Do **not** delete the central FSAssets directory, asset SQL tables, inventory, OAR/IAR files, or arbitrary `bin/` files.
## Immediate workaround while binaries are not yet deployed
In the active simulator's `[AssetCache]` configuration (typically `bin/config-include/FlotsamCache.ini`), set `FileCacheEnabled = false` and restart the simulator normally. This disables only Flotsam's file cache. It may increase ROBUST asset-service load. Re-enable after deploying the corrected binary.
## Cache path and cleanup
The checked-in setting `CacheDirectory = ./opt/cache/assetcache` is intentionally relative to the simulator's process working directory, hence `/opt/robust/bin/opt/cache/assetcache` when launched from `/opt/robust/bin`. To use an external absolute path instead, change the active setting to `CacheDirectory = /opt/cache/assetcache` **only after** checking directory permissions and that no other service uses that path. The format fix does **not** automatically move files or change operator-owned settings.
Existing stale cache files will be discarded on access. A controlled offline cache reset may accelerate reclamation, but only after the active cache directory is confirmed and it is verified to be exclusively a disposable simulator-side Flotsam cache.
## Regression
```bash
dotnet run --configuration Release --project tools/ci/FlotsamCacheNet10Regression/FlotsamCacheNet10Regression.csproj
```
This checks metadata and binary payload fidelity, rejected legacy entries, cache file disposal, wrong-ID rejection, tampering and truncation. It does not require MariaDB and never connects to a live grid.
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../../OpenSim/Framework/OpenSim.Framework.csproj" />
<ProjectReference Include="../../../OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,105 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using OpenSim.Framework;
using OpenSim.Region.CoreModules.Asset;
internal static class Program
{
private static int Main()
{
string root = Path.Combine(Path.GetTempPath(), "ogl-flotsam-net10-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
try
{
Type format = typeof(FlotsamAssetCache).Assembly.GetType(
"OpenSim.Region.CoreModules.Asset.FlotsamAssetCacheBinaryFormat", throwOnError: true)!;
MethodInfo write = format.GetMethod("Write", BindingFlags.Static | BindingFlags.NonPublic)!;
MethodInfo read = format.GetMethod("Read", BindingFlags.Static | BindingFlags.NonPublic)!;
if (write is null || read is null)
throw new Exception("Missing versioned Flotsam codec");
const string id = "fee03dc5-1f4d-46cc-8456-e19b85699c69";
AssetBase original = new(id, "Net10 cache fixture", 7, "creator-test");
original.Description = "Structured cache metadata roundtrip";
original.Metadata.CreationDate = new DateTime(2026, 11, 4, 12, 30, 0, DateTimeKind.Utc);
original.Metadata.ContentType = "application/vnd.ll.notecard";
original.Type = 7;
original.Metadata.SHA1 = Enumerable.Range(0, 20).Select(i => (byte)i).ToArray();
original.Local = true;
original.Temporary = true;
original.Flags = AssetFlags.Collectable;
original.UploadAttempts = 3;
original.Data = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray();
using MemoryStream encoded = new();
write.Invoke(null, new object[] { encoded, original });
if (encoded.Length <= original.Data.Length)
throw new Exception("Invalid cache encoding");
encoded.Position = 0;
AssetBase restored = (AssetBase)read.Invoke(null, new object[] { encoded, id })!;
Check(restored.ID == original.ID, "ID mismatch");
Check(restored.Name == original.Name, "Name mismatch");
Check(restored.Description == original.Description, "Description mismatch");
Check(restored.CreatorID == original.CreatorID, "Creator mismatch");
Check(restored.Type == original.Type, "Asset Type mismatch");
Check(restored.Metadata.ContentType == original.Metadata.ContentType, "Content type mismatch");
Check(restored.Flags == original.Flags, "Flags mismatch");
Check(restored.Local && restored.Temporary, "Local/Temporary lost");
Check(restored.UploadAttempts == original.UploadAttempts, "UploadAttempts mismatch");
Check(restored.Metadata.CreationDate == original.Metadata.CreationDate, "Creation time mismatch");
Check(restored.Metadata.SHA1!.SequenceEqual(original.Metadata.SHA1!), "SHA1 mismatch");
Check(restored.Data.SequenceEqual(original.Data), "Payload mismatch");
byte[] payload = encoded.ToArray();
byte[] tampered = (byte[])payload.Clone();
tampered[^33] ^= 0x11;
MustReject(read, tampered, id, "corrupt payload hash");
MustReject(read, payload.Take(payload.Length - 6).ToArray(), id, "truncated file");
MustReject(read, payload, "11111111-2222-3333-4444-555555555555", "wrong asset ID");
MustReject(read, new byte[] { 0, 1, 0, 0, 0, 0, 0, 0 }, id, "legacy format");
var cache = new FlotsamAssetCache();
typeof(FlotsamAssetCache).GetField("m_CacheDirectory", BindingFlags.Instance | BindingFlags.NonPublic)!
.SetValue(cache, root);
var filename = typeof(FlotsamAssetCache).GetMethod("GetFileName", BindingFlags.Instance | BindingFlags.NonPublic)!;
var getFile = typeof(FlotsamAssetCache).GetMethod("GetFromFileCache", BindingFlags.Instance | BindingFlags.NonPublic)!;
string path = (string)filename.Invoke(cache, new object[] { id })!;
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
File.WriteAllBytes(path, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 });
Check(getFile.Invoke(cache, new object[] { id }) is null, "Legacy cache returned an asset");
Check(!File.Exists(path), "Legacy cache entry was not discarded");
File.WriteAllBytes(path, payload);
var fromFile = (AssetBase)getFile.Invoke(cache, new object[] { id })!;
Check(fromFile is not null && fromFile.Data.SequenceEqual(original.Data), "File cache could not read new versioned format");
Console.WriteLine("PASS: Flotsam .NET10 binary cache roundtrip, integrity, bounded legacy rejection and refetch");
return 0;
}
finally
{
Directory.Delete(root, recursive: true);
}
}
private static void Check(bool ok, string error)
{
if (!ok)
throw new InvalidOperationException(error);
}
private static void MustReject(MethodInfo read, byte[] contents, string id, string label)
{
using MemoryStream stream = new(contents);
try
{
read.Invoke(null, new object[] { stream, id });
throw new InvalidOperationException("Invalid cache accepted: " + label);
}
catch (TargetInvocationException ex) when (ex.InnerException is InvalidDataException ||
ex.InnerException is EndOfStreamException)
{
}
}
}