mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 23:06:36 +08:00
refactor(storage): drop per-upload storage_driver, use storage_config as single source
Remove w_uploads.storage_driver and route all read/write/delete paths through storage.Active() backed by storage_config.driver. Block direct driver switches when uploads exist; require migration task instead. Simplify migration to cursor-based file_path iteration without per-row driver updates.
This commit is contained in:
@@ -155,26 +155,6 @@ func Active(ctx context.Context) (Driver, Backend, error) {
|
||||
return activeDriver, activeBackend, nil
|
||||
}
|
||||
|
||||
// ForDriver returns the active or pending backend for an upload record, reusing the active singleton if matched.
|
||||
func ForDriver(ctx context.Context, driver Driver) (Backend, error) {
|
||||
if driver == DriverS3 && mockBackend != nil {
|
||||
return mockBackend, nil
|
||||
}
|
||||
activeDrv, activeBnd, err := Active(ctx)
|
||||
if err == nil && activeDrv == driver {
|
||||
return activeBnd, nil
|
||||
}
|
||||
cfg, err := LoadConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
backend, err := NewBackend(ctx, cfg, driver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("storage configuration for driver %q is unavailable: %w", driver, err)
|
||||
}
|
||||
return backend, nil
|
||||
}
|
||||
|
||||
type functionBackend struct {
|
||||
put func(context.Context, string, io.Reader, int64, string) error
|
||||
get func(context.Context, string) (*Object, error)
|
||||
|
||||
@@ -70,16 +70,7 @@ func TestStorageCache(t *testing.T) {
|
||||
t.Errorf("Active returned driver %v, backend %v; expected %v, %v", drv, bnd, DriverLocal, mockBnd)
|
||||
}
|
||||
|
||||
// 5. Test ForDriver returns cached backend
|
||||
bnd2, err := ForDriver(ctx, DriverLocal)
|
||||
if err != nil {
|
||||
t.Fatalf("ForDriver failed: %v", err)
|
||||
}
|
||||
if bnd2 != mockBnd {
|
||||
t.Errorf("ForDriver returned backend %v, expected %v", bnd2, mockBnd)
|
||||
}
|
||||
|
||||
// 6. Test ResetCache again
|
||||
// 5. Test ResetCache again
|
||||
ResetCache()
|
||||
if activeConfigJSON != "" || activeDriver != "" || activeBackend != nil || !lastChecked.IsZero() {
|
||||
t.Fatal("ResetCache did not clear cache variables after setting them")
|
||||
|
||||
Reference in New Issue
Block a user