Files
seaweedfs/weed/server/filer_grpc_server_rename_sqlite_test.go
T
040ff9049c filer: roll back a stream rename refused for a non-empty target (#12886)
* filer: roll back a stream rename refused for a non-empty target

StreamRenameEntry refuses to move a directory onto a non-empty one, but
returned without ending the transaction it had begun. On a SQL store
(MySQL, Postgres and the stores built on them) that transaction keeps its
pooled connection: it was begun under context.Background(), so database/sql
never rolls it back by itself. Every such refusal holds one more connection
for the life of the filer, and once connection_max_open (50 in the scaffold)
are held, store calls wait for a connection that never comes back.

Roll the transaction back before returning, as the function's other
refusals already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: check a stream rename's target directory inside its transaction

The not-empty check listed the target under context.Background(), outside
the transaction the rename had already begun. The SQLite store's main pool
has a single connection, which the transaction holds, so every directory
rename onto an existing directory waited for that connection forever and
the filer's store stopped answering. On a bounded SQL pool, concurrent
renames that each hold a transaction can wedge the same way.

List through the transaction's context, as the child move already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-11-22 10:18:25 -08:00

51 lines
1.3 KiB
Go

//go:build (linux || darwin || windows) && sqlite
package weed_server
import (
"context"
"path/filepath"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/filer/sqlite"
)
// The SQLite store has one connection and the rename's transaction holds it,
// so a check that reads outside the transaction waits for it forever.
func TestStreamRenameOntoDirectoryOnSqlite(t *testing.T) {
store := &sqlite.SqliteStore{}
if err := store.Initialize(testConfig{"dbFile": filepath.Join(t.TempDir(), "filer.db")}, ""); err != nil {
t.Fatal(err)
}
defer store.Shutdown()
ctx := context.Background()
for _, entry := range []*filer.Entry{
newDirectoryEntry("/a", 101),
newFileEntry("/a/y.txt", 102),
newDirectoryEntry("/e", 103),
} {
if err := store.InsertEntry(ctx, entry); err != nil {
t.Fatal(err)
}
}
done := make(chan error, 1)
go func() {
_, err := streamRename(t, store, "a", "e")
done <- err
}()
select {
case err := <-done:
if err != nil {
t.Fatalf("StreamRenameEntry: %v", err)
}
case <-time.After(10 * time.Second):
t.Fatalf("StreamRenameEntry onto an existing directory never returned: %+v", store.DB.Stats())
}
if _, err := store.FindEntry(ctx, "/e/y.txt"); err != nil {
t.Fatalf("moved child: %v", err)
}
}