fix(workspace): leave orphaned workspaces recoverable

Stop New() from eagerly discarding orphaned workspace files so callers can recover them explicitly through RecoverOrphans().

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 08:23:31 +00:00
parent 41eaa7c96c
commit 5af3f90e2d
3 changed files with 7 additions and 13 deletions

View file

@ -156,7 +156,6 @@ func newStoreFromConfig(operation string, config StoreConfig) (*Store, error) {
}
storeInstance.startBackgroundPurge()
storeInstance.cleanUpOrphanedWorkspaces(defaultWorkspaceStateDirectory)
return storeInstance, nil
}

View file

@ -159,17 +159,6 @@ func discoverOrphanWorkspacePaths(stateDirectory string) []string {
return orphanPaths
}
func (storeInstance *Store) cleanUpOrphanedWorkspaces(stateDirectory string) {
if storeInstance == nil {
return
}
for _, orphanWorkspace := range storeInstance.RecoverOrphans(stateDirectory) {
_ = orphanWorkspace.Aggregate()
orphanWorkspace.Discard()
}
}
func workspaceNameFromPath(stateDirectory, databasePath string) string {
relativePath := core.TrimPrefix(databasePath, joinPath(stateDirectory, ""))
return core.TrimSuffix(relativePath, ".duckdb")

View file

@ -184,7 +184,7 @@ func TestWorkspace_RecoverOrphans_Good(t *testing.T) {
assert.False(t, testFilesystem().Exists(workspaceFilePath(stateDirectory, "orphan-session")))
}
func TestWorkspace_New_Good_CleansUpOrphanedWorkspaces(t *testing.T) {
func TestWorkspace_New_Good_LeavesOrphanedWorkspacesForRecovery(t *testing.T) {
stateDirectory := useWorkspaceStateDirectory(t)
requireCoreOK(t, testFilesystem().EnsureDir(stateDirectory))
@ -198,6 +198,12 @@ func TestWorkspace_New_Good_CleansUpOrphanedWorkspaces(t *testing.T) {
require.NoError(t, err)
defer storeInstance.Close()
assert.True(t, testFilesystem().Exists(orphanDatabasePath))
orphans := storeInstance.RecoverOrphans(stateDirectory)
require.Len(t, orphans, 1)
assert.Equal(t, "orphan-session", orphans[0].Name())
orphans[0].Discard()
assert.False(t, testFilesystem().Exists(orphanDatabasePath))
assert.False(t, testFilesystem().Exists(orphanDatabasePath+"-wal"))
assert.False(t, testFilesystem().Exists(orphanDatabasePath+"-shm"))