feat(server): allow mirrors on any storage category — lift the backups-only rule

This commit is contained in:
jubnl
2026-08-20 18:50:38 +02:00
parent c4b1e18eaf
commit 32a12068c6
3 changed files with 23 additions and 13 deletions
@@ -26,8 +26,10 @@ export interface ReplicaFailure {
/**
* Composite backend: one primary (source of truth) plus best-effort replicas.
* Runs entirely over the driver interface — the second in-tree consumer of
* the contract suite. Only the `backups` category may be assigned a mirror
* (registry validation enforces it).
* the contract suite. Any category may be assigned a mirror (the v1
* backups-only rule was lifted by the replicas-on-primary spec); replica
* writes are synchronous in the request path, which is why hot categories
* carry an advisory in the admin UI rather than a prohibition here.
*
* Writes hit the primary first and must succeed; replica failures are
* reported through `onReplicaFailure` (surfaced as health status), never
@@ -459,8 +459,5 @@ function validateConfig(backends: Map<string, BackendConfig>, categories: Map<St
if (!backend) {
throw new StorageBackendError(`category '${category}' maps to unknown backend '${backendName}'`);
}
if (backend.type === 'mirror' && category !== 'backups') {
throw new StorageBackendError(`category '${category}' may not use a mirror backend (backups only)`);
}
}
}
@@ -215,16 +215,27 @@ describe('StorageRegistryService settings', () => {
expect(registry.resolve('files').backendName).toBe('uploads-local');
});
it('a mirror may serve any category — the backups-only rule is lifted (replicas-on-primary spec)', () => {
const extraRoot = makeTmpDir();
const { registry, uploadsRoot } = makeRegistry({
backends: [
{ name: 'extra-local', type: 'local', options: { root: extraRoot } },
{ name: 'm', type: 'mirror', options: { primary: 'uploads-local', replicas: ['extra-local'] } },
],
categories: { covers: 'm' },
});
const covers = registry.resolve('covers');
expect(covers.backendName).toBe('m');
expect(covers.driver).toBeInstanceOf(MirrorDriver);
expect(covers.keyPrefix).toBe('covers/');
// Hot-path reads stay free: getLocalPath delegates to the local primary.
expect(covers.driver.getLocalPath!('covers/x.jpg')).toBe(
path.join(fs.realpathSync(uploadsRoot), 'covers/x.jpg'),
);
});
it.each([
['unknown backend name in categories', undefined, JSON.stringify({ files: 'nope' })],
[
'mirror assigned to a non-backups category',
JSON.stringify([
{ name: 'extra-local', type: 'local', options: { root: '/tmp/x' } },
{ name: 'm', type: 'mirror', options: { primary: 'uploads-local', replicas: ['extra-local'] } },
]),
JSON.stringify({ files: 'm' }),
],
[
'nested mirror',
JSON.stringify([