Skip to content

Commit 9d9c779

Browse files
author
Brendan Doyle
committed
Merge branch 'master' into add-etcd-client-auth
2 parents d80bca7 + 8843579 commit 9d9c779

File tree

4 files changed

+90
-8
lines changed

4 files changed

+90
-8
lines changed

common/scala/src/main/scala/org/apache/openwhisk/common/Logging.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,9 @@ object LoggingMarkers {
592592
// Time that is needed to produce message in kafka
593593
val SCHEDULER_KAFKA = LogMarkerToken(scheduler, kafka, start)(MeasurementUnit.time.milliseconds)
594594
val SCHEDULER_KAFKA_WAIT_TIME =
595-
LogMarkerToken(scheduler, "kafkaWaitTime", counter)(MeasurementUnit.none)
596-
def SCHEDULER_WAIT_TIME(action: String) = LogMarkerToken(scheduler, "waitTime", counter, Some(action), Map("action" -> action))(MeasurementUnit.none)
595+
LogMarkerToken(scheduler, "kafkaWaitTime", counter)(MeasurementUnit.time.milliseconds)
596+
def SCHEDULER_WAIT_TIME(action: String) =
597+
LogMarkerToken(scheduler, "waitTime", counter, Some(action), Map("action" -> action))(MeasurementUnit.time.milliseconds)
597598

598599
def SCHEDULER_KEEP_ALIVE(leaseId: Long) =
599600
LogMarkerToken(scheduler, "keepAlive", counter, None, Map("leaseId" -> leaseId.toString))(MeasurementUnit.none)

core/scheduler/src/main/scala/org/apache/openwhisk/core/scheduler/queue/MemoryQueue.scala

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ import org.apache.openwhisk.core.etcd.EtcdClient
3535
import org.apache.openwhisk.core.etcd.EtcdKV.ContainerKeys.containerPrefix
3636
import org.apache.openwhisk.core.etcd.EtcdKV.{ContainerKeys, QueueKeys, ThrottlingKeys}
3737
import org.apache.openwhisk.core.scheduler.grpc.{GetActivation, ActivationResponse => GetActivationResponse}
38-
import org.apache.openwhisk.core.scheduler.message.{ContainerCreation, ContainerDeletion, FailedCreationJob, SuccessfulCreationJob}
38+
import org.apache.openwhisk.core.scheduler.message.{
39+
ContainerCreation,
40+
ContainerDeletion,
41+
FailedCreationJob,
42+
SuccessfulCreationJob
43+
}
3944
import org.apache.openwhisk.core.scheduler.{SchedulerEndpoints, SchedulingConfig}
4045
import org.apache.openwhisk.core.service._
4146
import org.apache.openwhisk.http.Messages.{namespaceLimitUnderZero, tooManyConcurrentRequests}
@@ -47,7 +52,7 @@ import scala.annotation.tailrec
4752
import scala.collection.immutable.Queue
4853
import scala.collection.mutable
4954
import scala.concurrent.duration._
50-
import scala.concurrent.{ExecutionContextExecutor, Future, Promise, duration}
55+
import scala.concurrent.{duration, ExecutionContextExecutor, Future, Promise}
5156
import scala.util.{Failure, Success}
5257

5358
// States
@@ -453,7 +458,9 @@ class MemoryQueue(private val etcdClient: EtcdClient,
453458
case `inProgressContainerPrefixKey` =>
454459
creationIds -= key.split("/").last
455460
case `existingContainerPrefixKey` =>
456-
containers -= key.split("/").last
461+
val containerId = key.split("/").last
462+
removeDeletedContainerFromRequestBuffer(containerId)
463+
containers -= containerId
457464
case _ =>
458465
}
459466
stay
@@ -499,6 +506,7 @@ class MemoryQueue(private val etcdClient: EtcdClient,
499506
handleActivationRequest(request)
500507
} else {
501508
logging.info(this, s"Remove containerId because ${request.containerId} is not alive")
509+
removeDeletedContainerFromRequestBuffer(request.containerId)
502510
sender ! GetActivationResponse(Left(NoActivationMessage()))
503511
containers -= request.containerId
504512
stay
@@ -766,7 +774,9 @@ class MemoryQueue(private val etcdClient: EtcdClient,
766774
activation.transid)
767775

768776
val totalTimeInScheduler = Interval(activation.transid.meta.start, Instant.now()).duration
769-
MetricEmitter.emitHistogramMetric(LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString), totalTimeInScheduler.toMillis)
777+
MetricEmitter.emitHistogramMetric(
778+
LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString),
779+
totalTimeInScheduler.toMillis)
770780

771781
val activationResponse =
772782
if (isWhiskError)
@@ -931,14 +941,26 @@ class MemoryQueue(private val etcdClient: EtcdClient,
931941
} else None
932942
}
933943

944+
private def removeDeletedContainerFromRequestBuffer(containerId: String): Unit = {
945+
requestBuffer = requestBuffer.filter { buffer =>
946+
if (buffer.containerId.drop(1) == containerId) {
947+
buffer.promise.trySuccess(Left(NoActivationMessage()))
948+
false
949+
} else
950+
true
951+
}
952+
}
953+
934954
private def handleActivationMessage(msg: ActivationMessage) = {
935955
logging.info(this, s"[$invocationNamespace:$action:$stateName] got a new activation message ${msg.activationId}")(
936956
msg.transid)
937957
in.incrementAndGet()
938958
takeUncompletedRequest()
939959
.map { res =>
940960
val totalTimeInScheduler = Interval(msg.transid.meta.start, Instant.now()).duration
941-
MetricEmitter.emitHistogramMetric(LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString), totalTimeInScheduler.toMillis)
961+
MetricEmitter.emitHistogramMetric(
962+
LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString),
963+
totalTimeInScheduler.toMillis)
942964
res.trySuccess(Right(msg))
943965
in.decrementAndGet()
944966
stay
@@ -960,7 +982,9 @@ class MemoryQueue(private val etcdClient: EtcdClient,
960982
this,
961983
s"[$invocationNamespace:$action:$stateName] Get activation request ${request.containerId}, send one message: ${msg.activationId}")
962984
val totalTimeInScheduler = Interval(msg.transid.meta.start, Instant.now()).duration
963-
MetricEmitter.emitHistogramMetric(LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString), totalTimeInScheduler.toMillis)
985+
MetricEmitter.emitHistogramMetric(
986+
LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString),
987+
totalTimeInScheduler.toMillis)
964988

965989
sender ! GetActivationResponse(Right(msg))
966990
tryDisableActionThrottling()

tests/src/test/scala/org/apache/openwhisk/core/scheduler/queue/test/MemoryQueueTests.scala

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,60 @@ class MemoryQueueTests
697697
fsm.stop()
698698
}
699699

700+
it should "not send msg to a deleted container" in {
701+
val mockEtcdClient = mock[EtcdClient]
702+
val probe = TestProbe()
703+
val tid = TransactionId(TransactionId.generateTid())
704+
705+
expectDurationChecking(mockEsClient, testInvocationNamespace)
706+
707+
val fsm =
708+
TestFSMRef(
709+
new MemoryQueue(
710+
mockEtcdClient,
711+
durationChecker,
712+
fqn,
713+
mockMessaging(),
714+
schedulingConfig,
715+
testInvocationNamespace,
716+
revision,
717+
endpoints,
718+
actionMetadata,
719+
probe.ref,
720+
probe.ref,
721+
probe.ref,
722+
TestProbe().ref,
723+
schedulerId,
724+
ack,
725+
store,
726+
getUserLimit,
727+
checkToDropStaleActivation,
728+
queueConfig))
729+
730+
fsm.setState(Running, RunningData(probe.ref, probe.ref))
731+
732+
val sender1 = TestProbe()
733+
val sender2 = TestProbe()
734+
fsm.tell(GetActivation(tid, fqn, "1", false, None), sender1.ref)
735+
fsm.tell(GetActivation(tid, fqn, "2", false, None), sender2.ref)
736+
fsm.tell(GetActivation(tid, fqn, "2", false, None, false), sender2.ref)
737+
fsm ! message
738+
739+
// sender 1 will get a message while sender 2 will get a NoActivationMessage
740+
sender1.expectMsg(GetActivationResponse(Right(message)))
741+
sender2.expectMsg(GetActivationResponse(Left(NoActivationMessage())))
742+
sender2.expectMsg(GetActivationResponse(Left(NoActivationMessage())))
743+
744+
fsm.tell(GetActivation(tid, fqn, "1", false, None), sender1.ref)
745+
fsm.tell(GetActivation(tid, fqn, "2", false, None), sender2.ref)
746+
fsm ! WatchEndpointRemoved(existingContainerKey, "2", "", true) // remove container2 using watch event
747+
fsm ! message
748+
749+
// sender 1 will get a message while sender 2 will get a NoActivationMessage
750+
sender1.expectMsg(GetActivationResponse(Right(message)))
751+
sender2.expectMsg(GetActivationResponse(Left(NoActivationMessage())))
752+
}
753+
700754
it should "send response to request according to the order of container id and warmed flag" in {
701755
val mockEtcdClient = mock[EtcdClient]
702756
val probe = TestProbe()

tools/ow-utils/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ RUN apt-get update && apt-get install -y \
3535
locales \
3636
&& rm -rf /var/lib/apt/lists/*
3737

38+
# update npm
39+
RUN npm install -g n && n stable && hash -r
40+
3841
RUN locale-gen en_US.UTF-8
3942
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
4043

0 commit comments

Comments
 (0)