Skip to content

Commit edefe75

Browse files
author
mani
committed
Removed timer, keeping only config change
1 parent e92b8ea commit edefe75

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

pkg/scheduler/objects/queue.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ type Queue struct {
8989
template *template.Template
9090
queueEvents *schedEvt.QueueEvents
9191
quotaChangePreemptionDelay uint64
92-
quotaChangePreemptionTimer *time.Timer
9392

9493
locking.RWMutex
9594
}
@@ -113,7 +112,6 @@ func newBlankQueue() *Queue {
113112
preemptionDelay: configs.DefaultPreemptionDelay,
114113
preemptionPolicy: policies.DefaultPreemptionPolicy,
115114
quotaChangePreemptionDelay: 0,
116-
quotaChangePreemptionTimer: nil,
117115
}
118116
}
119117

@@ -409,37 +407,30 @@ func (sq *Queue) setPreemptionSettings(oldMaxResource *resources.Resource, conf
409407
// Quota decrease
410408
case resources.StrictlyGreaterThan(oldMaxResource, newMaxResource) && conf.Preemption.Delay != 0:
411409
set = true
410+
// Quota increase
411+
case resources.StrictlyGreaterThan(newMaxResource, oldMaxResource) && conf.Preemption.Delay != 0:
412+
reset = true
412413
// Quota remains as is but delay has changed
413414
case resources.Equals(oldMaxResource, newMaxResource) && conf.Preemption.Delay != 0 && sq.quotaChangePreemptionDelay != conf.Preemption.Delay:
414415
sq.quotaChangePreemptionDelay = conf.Preemption.Delay
415-
sq.quotaChangePreemptionTimer.Reset(time.Duration(sq.quotaChangePreemptionDelay))
416-
// Quota increase
417416
default:
418-
reset = true
417+
// noop
419418
}
420419
}
421420

422421
// Set preemption settings
423422
if set {
424423
sq.quotaChangePreemptionDelay = conf.Preemption.Delay
425-
sq.quotaChangePreemptionTimer = time.AfterFunc(time.Duration(sq.quotaChangePreemptionDelay), sq.tryPreemptionToEnforceQuota)
426424
}
427425

428426
// Reset preemption settings
429427
if reset {
430428
if sq.quotaChangePreemptionDelay != 0 {
431429
sq.quotaChangePreemptionDelay = 0
432-
sq.quotaChangePreemptionTimer.Stop()
433-
sq.quotaChangePreemptionTimer = nil
434430
}
435431
}
436432
}
437433

438-
// tryPreemptionToEnforceQuota Try Preemption to enforce quota change if the quota change preemption delay is reached
439-
func (sq *Queue) tryPreemptionToEnforceQuota() {
440-
441-
}
442-
443434
// setResourcesFromConf sets the maxResource and guaranteedResource of the queue from the config.
444435
func (sq *Queue) setResourcesFromConf(resource configs.Resources) error {
445436
maxResource, err := resources.NewResourceFromConf(resource.Max)

pkg/scheduler/objects/queue_test.go

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,63 +2250,64 @@ func TestQuotaChangePreemptionSettings(t *testing.T) {
22502250

22512251
parent, err := createManagedQueueWithProps(root, "parent", false, getResourceConf(), getResourceConf())
22522252
assert.NilError(t, err, "failed to create basic queue: %v", err)
2253-
2254-
var nilTimer *time.Timer
22552253
testCases := []struct {
22562254
name string
22572255
conf configs.QueueConfig
22582256
expectedDelay uint64
2259-
expectedTimer *time.Timer
22602257
}{{"first queue setup without delay", configs.QueueConfig{
22612258
Resources: configs.Resources{
22622259
Max: getResourceConf(),
22632260
Guaranteed: getResourceConf(),
22642261
},
2265-
}, 0, nilTimer},
2262+
}, 0},
22662263
{"increase max with delay", configs.QueueConfig{
22672264
Resources: configs.Resources{
22682265
Max: map[string]string{"memory": "100000000"},
22692266
},
22702267
Preemption: configs.Preemption{
22712268
Delay: 500,
22722269
},
2273-
}, 0, nilTimer},
2270+
}, 0},
22742271
{"decrease max with delay", configs.QueueConfig{
22752272
Resources: configs.Resources{
22762273
Max: map[string]string{"memory": "100"},
22772274
},
22782275
Preemption: configs.Preemption{
22792276
Delay: 500,
22802277
},
2281-
}, 500, time.AfterFunc(time.Duration(500), parent.tryPreemptionToEnforceQuota)},
2278+
}, 500},
22822279
{"max remains as is but delay changed", configs.QueueConfig{
22832280
Resources: configs.Resources{
22842281
Max: map[string]string{"memory": "100"},
22852282
},
22862283
Preemption: configs.Preemption{
22872284
Delay: 200,
22882285
},
2289-
}, 200, time.AfterFunc(time.Duration(200), parent.tryPreemptionToEnforceQuota)},
2286+
}, 200},
2287+
{"unrelated config change, should not impact earlier set preemption settings", configs.QueueConfig{
2288+
Resources: configs.Resources{
2289+
Max: map[string]string{"memory": "100"},
2290+
Guaranteed: map[string]string{"memory": "50"},
2291+
},
2292+
Preemption: configs.Preemption{
2293+
Delay: 200,
2294+
},
2295+
}, 200},
22902296
{"increase max again with delay", configs.QueueConfig{
22912297
Resources: configs.Resources{
22922298
Max: map[string]string{"memory": "101"},
22932299
},
22942300
Preemption: configs.Preemption{
22952301
Delay: 200,
22962302
},
2297-
}, 0, nilTimer}}
2303+
}, 0}}
22982304

22992305
for _, tc := range testCases {
23002306
t.Run(tc.name, func(t *testing.T) {
23012307
err = parent.ApplyConf(tc.conf)
23022308
assert.NilError(t, err, "failed to apply conf: %v", err)
23032309
assert.Assert(t, parent.maxResource != nil)
23042310
assert.Equal(t, parent.quotaChangePreemptionDelay, tc.expectedDelay)
2305-
if tc.expectedTimer != nil {
2306-
assert.Equal(t, *parent.quotaChangePreemptionTimer, *tc.expectedTimer)
2307-
} else {
2308-
assert.Assert(t, parent.quotaChangePreemptionTimer == nil)
2309-
}
23102311
})
23112312
}
23122313
}
@@ -2341,8 +2342,6 @@ func TestNewConfiguredQueue(t *testing.T) {
23412342
assert.Assert(t, resources.Equals(resourceStruct, parent.template.GetMaxResource()))
23422343
assert.Assert(t, resources.Equals(resourceStruct, parent.template.GetGuaranteedResource()))
23432344
assert.Equal(t, parent.quotaChangePreemptionDelay, uint64(0))
2344-
var expectedTimer *time.Timer
2345-
assert.Equal(t, parent.quotaChangePreemptionTimer, expectedTimer)
23462345

23472346
// case 0: managed leaf queue can't use template
23482347
leafConfig := configs.QueueConfig{
@@ -2369,8 +2368,6 @@ func TestNewConfiguredQueue(t *testing.T) {
23692368
assert.NilError(t, err, "Resource creation failed")
23702369
assert.Assert(t, resources.Equals(childLeaf.guaranteedResource, childLeafGuaranteed))
23712370
assert.Equal(t, childLeaf.quotaChangePreemptionDelay, uint64(500))
2372-
leafExpectedTimer := time.AfterFunc(time.Duration(uint64(500)), childLeaf.tryPreemptionToEnforceQuota)
2373-
assert.Equal(t, *childLeaf.quotaChangePreemptionTimer, *leafExpectedTimer)
23742371

23752372
// case 1: non-leaf can't use template but it can inherit template from parent
23762373
NonLeafConfig := configs.QueueConfig{
@@ -2388,8 +2385,6 @@ func TestNewConfiguredQueue(t *testing.T) {
23882385
assert.Assert(t, childNonLeaf.guaranteedResource == nil)
23892386
assert.Assert(t, childNonLeaf.maxResource == nil)
23902387
assert.Equal(t, childNonLeaf.quotaChangePreemptionDelay, uint64(0))
2391-
var nonLeafExpectedTimer *time.Timer
2392-
assert.Equal(t, childNonLeaf.quotaChangePreemptionTimer, nonLeafExpectedTimer)
23932388

23942389
// case 2: do not send queue event when silence flag is set to true
23952390
events.Init()
@@ -2407,8 +2402,6 @@ func TestNewConfiguredQueue(t *testing.T) {
24072402
noEvents := eventSystem.Store.CountStoredEvents()
24082403
assert.Equal(t, noEvents, uint64(0), "expected 0 event, got %d", noEvents)
24092404
assert.Equal(t, rootQ.quotaChangePreemptionDelay, uint64(0))
2410-
var rootQTimer *time.Timer
2411-
assert.Equal(t, rootQ.quotaChangePreemptionTimer, rootQTimer)
24122405
}
24132406

24142407
func TestResetRunningState(t *testing.T) {

0 commit comments

Comments
 (0)