Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scheduler Enhancement] Remove deleted containers. #5265

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,9 @@ object LoggingMarkers {
// Time that is needed to produce message in kafka
val SCHEDULER_KAFKA = LogMarkerToken(scheduler, kafka, start)(MeasurementUnit.time.milliseconds)
val SCHEDULER_KAFKA_WAIT_TIME =
LogMarkerToken(scheduler, "kafkaWaitTime", counter)(MeasurementUnit.none)
def SCHEDULER_WAIT_TIME(action: String) = LogMarkerToken(scheduler, "waitTime", counter, Some(action), Map("action" -> action))(MeasurementUnit.none)
LogMarkerToken(scheduler, "kafkaWaitTime", counter)(MeasurementUnit.time.milliseconds)
def SCHEDULER_WAIT_TIME(action: String) =
LogMarkerToken(scheduler, "waitTime", counter, Some(action), Map("action" -> action))(MeasurementUnit.time.milliseconds)

def SCHEDULER_KEEP_ALIVE(leaseId: Long) =
LogMarkerToken(scheduler, "keepAlive", counter, None, Map("leaseId" -> leaseId.toString))(MeasurementUnit.none)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ import org.apache.openwhisk.core.etcd.EtcdClient
import org.apache.openwhisk.core.etcd.EtcdKV.ContainerKeys.containerPrefix
import org.apache.openwhisk.core.etcd.EtcdKV.{ContainerKeys, QueueKeys, ThrottlingKeys}
import org.apache.openwhisk.core.scheduler.grpc.{GetActivation, ActivationResponse => GetActivationResponse}
import org.apache.openwhisk.core.scheduler.message.{ContainerCreation, ContainerDeletion, FailedCreationJob, SuccessfulCreationJob}
import org.apache.openwhisk.core.scheduler.message.{
ContainerCreation,
ContainerDeletion,
FailedCreationJob,
SuccessfulCreationJob
}
import org.apache.openwhisk.core.scheduler.{SchedulerEndpoints, SchedulingConfig}
import org.apache.openwhisk.core.service._
import org.apache.openwhisk.http.Messages.{namespaceLimitUnderZero, tooManyConcurrentRequests}
Expand All @@ -47,7 +52,7 @@ import scala.annotation.tailrec
import scala.collection.immutable.Queue
import scala.collection.mutable
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContextExecutor, Future, Promise, duration}
import scala.concurrent.{duration, ExecutionContextExecutor, Future, Promise}
import scala.util.{Failure, Success}

// States
Expand Down Expand Up @@ -453,7 +458,9 @@ class MemoryQueue(private val etcdClient: EtcdClient,
case `inProgressContainerPrefixKey` =>
creationIds -= key.split("/").last
case `existingContainerPrefixKey` =>
containers -= key.split("/").last
val containerId = key.split("/").last
removeDeletedContainerFromRequestBuffer(containerId)
containers -= containerId
case _ =>
}
stay
Expand Down Expand Up @@ -499,6 +506,7 @@ class MemoryQueue(private val etcdClient: EtcdClient,
handleActivationRequest(request)
} else {
logging.info(this, s"Remove containerId because ${request.containerId} is not alive")
removeDeletedContainerFromRequestBuffer(request.containerId)
sender ! GetActivationResponse(Left(NoActivationMessage()))
containers -= request.containerId
stay
Expand Down Expand Up @@ -766,7 +774,9 @@ class MemoryQueue(private val etcdClient: EtcdClient,
activation.transid)

val totalTimeInScheduler = Interval(activation.transid.meta.start, Instant.now()).duration
MetricEmitter.emitHistogramMetric(LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString), totalTimeInScheduler.toMillis)
MetricEmitter.emitHistogramMetric(
LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString),
totalTimeInScheduler.toMillis)

val activationResponse =
if (isWhiskError)
Expand Down Expand Up @@ -931,14 +941,26 @@ class MemoryQueue(private val etcdClient: EtcdClient,
} else None
}

private def removeDeletedContainerFromRequestBuffer(containerId: String): Unit = {
requestBuffer = requestBuffer.filter { buffer =>
if (buffer.containerId.drop(1) == containerId) {
buffer.promise.trySuccess(Left(NoActivationMessage()))
false
} else
true
}
}

private def handleActivationMessage(msg: ActivationMessage) = {
logging.info(this, s"[$invocationNamespace:$action:$stateName] got a new activation message ${msg.activationId}")(
msg.transid)
in.incrementAndGet()
takeUncompletedRequest()
.map { res =>
val totalTimeInScheduler = Interval(msg.transid.meta.start, Instant.now()).duration
MetricEmitter.emitHistogramMetric(LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString), totalTimeInScheduler.toMillis)
MetricEmitter.emitHistogramMetric(
LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString),
totalTimeInScheduler.toMillis)
res.trySuccess(Right(msg))
in.decrementAndGet()
stay
Expand All @@ -960,7 +982,9 @@ class MemoryQueue(private val etcdClient: EtcdClient,
this,
s"[$invocationNamespace:$action:$stateName] Get activation request ${request.containerId}, send one message: ${msg.activationId}")
val totalTimeInScheduler = Interval(msg.transid.meta.start, Instant.now()).duration
MetricEmitter.emitHistogramMetric(LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString), totalTimeInScheduler.toMillis)
MetricEmitter.emitHistogramMetric(
LoggingMarkers.SCHEDULER_WAIT_TIME(action.asString),
totalTimeInScheduler.toMillis)

sender ! GetActivationResponse(Right(msg))
tryDisableActionThrottling()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,60 @@ class MemoryQueueTests
fsm.stop()
}

it should "not send msg to a deleted container" in {
val mockEtcdClient = mock[EtcdClient]
val probe = TestProbe()
val tid = TransactionId(TransactionId.generateTid())

expectDurationChecking(mockEsClient, testInvocationNamespace)

val fsm =
TestFSMRef(
new MemoryQueue(
mockEtcdClient,
durationChecker,
fqn,
mockMessaging(),
schedulingConfig,
testInvocationNamespace,
revision,
endpoints,
actionMetadata,
probe.ref,
probe.ref,
probe.ref,
TestProbe().ref,
schedulerId,
ack,
store,
getUserLimit,
checkToDropStaleActivation,
queueConfig))

fsm.setState(Running, RunningData(probe.ref, probe.ref))

val sender1 = TestProbe()
val sender2 = TestProbe()
fsm.tell(GetActivation(tid, fqn, "1", false, None), sender1.ref)
fsm.tell(GetActivation(tid, fqn, "2", false, None), sender2.ref)
fsm.tell(GetActivation(tid, fqn, "2", false, None, false), sender2.ref)
fsm ! message

// sender 1 will get a message while sender 2 will get a NoActivationMessage
sender1.expectMsg(GetActivationResponse(Right(message)))
sender2.expectMsg(GetActivationResponse(Left(NoActivationMessage())))
sender2.expectMsg(GetActivationResponse(Left(NoActivationMessage())))

fsm.tell(GetActivation(tid, fqn, "1", false, None), sender1.ref)
fsm.tell(GetActivation(tid, fqn, "2", false, None), sender2.ref)
fsm ! WatchEndpointRemoved(existingContainerKey, "2", "", true) // remove container2 using watch event
fsm ! message

// sender 1 will get a message while sender 2 will get a NoActivationMessage
sender1.expectMsg(GetActivationResponse(Right(message)))
sender2.expectMsg(GetActivationResponse(Left(NoActivationMessage())))
}

it should "send response to request according to the order of container id and warmed flag" in {
val mockEtcdClient = mock[EtcdClient]
val probe = TestProbe()
Expand Down