Browse Source
feat: auto-disable master vacuum when plugin worker is active (#8624)
feat: auto-disable master vacuum when plugin worker is active (#8624)
* feat: auto-disable master vacuum when plugin vacuum worker is active When a vacuum-capable plugin worker connects to the admin server, the admin server calls DisableVacuum on the master to prevent the automatic scheduled vacuum from conflicting with the plugin worker's vacuum. When the worker disconnects, EnableVacuum is called to restore the default behavior. A safety net in the topology refresh loop re-enables vacuum if the admin server disconnects without cleanup. * rename isAdminServerConnected to isAdminServerConnectedFunc * add 5s timeout to DisableVacuum/EnableVacuum gRPC calls Prevents the monitor goroutine from blocking indefinitely if the master is unresponsive. * track plugin ownership of vacuum disable to avoid overriding operator - Add vacuumDisabledByPlugin flag to Topology, set when DisableVacuum is called while admin server is connected (i.e., by plugin monitor) - Safety net only re-enables vacuum when it was disabled by plugin, not when an operator intentionally disabled it via shell command - EnableVacuum clears the plugin flag * extract syncVacuumState for testability, add fake toggler tests Extract the single sync step into syncVacuumState() with a vacuumToggler interface. Add TestSyncVacuumState with a fake toggler that verifies disable/enable calls on state transitions. * use atomic.Bool for isDisableVacuum and vacuumDisabledByPlugin Both fields are written by gRPC handlers and read by the vacuum goroutine, causing a data race. Use atomic.Bool with Store/Load for thread-safe access. * use explicit by_plugin field instead of connection heuristic Add by_plugin bool to DisableVacuumRequest proto so the caller declares intent explicitly. The admin server monitor sets it to true; shell commands leave it false. This prevents an operator's intentional disable from being auto-reversed by the safety net. * use setter for admin server callback instead of function parameter Move isAdminServerConnected from StartRefreshWritableVolumes parameter to Topology.SetAdminServerConnectedFunc() setter. Keeps the function signature stable and decouples the topology layer from the admin server concept. * suppress repeated log messages on persistent sync failures Add retrying parameter to syncVacuumState so the initial state transition is logged at V(0) but subsequent retries of the same transition are silent until the call succeeds. * clear plugin ownership flag on manual DisableVacuum Prevents stale plugin flag from causing incorrect auto-enable when an operator manually disables vacuum after a plugin had previously disabled it. * add by_plugin to EnableVacuumRequest for symmetric ownership tracking Plugin-driven EnableVacuum now only re-enables if the plugin was the one that disabled it. If an operator manually disabled vacuum after the plugin, the plugin's EnableVacuum is a no-op. This prevents the plugin monitor from overriding operator intent on worker disconnect. * use cancellable context for monitorVacuumWorker goroutine Replace context.Background() with a cancellable context stored as bgCancel on AdminServer. Shutdown() calls bgCancel() so monitorVacuumWorker exits cleanly via ctx.Done(). * track operator and plugin vacuum disables independently Replace single isDisableVacuum flag with two independent flags: vacuumDisabledByOperator and vacuumDisabledByPlugin. Each caller only flips its own flag. The effective disabled state is the OR of both. This prevents a plugin connect/disconnect cycle from overriding an operator's manual disable, and vice versa. * fix safety net to clear plugin flag, not operator flag The safety net should call EnableVacuumByPlugin() to clear only the plugin disable flag when the admin server disconnects. The previous call to EnableVacuum() incorrectly cleared the operator flag instead.pull/8632/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 435 additions and 32 deletions
-
95weed/admin/dash/admin_server.go
-
116weed/admin/dash/vacuum_monitor_test.go
-
15weed/admin/plugin/plugin.go
-
22weed/admin/plugin/registry.go
-
82weed/admin/plugin/registry_test.go
-
2weed/pb/master.proto
-
47weed/pb/master_pb/master.pb.go
-
17weed/server/master_grpc_server_volume.go
-
5weed/server/master_server.go
-
48weed/topology/topology.go
-
10weed/topology/topology_event_handling.go
-
8weed/topology/topology_vacuum.go
@ -0,0 +1,116 @@ |
|||
package dash |
|||
|
|||
import ( |
|||
"testing" |
|||
"time" |
|||
|
|||
"github.com/seaweedfs/seaweedfs/weed/pb/plugin_pb" |
|||
|
|||
adminplugin "github.com/seaweedfs/seaweedfs/weed/admin/plugin" |
|||
) |
|||
|
|||
// TestVacuumMonitorStateTransitions verifies the state transition logic that
|
|||
// drives the vacuum monitor goroutine: the plugin registry correctly reports
|
|||
// whether a vacuum-capable worker is present or absent.
|
|||
func TestVacuumMonitorStateTransitions(t *testing.T) { |
|||
t.Parallel() |
|||
|
|||
opts := adminplugin.Options{ |
|||
DataDir: "", |
|||
} |
|||
p, err := adminplugin.New(opts) |
|||
if err != nil { |
|||
t.Fatalf("failed to create plugin: %v", err) |
|||
} |
|||
defer p.Shutdown() |
|||
|
|||
// Initially no workers => no capable worker.
|
|||
if p.HasCapableWorker("vacuum") { |
|||
t.Fatalf("expected no capable worker initially") |
|||
} |
|||
|
|||
// Simulate state transition false -> true: worker connects.
|
|||
p.WorkerConnectForTest(&plugin_pb.WorkerHello{ |
|||
WorkerId: "vacuum-worker-1", |
|||
Capabilities: []*plugin_pb.JobTypeCapability{ |
|||
{JobType: "vacuum", CanDetect: true, CanExecute: true}, |
|||
}, |
|||
}) |
|||
|
|||
if !p.HasCapableWorker("vacuum") { |
|||
t.Fatalf("expected capable worker after connect") |
|||
} |
|||
|
|||
// Simulate state transition true -> false: worker disconnects.
|
|||
p.WorkerDisconnectForTest("vacuum-worker-1") |
|||
|
|||
// Give registry removal a moment (it's synchronous, but be safe).
|
|||
time.Sleep(10 * time.Millisecond) |
|||
|
|||
if p.HasCapableWorker("vacuum") { |
|||
t.Fatalf("expected no capable worker after disconnect") |
|||
} |
|||
} |
|||
|
|||
// fakeToggler records disable/enable calls for testing.
|
|||
type fakeToggler struct { |
|||
disableCalls int |
|||
enableCalls int |
|||
} |
|||
|
|||
func (f *fakeToggler) disableVacuum() error { |
|||
f.disableCalls++ |
|||
return nil |
|||
} |
|||
|
|||
func (f *fakeToggler) enableVacuum() error { |
|||
f.enableCalls++ |
|||
return nil |
|||
} |
|||
|
|||
func TestSyncVacuumState(t *testing.T) { |
|||
t.Parallel() |
|||
|
|||
t.Run("no change when state matches", func(t *testing.T) { |
|||
tog := &fakeToggler{} |
|||
result, failed := syncVacuumState(false, false, tog, false) |
|||
if result != false || failed { |
|||
t.Error("expected false, no failure") |
|||
} |
|||
result, failed = syncVacuumState(true, true, tog, false) |
|||
if result != true || failed { |
|||
t.Error("expected true, no failure") |
|||
} |
|||
if tog.disableCalls != 0 || tog.enableCalls != 0 { |
|||
t.Errorf("expected no calls, got disable=%d enable=%d", tog.disableCalls, tog.enableCalls) |
|||
} |
|||
}) |
|||
|
|||
t.Run("worker connects triggers disable", func(t *testing.T) { |
|||
tog := &fakeToggler{} |
|||
result, failed := syncVacuumState(true, false, tog, false) |
|||
if result != true || failed { |
|||
t.Error("expected true after disable, no failure") |
|||
} |
|||
if tog.disableCalls != 1 { |
|||
t.Errorf("expected 1 disable call, got %d", tog.disableCalls) |
|||
} |
|||
if tog.enableCalls != 0 { |
|||
t.Errorf("expected 0 enable calls, got %d", tog.enableCalls) |
|||
} |
|||
}) |
|||
|
|||
t.Run("worker disconnects triggers enable", func(t *testing.T) { |
|||
tog := &fakeToggler{} |
|||
result, failed := syncVacuumState(false, true, tog, false) |
|||
if result != false || failed { |
|||
t.Error("expected false after enable, no failure") |
|||
} |
|||
if tog.enableCalls != 1 { |
|||
t.Errorf("expected 1 enable call, got %d", tog.enableCalls) |
|||
} |
|||
if tog.disableCalls != 0 { |
|||
t.Errorf("expected 0 disable calls, got %d", tog.disableCalls) |
|||
} |
|||
}) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue