Skip to content

Commit c507069

Browse files
authored
Do not put data to ETCD when no date is changed. (#5291)
* Do not put data to ETCD when no date is changed. * Update the hashcode calculation. * Take dedicated namespace into account when calculating the hash code. * Apply the comment. * Apply the comment.
1 parent 4912565 commit c507069

File tree

3 files changed

+127
-0
lines changed
  • common/scala/src/main/scala/org/apache/openwhisk/core/connector
  • core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler
  • tests/src/test/scala/org/apache/openwhisk/core/connector/test

3 files changed

+127
-0
lines changed

common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,31 @@ case class InvokerResourceMessage(status: String,
470470
* Serializes message to string. Must be idempotent.
471471
*/
472472
override def serialize: String = InvokerResourceMessage.serdes.write(this).compactPrint
473+
474+
override def equals(that: Any): Boolean =
475+
that match {
476+
case that: InvokerResourceMessage =>
477+
this.status == that.status &&
478+
this.freeMemory == that.freeMemory &&
479+
this.busyMemory == that.busyMemory &&
480+
this.inProgressMemory == that.inProgressMemory &&
481+
this.tags.toSet == that.tags.toSet &&
482+
this.dedicatedNamespaces.toSet == that.dedicatedNamespaces.toSet
483+
484+
case _ => false
485+
}
486+
487+
override def hashCode: Int = {
488+
var result = 1
489+
val prime = 31
490+
result = prime * result + status.hashCode()
491+
result = prime * result + freeMemory.hashCode()
492+
result = prime * result + busyMemory.hashCode()
493+
result = prime * result + inProgressMemory.hashCode()
494+
result = prime * result + tags.hashCode()
495+
result = prime * result + dedicatedNamespaces.hashCode()
496+
result
497+
}
473498
}
474499

475500
object InvokerResourceMessage extends DefaultJsonProtocol {

core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/Scheduler.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,21 @@ case class SchedulerStates(sid: SchedulerInstanceId, queueSize: Int, endpoints:
389389
def getSchedulerId(): SchedulerInstanceId = sid
390390

391391
def serialize = SchedulerStates.serdes.write(this).compactPrint
392+
393+
override def equals(that: Any): Boolean =
394+
that match {
395+
case that: SchedulerStates => {
396+
this.queueSize == that.queueSize
397+
}
398+
case _ => false
399+
}
400+
401+
override def hashCode: Int = {
402+
var result = 1
403+
val prime = 31
404+
result = prime * result + queueSize.hashCode()
405+
result
406+
}
392407
}
393408

394409
object SchedulerStates extends DefaultJsonProtocol {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.apache.openwhisk.core.connector.test
2+
3+
import akka.actor.ActorSystem
4+
import akka.testkit.TestKit
5+
import org.apache.openwhisk.common.InvokerState.{Healthy, Unhealthy}
6+
import org.apache.openwhisk.core.connector.InvokerResourceMessage
7+
import org.apache.openwhisk.core.entity.SchedulerInstanceId
8+
import org.apache.openwhisk.core.scheduler.{SchedulerEndpoints, SchedulerStates}
9+
import org.junit.runner.RunWith
10+
import org.scalatest.junit.JUnitRunner
11+
import org.scalatest.{FlatSpecLike, Matchers}
12+
13+
@RunWith(classOf[JUnitRunner])
14+
class MessageTests extends TestKit(ActorSystem("Message")) with FlatSpecLike with Matchers {
15+
behavior of "Message"
16+
17+
it should "be able to compare the InvokerResourceMessage" in {
18+
val msg1 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
19+
val msg2 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
20+
21+
msg1 == msg2 shouldBe true
22+
}
23+
24+
it should "be different when the state of InvokerResourceMessage is different" in {
25+
val msg1 = InvokerResourceMessage(Unhealthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
26+
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
27+
28+
msg1 != msg2 shouldBe true
29+
}
30+
31+
it should "be different when the free memory of InvokerResourceMessage is different" in {
32+
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
33+
val msg2 = InvokerResourceMessage(Healthy.asString, 2048L, 0, 0, Seq.empty, Seq.empty)
34+
35+
msg1 != msg2 shouldBe true
36+
}
37+
38+
it should "be different when the busy memory of InvokerResourceMessage is different" in {
39+
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
40+
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 1024L, 0, Seq.empty, Seq.empty)
41+
42+
msg1 != msg2 shouldBe true
43+
}
44+
45+
it should "be different when the in-progress memory of InvokerResourceMessage is different" in {
46+
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq.empty)
47+
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 1024L, Seq.empty, Seq.empty)
48+
49+
msg1 != msg2 shouldBe true
50+
}
51+
52+
it should "be different when the tags of InvokerResourceMessage is different" in {
53+
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq("tag1"), Seq.empty)
54+
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq("tag1", "tag2"), Seq.empty)
55+
56+
msg1 != msg2 shouldBe true
57+
}
58+
59+
it should "be different when the dedicated namespaces of InvokerResourceMessage is different" in {
60+
val msg1 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq("ns1"))
61+
val msg2 = InvokerResourceMessage(Healthy.asString, 1024L, 0, 0, Seq.empty, Seq("ns2"))
62+
63+
msg1 != msg2 shouldBe true
64+
}
65+
66+
it should "be able to compare the SchedulerStates" in {
67+
val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 0, SchedulerEndpoints("10.10.10.10", 1234, 1234))
68+
val msg2 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 0, SchedulerEndpoints("10.10.10.10", 1234, 1234))
69+
70+
msg1 == msg2 shouldBe true
71+
}
72+
73+
it should "be different when the queue size of SchedulerStates is different" in {
74+
val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 20, SchedulerEndpoints("10.10.10.10", 1234, 1234))
75+
val msg2 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 10, SchedulerEndpoints("10.10.10.10", 1234, 1234))
76+
77+
msg1 != msg2 shouldBe true
78+
}
79+
80+
it should "be not different when other than the queue size of SchedulerStates is different" in {
81+
// only the queue size matter
82+
val msg1 = SchedulerStates(SchedulerInstanceId("0"), queueSize = 20, SchedulerEndpoints("10.10.10.10", 1234, 1234))
83+
val msg2 = SchedulerStates(SchedulerInstanceId("1"), queueSize = 20, SchedulerEndpoints("10.10.10.20", 5678, 5678))
84+
85+
msg1 == msg2 shouldBe true
86+
}
87+
}

0 commit comments

Comments
 (0)