mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-28 07:50:44 +01:00
fix: address review comments on admin_script seeding
- Replace TOCTOU race (separate Load+Save) with atomic SaveJobTypeConfigIfNotExists on ConfigStore and Plugin - Replace ineffective polling loop with single GetMaster call using 30s context timeout, since GetMaster respects context cancellation - Add unit tests for SaveJobTypeConfigIfNotExists (in-memory + on-disk) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
5432c03ba5
commit
4b2a231913
4 files changed
+146
-18
No files matched your search
@@ -287,12 +287,12 @@ func (s *AdminServer) seedAdminScriptFromMaster() {
|
||||
return
|
||||
}
|
||||
|
||||
// Wait for master connection to be available
|
||||
for i := 0; i < 30; i++ {
|
||||
if s.masterClient.GetMaster(context.Background()) != "" {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
// Wait for master connection with a bounded timeout
|
||||
waitCtx, waitCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer waitCancel()
|
||||
if s.masterClient.GetMaster(waitCtx) == "" {
|
||||
glog.V(1).Infof("Timed out waiting for master connection for admin_script seeding")
|
||||
return
|
||||
}
|
||||
|
||||
var maintenanceScripts string
|
||||
@@ -318,16 +318,6 @@ func (s *AdminServer) seedAdminScriptFromMaster() {
|
||||
return
|
||||
}
|
||||
|
||||
// Only seed if the admin_script plugin does not already have a saved config
|
||||
existing, err := s.plugin.LoadJobTypeConfig("admin_script")
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to check admin_script plugin config: %v", err)
|
||||
return
|
||||
}
|
||||
if existing != nil {
|
||||
return
|
||||
}
|
||||
|
||||
interval := int64(sleepMinutes)
|
||||
if interval <= 0 {
|
||||
interval = clustermaintenance.DefaultMaintenanceSleepMinutes
|
||||
@@ -355,11 +345,14 @@ func (s *AdminServer) seedAdminScriptFromMaster() {
|
||||
UpdatedBy: "master_migration",
|
||||
}
|
||||
|
||||
if err := s.plugin.SaveJobTypeConfig(cfg); err != nil {
|
||||
saved, err := s.plugin.SaveJobTypeConfigIfNotExists(cfg)
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to seed admin_script plugin config from master: %v", err)
|
||||
return
|
||||
}
|
||||
glog.V(0).Infof("Seeded admin_script plugin config from master maintenance scripts (interval=%dm)", interval)
|
||||
if saved {
|
||||
glog.V(0).Infof("Seeded admin_script plugin config from master maintenance scripts (interval=%dm)", interval)
|
||||
}
|
||||
}
|
||||
|
||||
// cleanMaintenanceScript strips lock/unlock commands and normalizes a
|
||||
|
||||
Reference in new issue
Block a user