Skip to content

Commit c204a44

Browse files
committed
fix
1 parent 631fb63 commit c204a44

File tree

4 files changed

+33
-84
lines changed

4 files changed

+33
-84
lines changed

module/modmanager/manager.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"regexp"
1010
"runtime"
11-
"slices"
1211
"strings"
1312
"sync"
1413
"time"
@@ -690,75 +689,6 @@ func (mgr *Manager) ValidateConfig(ctx context.Context, conf resource.Config) ([
690689
// and modified resources. It also puts modular resources whose module has been modified or added in conf.Added if
691690
// they are not already there since the resources themselves are not necessarily new.
692691
func (mgr *Manager) ResolveImplicitDependenciesInConfig(ctx context.Context, conf *config.Diff) error {
693-
// NOTE(benji): We could simplify some of the following `continue`
694-
// conditional clauses to a single clause, but we split them for readability.
695-
for _, c := range conf.Right.Components {
696-
mod, ok := mgr.getModule(c)
697-
if !ok {
698-
// continue if this component is not being provided by a module.
699-
continue
700-
}
701-
702-
lenModified, lenAdded := len(conf.Modified.Modules), len(conf.Added.Modules)
703-
deltaModules := make([]config.Module, lenModified, lenModified+lenAdded)
704-
copy(deltaModules, conf.Modified.Modules)
705-
deltaModules = append(deltaModules, conf.Added.Modules...)
706-
707-
if !slices.ContainsFunc(deltaModules, func(elem config.Module) bool {
708-
return elem.Name == mod.cfg.Name
709-
}) {
710-
// continue if this modular component is not being handled by a modified
711-
// or added module.
712-
continue
713-
}
714-
if slices.ContainsFunc(conf.Added.Components, func(elem resource.Config) bool {
715-
return elem.Name == c.Name
716-
}) {
717-
// continue if this modular component handled by a modified module is
718-
// already in conf.Added.Components.
719-
continue
720-
}
721-
722-
// Add modular component to conf.Added.Components.
723-
conf.Added.Components = append(conf.Added.Components, c)
724-
// If component is in conf.Modified, the user modified a module and its
725-
// component at the same time. Remove that resource from conf.Modified so
726-
// the restarted module receives an AddResourceRequest and not a
727-
// ReconfigureResourceRequest.
728-
conf.Modified.Components = slices.DeleteFunc(
729-
conf.Modified.Components, func(elem resource.Config) bool { return elem.Name == c.Name })
730-
}
731-
for _, s := range conf.Right.Services {
732-
mod, ok := mgr.getModule(s)
733-
if !ok {
734-
// continue if this service is not being provided by a module.
735-
continue
736-
}
737-
if !slices.ContainsFunc(conf.Modified.Modules, func(elem config.Module) bool {
738-
return elem.Name == mod.cfg.Name
739-
}) {
740-
// continue if this modular service is not being handled by a modified
741-
// module.
742-
continue
743-
}
744-
if slices.ContainsFunc(conf.Added.Services, func(elem resource.Config) bool {
745-
return elem.Name == s.Name
746-
}) {
747-
// continue if this modular service handled by a modified module is
748-
// already in conf.Added.Services.
749-
continue
750-
}
751-
752-
// Add modular service to conf.Added.Services.
753-
conf.Added.Services = append(conf.Added.Services, s)
754-
// If service is in conf.Modified, the user modified a module and its
755-
// service at the same time. Remove that resource from conf.Modified so
756-
// the restarted module receives an AddResourceRequest and not a
757-
// ReconfigureResourceRequest.
758-
conf.Modified.Services = slices.DeleteFunc(
759-
conf.Modified.Services, func(elem resource.Config) bool { return elem.Name == s.Name })
760-
}
761-
762692
// If something was added or modified, go through components and services in
763693
// diff.Added and diff.Modified, call Validate on all those that are modularized,
764694
// and store implicit dependencies.

resource/graph_node.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,18 @@ func (w *GraphNode) SetNewConfig(newConfig Config, dependencies []string) {
383383
// dependency updates. If the node was previously marked for removal,
384384
// this makes no changes.
385385
func (w *GraphNode) SetNeedsUpdate() {
386-
// doing two mutex ops here but we assume there's only one caller.
387386
w.setNeedsReconfigure(w.Config(), false, w.UnresolvedDependencies())
388387
}
389388

389+
// Reinitialize is used to inform the node that it should
390+
// rebuild itself with the same config in cases where modules reconfigured
391+
// or crashed.
392+
func (w *GraphNode) Reinitialize() {
393+
// doing two mutex ops here but we assume there's only one caller.
394+
w.UnsetResource()
395+
w.setNeedsReconfigure(w.Config(), true, w.UnresolvedDependencies())
396+
}
397+
390398
// setUnresolvedDependencies sets names that are yet to be resolved as
391399
// dependencies for the node. Note that even an empty list will still
392400
// set needsDependencyResolution to true. If no resolution is needed,

robot/impl/local_robot.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,14 @@ func New(
552552
}
553553

554554
// removeOrphanedResources is called by the module manager to remove resources
555-
// orphaned due to module crashes.
555+
// orphaned due to module crashes. Resources passed into this function will be
556+
// reinitialized and handled by the completeConfig worker.
556557
func (r *localRobot) removeOrphanedResources(ctx context.Context,
557558
rNames []resource.Name,
558559
) {
559560
r.reconfigurationLock.Lock()
560561
defer r.reconfigurationLock.Unlock()
561-
r.manager.markResourcesRemoved(rNames, nil)
562-
if err := r.manager.removeMarkedAndClose(ctx, nil); err != nil {
563-
r.logger.CErrorw(ctx, "error removing and closing marked resources",
564-
"error", err)
565-
}
562+
r.manager.reinitializeResources(rNames)
566563
r.updateWeakAndOptionalDependents(ctx)
567564
}
568565

robot/impl/resource_manager.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,16 +1158,11 @@ func (manager *resourceManager) updateResources(
11581158
manager.logger.CErrorw(ctx, "module config validation error; skipping", "module", mod.Name, "error", err)
11591159
continue
11601160
}
1161-
orphanedResourceNames, err := manager.moduleManager.Reconfigure(ctx, mod)
1161+
affectedResourceNames, err := manager.moduleManager.Reconfigure(ctx, mod)
11621162
if err != nil {
11631163
manager.logger.CErrorw(ctx, "error reconfiguring module", "module", mod.Name, "error", err)
11641164
}
1165-
for _, resToClose := range manager.markResourcesRemoved(orphanedResourceNames, nil) {
1166-
if err := resToClose.Close(ctx); err != nil {
1167-
manager.logger.CErrorw(ctx, "error closing now orphaned resource", "resource",
1168-
resToClose.Name().String(), "module", mod.Name, "error", err)
1169-
}
1170-
}
1165+
manager.reinitializeResources(affectedResourceNames)
11711166
}
11721167

11731168
if manager.moduleManager != nil {
@@ -1333,6 +1328,25 @@ func (manager *resourceManager) markResourcesRemoved(
13331328
return resourcesToCloseBeforeComplete
13341329
}
13351330

1331+
// reinitializeResources reinitializes resources passed in, forcing a rebuild of the resource during
1332+
// reconfiguration and/or completeConfig loop. This function assumes the resources passed in
1333+
// are already Closed and thus will not call Close.
1334+
func (manager *resourceManager) reinitializeResources(rNames []resource.Name) {
1335+
for _, rName := range rNames {
1336+
// Disable changes to shell in untrusted
1337+
if manager.opts.untrustedEnv && rName.API == shell.API {
1338+
continue
1339+
}
1340+
1341+
resNode, ok := manager.resources.Node(rName)
1342+
if !ok {
1343+
continue
1344+
}
1345+
resNode.Reinitialize()
1346+
manager.markChildrenForUpdate(rName)
1347+
}
1348+
}
1349+
13361350
// createConfig will create a config.Config based on the current state of the
13371351
// resource graph, processManager and moduleManager. The created config will
13381352
// possibly contain default services registered by the RDK and not specified by

0 commit comments

Comments
 (0)