Skip to content

Commit 965bfee

Browse files
committed
FIX: unique placement.
1 parent 918932c commit 965bfee

File tree

8 files changed

+136
-103
lines changed

8 files changed

+136
-103
lines changed

.version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{ "version":"v1.0.3", "builddate":"20240718" }]
1+
[{ "version":"v1.0.3", "builddate":"20240802" }]

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- ADD: Kafka Plugin to forware mesos event messages to kafka
1212
- CHANGE: Migrate to google protobuf
1313
- FIX: Scale up/down of a mesos task.
14+
- FIX: unique placement
1415

1516
## 1.0.3
1617

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/Showmax/go-fqdn v1.0.0
88
github.com/confluentinc/confluent-kafka-go v1.9.2
99
github.com/gorilla/mux v1.8.1
10-
github.com/redis/go-redis/v9 v9.5.4
10+
github.com/redis/go-redis/v9 v9.6.1
1111
github.com/sirupsen/logrus v1.9.3
1212
google.golang.org/protobuf v1.34.2
1313
gopkg.in/yaml.v3 v3.0.1
@@ -18,7 +18,7 @@ require (
1818
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
1919
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2020
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
21-
github.com/go-jose/go-jose/v4 v4.0.3 // indirect
21+
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
2222
github.com/hashicorp/errwrap v1.1.0 // indirect
2323
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
2424
github.com/hashicorp/go-multierror v1.1.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03D
5353
github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
5454
github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og=
5555
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
56-
github.com/go-jose/go-jose/v4 v4.0.3 h1:o8aphO8Hv6RPmH+GfzVuyf7YXSBibp+8YyHdOoDESGo=
57-
github.com/go-jose/go-jose/v4 v4.0.3/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc=
56+
github.com/go-jose/go-jose/v4 v4.0.4 h1:VsjPI33J0SB9vQM6PLmNjoHqMQNGPiZ0rHL7Ni7Q6/E=
57+
github.com/go-jose/go-jose/v4 v4.0.4/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc=
5858
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
5959
github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
6060
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -160,8 +160,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
160160
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
161161
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
162162
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
163-
github.com/redis/go-redis/v9 v9.5.4 h1:vOFYDKKVgrI5u++QvnMT7DksSMYg7Aw/Np4vLJLKLwY=
164-
github.com/redis/go-redis/v9 v9.5.4/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
163+
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
164+
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
165165
github.com/rogpeppe/clock v0.0.0-20190514195947-2896927a307a/go.mod h1:4r5QyqhjIWCcK8DO4KMclc5Iknq5qVBAlbYYzAbUScQ=
166166
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
167167
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=

redis/redis.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,31 @@ func (e *Redis) CountRedisKey(pattern string, ignoreState string) int {
125125
return count
126126
}
127127

128+
// CountRedisKeyState will get back the amount of redis keys with the spesific state.
129+
func (e *Redis) CountRedisKeyState(pattern string, state string) int {
130+
keys := e.GetAllRedisKeys(pattern)
131+
count := 0
132+
for keys.Next(e.CTX) {
133+
// ignore redis keys if they are not mesos tasks
134+
if e.CheckIfNotTask(keys) {
135+
continue
136+
}
137+
138+
// do not count these key
139+
if state != "" {
140+
// get the values of the current key
141+
key := e.GetRedisKey(keys.Val())
142+
task := e.Mesos.DecodeTask(key)
143+
144+
if task.State != state {
145+
continue
146+
}
147+
}
148+
count++
149+
}
150+
return count
151+
}
152+
128153
// SaveConfig store the current framework config
129154
func (e *Redis) SaveConfig(config cfg.Config) {
130155
data, _ := json.Marshal(config)

sbom.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

sbom.txt

Lines changed: 96 additions & 95 deletions
Large diffs are not rendered by default.

scheduler/heartbeat.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ func (e *Scheduler) Heartbeat() {
4040

4141
// there are lesser instances are running as it should be
4242
if e.Redis.CountRedisKey(task.TaskName+":*", "__KILL") < task.Instances {
43+
// do not schedule task if the placement is unique and the amount of running tasks
44+
// are same like the amount of mesos agents.
45+
if e.getLabelValue("__mc_placement", task) == "unique" && e.Redis.CountRedisKeyState(task.TaskName+":*", "TASK_RUNNING") >= e.Mesos.CountAgent {
46+
continue
47+
}
48+
4349
logrus.WithField("func", "scheduler.CheckState").Info("Scale up Mesos Task: ", task.TaskName)
4450
e.Mesos.Revive()
4551
task.State = ""

0 commit comments

Comments
 (0)