Move a migrated project's wiki with its history (P34)
Summary
A migrated project X reads <wiki>/X/ in place. Its pages' attachments (<wiki>/.attachments/X/), revisions (<data_dir>/wiki/), and page metadata (the default wiki's metadata file) sit outside that directory, keyed by X/<page>. Once <projects_dir>/X/wiki/ exists, X reads them from its own wiki and state directories, so moving the pages alone dropped every page's history from view.
Changes
- The first time the server opens
X's own wiki, it moves the attachments, revisions, and page metadata of every page under<wiki>/X/intoX's wiki.- Which folder is
X's: where the file system tells case apart (Linux), only the folder spelled exactly asX's workspace name, as v2's wiki visibility matched it. Where it ignores case (macOS, Windows), names that differ only in case are one folder, so the match ignores case. The exception is another migrated project whose workspace name differs only in case (opsandOps): then each project uses its exact spelling. - The in-place wiki, the move, and the warning share this rule. It never depends on which folders are on disk, since the admin's move changes them.
- In-place wiki on Linux, before: a lone
team/folder served workspaceTeam. After:Team's in-place wiki is<wiki>/Team/only, and empty until that folder exists. - Before: after
mv <wiki>/X <projects_dir>/X/wiki, every page showed no revisions, no attachments, and a new creation time. - After: the same
mvis the only step. Each page keeps its revisions, attachments, and creation time.
- Which folder is
- Pages left in
<wiki>/X/after the switch show in no wiki. When the server first opensX's wiki after each start, it logs a warning with the directory and the page count. - Spec 102 §Wiki of Migrated Projects states the move, its conflict rules, retries, and the leftover warning.
Core change
ownStore moves the history before it caches X's own store. It runs under a lock for that project only, so other projects' wikis don't wait. If the move fails, the request fails, and the next open retries. filewiki.Store.MoveHistory(ctx, inRoot, dst) holds both stores' mutation locks:
- Revisions: revisions already in the destination stay. The newest moved ones fill the room left under the 20-revision limit. The move copies those blobs, saves the destination manifest, removes the source blobs, then saves the source manifest. A kill at any point leaves no unrecorded revision file on either side.
- Page metadata: an entry the destination already has wins.
- Attachments: moved file by file.
- Each file is renamed. If the rename fails as cross-device (
EXDEV, orERROR_NOT_SAME_DEVICEon Windows), it is copied through a synced temporary file installed withfileutil.ReplaceFileDurableinstead. - If the destination has a file of the same name with the same content, the source copy is removed.
- With other content, both stay, and a warning names the kept file.
- Each file is renamed. If the rename fails as cross-device (
internal/service/frontend/file/wiki.go, ownStore, inPlaceDirs, and inAnyCase. foldCase is probed once, with fileutil.IsCaseInsensitiveFS(cfg.Paths.WikiDir):
if p.MigratedFrom != "" {
inRoot := w.inPlaceDirs(p.MigratedFrom)
if err := w.shared.MoveHistory(ctx, inRoot, store); err != nil {
return nil, fmt.Errorf("move the wiki history of project %q: %w", p.Name, err)
}
w.warnLeftPages(ctx, p, inRoot)
}
func (w *projectWikis) inPlaceDirs(name string) func(dir string) bool {
if inAnyCase(name, slices.Collect(maps.Keys(w.onDisk)), w.foldCase) {
return func(dir string) bool { return strings.EqualFold(dir, name) }
}
return func(dir string) bool { return dir == name }
}
func inAnyCase(name string, names []string, foldCase bool) bool {
return foldCase && !slices.ContainsFunc(names, func(other string) bool {
return other != name && strings.EqualFold(other, name)
})
}
// migratedRoots: the in-place view's folder follows the same rule.
onDisk[name] = name
if inAnyCase(name, names, w.foldCase) {
onDisk[name] = diskSpelling(name, dirs)
}
Testing
TestMovedWikiKeepsHistory: edits a page and attaches a file in place, renames<wiki>/opsto<projects_dir>/ops/wiki, then checks that the revision and the attachment read back from the project's wiki.TestMovedWikiKeepsHistoryInAnyCase(only where the file system ignores case):Team's folder is spelledteam. It is moved away before the first open, and the open reads the directory anew. The revision still moves. It failed at 2357aa9a9.TestWikiPagesLeftBehindAreLogged: checks that a page left behind shows in neither wiki and that the warning names the directory and count.TestMigratedProjectWikiRootMatchesCase(only where the file system tells case apart): ateam/folder is notTeam's in-place wiki.TestMigratedProjectWikiFindsRootInAnyCasenow runs only where the file system ignores case.TestProjectOfOtherCaseWithoutFolderStartsEmpty:Opswith no folder besideopslists nothing and writes to<wiki>/Ops/. It failed at e37a7c1b8.TestMovedWikiLeavesOtherCase(only where the file system tells case apart): besideops/sits either projectOps2'sOps/or a v2 default-wiki folderOPS/. It movesops, then reads the directory anew.ops's revision moves, the other folder's revision and attachment stay, and no leftover warning names it.TestMoveHistory*ininternal/persis/file/wiki:- revisions, creation time, and attachments;
- case-insensitive matching, and leaving another case's folder alone;
- the copy fallback on a cross-device rename error;
- a conflicting attachment kept with a warning;
- finishing an interrupted move;
- filling only the room left under the 20-revision cap.
- Ran
go test -raceon both packages on macOS, and withTMPDIRon a case-sensitive APFS volume.golangci-lintpasses on them with plain andGOOS=windowsbuilds.
Performance
No steady-state cost. The move runs once per server process per migrated project: on the first open of that project's own wiki, never on later requests or ticks. It reads one manifest and one metadata file and walks only <wiki>/.attachments/X/ and <wiki>/X/. Its cost grows with that project's history: at most 20 revision blobs per page, plus its attachments. While it runs, only that project's wiki requests and default-wiki writes wait. Other projects and default-wiki reads go on. It adds no bytes per run, no index, and no migration.
Compatibility
Lands dark: the code path runs only with experimental_projects on, so v2 files, API, and CLI are unchanged. A v2 binary never reads <projects_dir>/X/wiki/, so a downgrade after the move does not show the moved history in <wiki>/X/. This is the same as for the pages the admin moved.
Review guide
- Mechanical: the tests, the spec text, and
crossdevice_*.go(one constant each). - Needs judgment:
history.go: the order of manifest saves and blob removals, which makes a killed move resumable.inAnyCaseinwiki.go: the case rule shared by the in-place wiki, the move, and the warning.- Lock order in
ownStore: the project'sopeninglock, thenw.mubriefly, thenshared.mutationMu, then the new store'smutationMu.- Default-wiki writes take only
shared.mutationMu. w.muis never held while a store lock is taken.- So no path takes these locks in the reverse order.
- Default-wiki writes take only
New steps are marked with *.
flowchart TD
A[storeOf X] --> B{"<projects_dir>/X/wiki exists?"}
B -- no --> C["in-place view of <wiki>/X/"]
B -- yes --> D["ownStore: lock opening[X] *"]
D --> E{cached?}
E -- yes --> F[return store]
E -- no --> G[open X's own store]
G --> H["MoveHistory: shared.mutationMu, then own mutationMu *"]
H -- error --> I["fail the request, cache nothing; next open retries *"]
H -- ok --> J["warn about pages left in <wiki>/X/ *"]
J --> K["cache store under w.mu"]
Out of scope
- P15: delete runs no history move. If a project is deleted before its own wiki is ever opened, its v2 history stays under
X/in the default wiki. That history would then reappear for a new default-wiki page atX/<page>. P15 should open the project's wiki store before deleting. - P16: wires
storeOfinto the API, which is what triggers the move in a running server. - P22 and P24: may list leftover pages in the report or on the projects page.
- The default project's wiki still leaves out every case variant of
<wiki>/X/, as it did before this change. On Linux, a v2 default-wiki folder such asOPS/besideops/, orteam/for workspaceTeam, shows in no wiki, and the warning does not name it. Showing such folders in the default wiki again changes its exclusion rule, so it is left for a follow-up.
Agent
Claude Code, claude-opus-5-5, high