The desktop keyed every server by the address it was reached at, so one
NAS reached by name and by IP, or after an address change, looked like two
servers, and all servers shared one workspace and one cache. Each server
now announces a stable id, and the desktop's folders are sorted into one
home per server, so that every server can have its own archive of
downloaded originals (or5 answers Q1).
- The server makes a Guid v7 once, keeps it as the app setting server.id
(so it survives restarts and restores, on SQLite and Postgres) and
announces it as ServerInfo.ServerId. Older clients ignore the field, and
older servers read as null.
- ServerIdentity keys a server as id:<N> when it announces an id, and by
its address otherwise. Address keys are kept as aliases.
- HomeFolders names the homes: local, servers/<id> or
servers/addr-<hash16>. The hash equals the 1.0 proxy cache folder name.
It also names the per-server originals archive root.
- WorkspaceHomes splits the workspace into one format-1 store per home
under a format-2 parent manifest, which 1.0 refuses. A 1.0 workspace
stays one store until it is sorted.
- HomeLayoutMigration plans as a dry run and applies through a journal:
- only same-folder renames, each checked by inventory;
- a clash keeps the copy saved last and sends the other to the trash;
- it resumes after a crash at any step;
- it skips leased projects;
- it defers an offline workspace or one being moved, while the cache
part still runs.
- RekeyAsync moves an alias home to the id home: whole folders, or
project-by-project merges. It also rewrites working states under their
lease, and moves sync_links (the newer row wins a clash).
- ProxyCache, the job root resolver, WorkspaceMover and WorkspaceCleaner
understand the split layout. The new layout is opt-in through
SyncOptions.ServersDirectory, so the app sees no change until it is
wired.
Refs #66
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.8 KiB
C#
59 lines
2.8 KiB
C#
using Chronos.Core.IO;
|
|
using Chronos.Data.Sync;
|
|
using Chronos.Data.Tests.Homes;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Sync;
|
|
|
|
/// <summary>Where the proxies of a server's sequence live (owner review 5, #66): its home in the cache, else where an earlier layout left them.</summary>
|
|
[Category("sync")]
|
|
public sealed class ProxyCacheTests(TestContext context)
|
|
{
|
|
private static readonly Guid Id = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
|
|
|
|
[Test]
|
|
public void WithoutAServersRootTheLayoutIs10s()
|
|
{
|
|
var root = context.CreateTempDirectory("proxies");
|
|
var remote = Guid.CreateVersion7();
|
|
var cache = new ProxyCache(root);
|
|
Assert.Equal(Path.Combine(root, HomeFolders.AddressHash(HomeFixtures.Nas), remote.ToString("N")), cache.Folder(HomeFixtures.Nas, remote));
|
|
}
|
|
|
|
[Test]
|
|
public void ANewSequenceGoesToItsServersHomeAndAnOldOneIsReadWhereItIs()
|
|
{
|
|
var cacheRoot = context.CreateTempDirectory("cache");
|
|
var (legacyRoot, servers) = (Path.Combine(cacheRoot, "proxies"), Path.Combine(cacheRoot, "servers"));
|
|
var identity = new ServerIdentity([new KnownServerKey(Id, [HomeFixtures.Nas])]);
|
|
var cache = new ProxyCache(legacyRoot, servers, () => identity);
|
|
var idKey = ServerIdentity.IdKey(Id);
|
|
|
|
var fresh = Guid.CreateVersion7();
|
|
Assert.Equal(Path.Combine(servers, Id.ToString("N"), "proxies", fresh.ToString("N")), cache.Folder(idKey, fresh));
|
|
Assert.Equal(cache.Folder(idKey, fresh), cache.Folder(HomeFixtures.Nas, fresh), "an alias names the same home");
|
|
|
|
// A sequence cached by 1.0 under the address is used where it is until it is moved.
|
|
var old = Guid.CreateVersion7();
|
|
var legacy = HomeFixtures.LegacyProxies(cacheRoot, HomeFixtures.Nas, old);
|
|
Assert.Equal(legacy, cache.Folder(idKey, old));
|
|
Assert.True(cache.Exists(idKey, old));
|
|
|
|
// In the home of the address (sorted before the server announced its id): used there too.
|
|
var sorted = Guid.CreateVersion7();
|
|
var byAddress = Path.Combine(servers, HomeFolders.ServerFolder(HomeFixtures.Nas), "proxies", sorted.ToString("N"));
|
|
Directory.CreateDirectory(byAddress);
|
|
Assert.Equal(byAddress, cache.Folder(idKey, sorted));
|
|
|
|
// Once in its home, that is where it is.
|
|
var home = Path.Combine(servers, Id.ToString("N"), "proxies", old.ToString("N"));
|
|
Directory.CreateDirectory(Path.GetDirectoryName(home)!);
|
|
Directory.Move(legacy, home);
|
|
Assert.Equal(home, cache.Folder(HomeFixtures.Nas, old));
|
|
|
|
// A server known by its address only has an address home.
|
|
var other = Guid.CreateVersion7();
|
|
Assert.Equal(Path.Combine(servers, HomeFolders.ServerFolder(HomeFixtures.Other), "proxies", other.ToString("N")), cache.Folder(HomeFixtures.Other, other));
|
|
}
|
|
}
|