diff --git a/docs/API-CONFIG.md b/docs/API-CONFIG.md index fce1e7c0..69be214a 100644 --- a/docs/API-CONFIG.md +++ b/docs/API-CONFIG.md @@ -142,7 +142,7 @@ Mount logs each write at INFO with the client address, the action, its arguments ### Web Dashboard -Mount serves a web dashboard at `http:///ui/`, unless `-dashboard=false`. It shows status, capacity, the cache, journal, TRIM and lock counters, and the nodes in the registry. It lists snapshots, and for a file you name it creates, clones and deletes them and clones the file. Its Settings page runs the admin endpoints. +Mount serves a web dashboard at `http:///ui/`, unless `-dashboard=false`. It shows status, capacity, the cache, journal, TRIM and lock counters, and the nodes in the registry. It lists snapshots, and for a file you name it creates, clones and deletes them and clones the file. Orphaned snapshots, whose file is gone, get a list of their own where you can delete them. Its Settings page runs the admin endpoints. The dashboard's files are static and hold no data, so they need no token and skip the rate limit. The page calls `/api/v1/...` on the same origin with the same rules as any client: reads need the token when one is set, and snapshots always need it. Enter the token on the dashboard's Settings page. The browser keeps it in `sessionStorage`, so closing the tab forgets it. Responses carry a `Content-Security-Policy` that lets the page load and call only its own origin and stops other sites from framing it. diff --git a/internal/api/writes_test.go b/internal/api/writes_test.go index e8e13779..201ec502 100644 --- a/internal/api/writes_test.go +++ b/internal/api/writes_test.go @@ -310,6 +310,21 @@ func TestTokenInQueryIsIgnored(t *testing.T) { } } +// The dashboard deletes orphans, whose file is gone, by leaving out ?path=. +func TestDeleteWithoutPathReachesTheService(t *testing.T) { + srv, files, _ := startWriteServer(t, "secret") + if status, body := call(t, srv, "DELETE", "/api/v1/snapshots/s1", "secret", ""); status != http.StatusOK { + t.Fatalf("delete without a path: %d %s", status, body) + } + if got := files.lastCall(); got != "delete s1" { + t.Fatalf("service got %q, want an empty path", got) + } + files.err = fmt.Errorf("snapshot %q belongs to inode 12: %w", "s1", syscall.EBUSY) + if status, body := call(t, srv, "DELETE", "/api/v1/snapshots/s1", "secret", ""); status != http.StatusConflict { + t.Fatalf("delete of a snapshot whose file exists: %d %s, want 409", status, body) + } +} + func TestDeleteTakesEscapedNames(t *testing.T) { srv, files, _ := startWriteServer(t, "secret") if status, body := call(t, srv, "DELETE", "/api/v1/snapshots/nightly%2F2026%3A1?path=/f", "secret", ""); status != http.StatusOK { diff --git a/web/dashboard/src/api/client.ts b/web/dashboard/src/api/client.ts index 0d9875fe..30e2d283 100644 --- a/web/dashboard/src/api/client.ts +++ b/web/dashboard/src/api/client.ts @@ -179,8 +179,10 @@ export class ApiClient { } // Deletion finishes in the background: the snapshot lists as "deleting" until the worker frees it. - deleteSnapshot(name: string, path: string): Promise { - return this.send('DELETE', `/api/v1/snapshots/${encodeURIComponent(name)}?path=${encodeURIComponent(path)}`) + // Without a path it deletes only an orphan, and answers 409 if the snapshot's file still exists. + deleteSnapshot(name: string, path?: string): Promise { + const query = path ? `?path=${encodeURIComponent(path)}` : '' + return this.send('DELETE', `/api/v1/snapshots/${encodeURIComponent(name)}${query}`) } cloneSnapshot(name: string, request: CloneRequest): Promise { @@ -209,7 +211,7 @@ export const api = { getClusterStats: (options?: RequestOptions) => apiClient.getClusterStats(options), listSnapshots: (path?: string, options?: RequestOptions) => apiClient.listSnapshots(path, options), createSnapshot: (request: SnapshotRequest) => apiClient.createSnapshot(request), - deleteSnapshot: (name: string, path: string) => apiClient.deleteSnapshot(name, path), + deleteSnapshot: (name: string, path?: string) => apiClient.deleteSnapshot(name, path), cloneSnapshot: (name: string, request: CloneRequest) => apiClient.cloneSnapshot(name, request), cloneFile: (request: CloneRequest) => apiClient.cloneFile(request), admin: (operation: AdminOperation) => apiClient.admin(operation), diff --git a/web/dashboard/src/api/types.ts b/web/dashboard/src/api/types.ts index 3def9932..7ca2c668 100644 --- a/web/dashboard/src/api/types.ts +++ b/web/dashboard/src/api/types.ts @@ -199,6 +199,8 @@ export interface SnapshotInfo { size_bytes: number blocks: number created_at?: string + /** Its file is gone, or it predates the record of which file it belongs to; only the full list shows it */ + orphan?: boolean } // GET /api/v1/snapshots[?path=] diff --git a/web/dashboard/src/pages/SnapshotsPage.tsx b/web/dashboard/src/pages/SnapshotsPage.tsx index a1b87664..8a9df538 100644 --- a/web/dashboard/src/pages/SnapshotsPage.tsx +++ b/web/dashboard/src/pages/SnapshotsPage.tsx @@ -158,11 +158,66 @@ function FileForm({ path, onChange }: { path: string; onChange: (path: string) = ) } +function OrphanSnapshots({ orphans, onDelete }: { orphans: SnapshotInfo[]; onDelete: (snapshot: SnapshotInfo) => void }) { + return ( +
+
+

Orphaned snapshots ({orphans.length})

+

+ The file each of these was taken of is gone, or it was taken by an older version that did not record its file. + No file lists them and they can't be cloned, but they keep their blocks until you delete them. +

+
+
+ + + + + + + + + + + + + + {orphans.map((snapshot) => ( + + + + + + + + + + ))} + +
{snapshot.name} + + {formatBytes(snapshot.size_bytes)}{formatNumber(snapshot.blocks)} + {snapshot.created_at ? formatRelativeTime(new Date(snapshot.created_at)) : '-'} + {snapshot.inode} + +
+
+
+ ) +} + type Dialog = | { kind: 'create' } | { kind: 'clone-file' } | { kind: 'clone-snapshot'; snapshot: SnapshotInfo } | { kind: 'delete'; snapshot: SnapshotInfo } + | { kind: 'delete-orphan'; snapshot: SnapshotInfo } export function SnapshotsPage() { const refreshInterval = useRefreshInterval() @@ -185,7 +240,7 @@ export function SnapshotsPage() { } const rows = useMemo(() => { - const list = snapshots.data?.snapshots ?? [] + const list = (snapshots.data?.snapshots ?? []).filter((s) => !s.orphan) const query = search.toLowerCase() const filtered = query ? list.filter((s) => s.name.toLowerCase().includes(query)) : [...list] filtered.sort((a, b) => { @@ -211,6 +266,8 @@ export function SnapshotsPage() { const closeDialog = () => setDialog(null) const list = snapshots.data?.snapshots ?? [] + const owned = list.filter((s) => !s.orphan) + const orphans = list.filter((s) => s.orphan) const totalSize = list.reduce((sum, s) => sum + s.size_bytes, 0) return ( @@ -291,82 +348,90 @@ export function SnapshotsPage() { -
- setSearch(e.target.value)} - className="px-3 py-1.5 bg-gfs-bg-tertiary border border-gfs-border rounded text-sm text-gfs-text-primary placeholder-gfs-text-muted focus:outline-none focus:ring-2 focus:ring-gfs-accent-primary w-64" - /> - - - Showing {rows.length} of {list.length} - -
+ {owned.length > 0 && ( + <> +
+ setSearch(e.target.value)} + className="px-3 py-1.5 bg-gfs-bg-tertiary border border-gfs-border rounded text-sm text-gfs-text-primary placeholder-gfs-text-muted focus:outline-none focus:ring-2 focus:ring-gfs-accent-primary w-64" + /> + + + Showing {rows.length} of {owned.length} + +
-
-
- - - - - - - - - {path ? : } - - - - {rows.map((snapshot) => ( - - - - - - - {path ? ( - - ) : ( - +
+
+
{snapshot.name} - - {formatBytes(snapshot.size_bytes)}{formatNumber(snapshot.blocks)} - {snapshot.created_at ? formatRelativeTime(new Date(snapshot.created_at)) : '-'} - -
- - -
-
{snapshot.inode}
+ + + + + + + + {path ? : } + + + + {rows.map((snapshot) => ( + + + + + + + {path ? ( + + ) : ( + + )} + + ))} + {rows.length === 0 && ( + + + )} - - ))} - {rows.length === 0 && ( - - - - )} - -
{snapshot.name} + + {formatBytes(snapshot.size_bytes)}{formatNumber(snapshot.blocks)} + {snapshot.created_at ? formatRelativeTime(new Date(snapshot.created_at)) : '-'} + +
+ + +
+
{snapshot.inode}
+ No snapshots match the filter +
- No snapshots match the filter -
-
-
+ + + + + + )} + + {orphans.length > 0 && ( + setDialog({ kind: 'delete-orphan', snapshot })} /> + )} )} @@ -440,6 +505,31 @@ export function SnapshotsPage() { /> )} + {dialog?.kind === 'delete-orphan' && ( + { + try { + await api.deleteSnapshot(dialog.snapshot.name) + } catch (err) { + if (err instanceof ApiError && err.status === 409) { + throw new Error('Its file still exists, so it is not an orphan. Delete it from that file\'s snapshots.') + } + throw err + } + snapshots.refetch() + }} + title="Delete orphaned snapshot" + itemName={dialog.snapshot.name} + itemType="snapshot" + warning="The snapshot and the blocks only it holds are freed. Its file is gone, so nothing else can reach them. This cannot be undone." + successMessage="Delete started. The snapshot shows as deleting until its blocks are freed." + requireTypeToConfirm + /> + )} + {dialog?.kind === 'delete' && (