Skip to content

Commit 02774f1

Browse files
committed
[core] 7 day eviction policy for task class cache
1 parent ddcc146 commit 02774f1

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

core/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"os/user"
3434
"path/filepath"
3535
"strings"
36+
"time"
3637

3738
"github.com/AliceO2Group/Control/apricot"
3839
apricotpb "github.com/AliceO2Group/Control/apricot/protos"
@@ -120,6 +121,7 @@ func setDefaults() error {
120121
viper.SetDefault("concurrentIteratorRoleExpansion", true)
121122
viper.SetDefault("reuseUnlockedTasks", false)
122123
viper.SetDefault("configCache", true)
124+
viper.SetDefault("taskClassCacheTTL", 7*24*time.Hour)
123125
return nil
124126
}
125127

@@ -183,6 +185,7 @@ func setFlags() error {
183185
pflag.Bool("concurrentIteratorRoleExpansion", viper.GetBool("concurrentIteratorRoleExpansion"), "Expand iterator roles concurrently during workflow template processing")
184186
pflag.Bool("reuseUnlockedTasks", viper.GetBool("reuseUnlockedTasks"), "Reuse unlocked active tasks when satisfying environment deployment requests")
185187
pflag.Bool("configCache", viper.GetBool("configCache"), "Enable cache layer between AliECS core and Apricot")
188+
pflag.Duration("taskClassCacheTTL", viper.GetDuration("taskClassCacheTTL"), "TTL for task class cache entries")
186189

187190
pflag.Parse()
188191
return viper.BindPFlags(pflag.CommandLine)

core/task/manager.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,18 @@ func (m *Manager) removeInactiveClasses() {
251251
_ = m.classes.Do(func(classMap *map[string]*taskclass.Class) error {
252252
keys := make([]string, 0)
253253

254+
taskClassCacheTTL := viper.GetDuration("taskClassCacheTTL")
255+
254256
// push keys of classes that don't appear in roster any more into a slice
255-
for taskClassIdentifier := range *classMap {
257+
for taskClassIdentifier, class := range *classMap {
258+
if class == nil {
259+
// don't really know what to do with a valid TCI but nil class
260+
continue
261+
}
262+
if time.Since(class.UpdatedTimestamp) < taskClassCacheTTL {
263+
// class is still fresh, skip
264+
continue
265+
}
256266
if len(m.roster.filteredForClass(taskClassIdentifier)) == 0 {
257267
keys = append(keys, taskClassIdentifier)
258268
}

core/task/taskclass/class.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package taskclass
2626

2727
import (
2828
"fmt"
29+
"time"
2930

3031
"github.com/AliceO2Group/Control/common"
3132
"github.com/AliceO2Group/Control/common/controlmode"
@@ -64,13 +65,14 @@ type Class struct {
6465
Control struct {
6566
Mode controlmode.ControlMode `yaml:"mode"`
6667
} `yaml:"control"`
67-
Command *common.CommandInfo `yaml:"command"`
68-
Wants ResourceWants `yaml:"wants"`
69-
Limits *ResourceLimits `yaml:"limits"`
70-
Bind []channel.Inbound `yaml:"bind"`
71-
Properties gera.StringMap `yaml:"properties"`
72-
Constraints []constraint.Constraint `yaml:"constraints"`
73-
Connect []channel.Outbound `yaml:"connect"`
68+
Command *common.CommandInfo `yaml:"command"`
69+
Wants ResourceWants `yaml:"wants"`
70+
Limits *ResourceLimits `yaml:"limits"`
71+
Bind []channel.Inbound `yaml:"bind"`
72+
Properties gera.StringMap `yaml:"properties"`
73+
Constraints []constraint.Constraint `yaml:"constraints"`
74+
Connect []channel.Outbound `yaml:"connect"`
75+
UpdatedTimestamp time.Time `yaml:"-"`
7476
}
7577

7678
func (c *Class) UnmarshalYAML(unmarshal func(interface{}) error) (err error) {
@@ -106,17 +108,18 @@ func (c *Class) UnmarshalYAML(unmarshal func(interface{}) error) (err error) {
106108
}
107109
}
108110
*c = Class{
109-
Identifier: aux.Identifier,
110-
Defaults: gera.MakeStringMapWithMap(aux.Defaults),
111-
Vars: gera.MakeStringMapWithMap(aux.Vars),
112-
Control: aux.Control,
113-
Command: aux.Command,
114-
Wants: aux.Wants,
115-
Limits: aux.Limits,
116-
Bind: aux.Bind,
117-
Properties: gera.MakeStringMapWithMap(aux.Properties),
118-
Constraints: aux.Constraints,
119-
Connect: aux.Connect,
111+
Identifier: aux.Identifier,
112+
Defaults: gera.MakeStringMapWithMap(aux.Defaults),
113+
Vars: gera.MakeStringMapWithMap(aux.Vars),
114+
Control: aux.Control,
115+
Command: aux.Command,
116+
Wants: aux.Wants,
117+
Limits: aux.Limits,
118+
Bind: aux.Bind,
119+
Properties: gera.MakeStringMapWithMap(aux.Properties),
120+
Constraints: aux.Constraints,
121+
Connect: aux.Connect,
122+
UpdatedTimestamp: time.Now(),
120123
}
121124
}
122125
return

core/task/taskclass/classes.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424

2525
package taskclass
2626

27-
import "sync"
27+
import (
28+
"sync"
29+
"time"
30+
)
2831

2932
type Classes struct {
3033
mu sync.RWMutex
@@ -75,7 +78,9 @@ func (c *Classes) DeleteKeys(keys []string) {
7578
func (c *Classes) UpdateClass(key string, class *Class) {
7679
c.mu.Lock()
7780
defer c.mu.Unlock()
78-
if _, ok := c.classMap[key]; ok { //contains
81+
82+
class.UpdatedTimestamp = time.Now() // used for invalidating stale classcache entries
83+
if _, ok := c.classMap[key]; ok { //contains
7984
*c.classMap[key] = *class // update
8085
} else {
8186
c.classMap[key] = class // else add class as new entry

0 commit comments

Comments
 (0)