Skip to content

Commit bab5ce6

Browse files
committed
Apply comments
1 parent 5635e36 commit bab5ce6

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

ansible/group_vars/all

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,8 @@ etcd_connect_string: "{% set ret = [] %}\
450450
{{ ret.append( hostvars[host].ansible_host + ':' + ((etcd.client.port+loop.index-1)|string) ) }}\
451451
{% endfor %}\
452452
{{ ret | join(',') }}"
453+
454+
scheduler:
455+
dataManagementService:
456+
retryInterval: "{{ scheduler_dataManagementService_retryInterval | default(1 second) }}"
457+

common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,6 @@ object ConfigKeys {
291291
val azBlob = "whisk.azure-blob"
292292

293293
val whiskClusterName = "whisk.cluster.name"
294+
295+
val dataManagementServiceRetryInterval = "whisk.scheduler.data-management-service.retryInterval"
294296
}

common/scala/src/main/scala/org/apache/openwhisk/core/service/DataManagementService.scala

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import akka.actor.{Actor, ActorRef, ActorRefFactory, ActorSystem, Props}
44
import akka.util.Timeout
55
import io.grpc.StatusRuntimeException
66
import org.apache.openwhisk.common.Logging
7+
import org.apache.openwhisk.core.ConfigKeys
78
import org.apache.openwhisk.core.etcd.{EtcdClient, EtcdFollower, EtcdLeader}
89
import org.apache.openwhisk.core.service.DataManagementService.retryInterval
10+
import pureconfig.loadConfigOrThrow
911

1012
import scala.collection.concurrent.TrieMap
1113
import scala.collection.mutable.{Map, Queue}
14+
import scala.concurrent.ExecutionContext
1215
import scala.concurrent.duration._
13-
import scala.concurrent.{ExecutionContext, Future}
1416
import scala.util.Success
1517

1618
// messages received by the actor
@@ -22,7 +24,7 @@ case class RegisterInitialData(key: String,
2224
recipient: Option[ActorRef] = None)
2325

2426
case class RegisterData(key: String, value: String, failoverEnabled: Boolean = true)
25-
case class DeRegisterData(key: String)
27+
case class UnregisterData(key: String)
2628
case class UpdateDataOnChange(key: String, value: String)
2729

2830
// messages sent by the actor
@@ -66,15 +68,15 @@ class DataManagementService(watcherService: ActorRef, workerFactory: ActorRefFac
6668
// normally these messages will be sent when queues are created.
6769
case request: ElectLeader =>
6870
if (inProgressKeys.contains(request.key)) {
69-
logging.info(this, s"save request $request into a buffer")
71+
logging.info(this, s"save a request $request into a buffer")
7072
operations.getOrElseUpdate(request.key, Queue.empty[Any]).enqueue(request)
7173
} else {
7274
worker ! request
7375
inProgressKeys = inProgressKeys + request.key
7476
}
7577

7678
case request: RegisterInitialData =>
77-
// send WatchEndpoint first as the put operation will be retry until success if failed
79+
// send WatchEndpoint first as the put operation will be retried until success if failed
7880
if (request.failoverEnabled)
7981
watcherService ! WatchEndpoint(request.key, request.value, isPrefix = false, watcherName, Set(DeleteEvent))
8082
if (inProgressKeys.contains(request.key)) {
@@ -108,8 +110,9 @@ class DataManagementService(watcherService: ActorRef, workerFactory: ActorRefFac
108110

109111
case request: WatcherClosed =>
110112
if (inProgressKeys.contains(request.key)) {
111-
// the new put|delete operation will erase influences made by older operations like put&delete
112-
// so we can remove these old operations
113+
// The put|delete operations against the same key will overwrite the previous results.
114+
// For example, if we put a value, delete it and put a new value again, the final result will be the new value.
115+
// So we can remove these old operations
113116
logging.info(this, s"save request $request into a buffer")
114117
val queue = operations.getOrElseUpdate(request.key, Queue.empty[Any]).filter { value =>
115118
value match {
@@ -126,8 +129,8 @@ class DataManagementService(watcherService: ActorRef, workerFactory: ActorRefFac
126129

127130
// It is required to close the watcher first before deleting etcd data
128131
// It is supposed to receive the WatcherClosed message after the watcher is stopped.
129-
case msg: DeRegisterData =>
130-
watcherService ! UnWatchEndpoint(msg.key, isPrefix = false, watcherName, needFeedback = true)
132+
case msg: UnregisterData =>
133+
watcherService ! UnwatchEndpoint(msg.key, isPrefix = false, watcherName, needFeedback = true)
131134

132135
case WatchEndpointRemoved(_, key, value, false) =>
133136
self ! RegisterInitialData(key, value, failoverEnabled = false) // the watcher is already setup
@@ -140,7 +143,6 @@ class DataManagementService(watcherService: ActorRef, workerFactory: ActorRefFac
140143
dataCache.get(msg.key) match {
141144
case Some(cached) if cached == msg.value =>
142145
logging.debug(this, s"skip publishing data ${msg.key} because the data is not changed.")
143-
// do nothing
144146

145147
case Some(cached) if cached != msg.value =>
146148
dataCache.update(msg.key, msg.value)
@@ -155,21 +157,20 @@ class DataManagementService(watcherService: ActorRef, workerFactory: ActorRefFac
155157
}
156158

157159
object DataManagementService {
158-
// Todo: Change to configuration
159-
val retryInterval: FiniteDuration = 1.second
160+
val retryInterval: FiniteDuration = loadConfigOrThrow[FiniteDuration](ConfigKeys.dataManagementServiceRetryInterval)
160161

161162
def props(watcherService: ActorRef, workerFactory: ActorRefFactory => ActorRef)(implicit logging: Logging,
162163
actorSystem: ActorSystem): Props = {
163164
Props(new DataManagementService(watcherService, workerFactory))
164165
}
165166
}
166167

167-
class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec: ExecutionContext,
168+
private[service] class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec: ExecutionContext,
168169
actorSystem: ActorSystem,
169170
logging: Logging)
170171
extends Actor {
171172

172-
private val parent = context.parent
173+
private val dataManagementService = context.parent
173174
private var lease: Option[Lease] = None
174175
leaseService ! GetLease
175176

@@ -186,7 +187,7 @@ class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec
186187
.andThen {
187188
case Success(msg) =>
188189
request.recipient ! ElectionResult(msg)
189-
parent ! FinishWork(request.key)
190+
dataManagementService ! FinishWork(request.key)
190191
}
191192
.recover {
192193
// if there is no lease, reissue it and retry immediately
@@ -215,7 +216,7 @@ class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec
215216
.put(request.key, request.value, l.id)
216217
.andThen {
217218
case Success(_) =>
218-
parent ! FinishWork(request.key)
219+
dataManagementService ! FinishWork(request.key)
219220
}
220221
.recover {
221222
// if there is no lease, reissue it and retry immediately
@@ -243,12 +244,12 @@ class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec
243244
etcdClient
244245
.putTxn(request.key, request.value, 0, l.id)
245246
.map { res =>
246-
parent ! FinishWork(request.key)
247+
dataManagementService ! FinishWork(request.key)
247248
if (res.getSucceeded) {
248-
logging.debug(this, s"data is stored.")
249+
logging.info(this, s"initial data storing succeeds for ${request.key}")
249250
request.recipient.map(_ ! InitialDataStorageResults(request.key, Right(Done())))
250251
} else {
251-
logging.debug(this, s"data is already stored for: $request")
252+
logging.info(this, s"data is already stored for: $request, cancel the initial data storing")
252253
request.recipient.map(_ ! InitialDataStorageResults(request.key, Left(AlreadyExist())))
253254
}
254255
}
@@ -278,7 +279,7 @@ class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec
278279
.del(msg.key)
279280
.andThen {
280281
case Success(_) =>
281-
parent ! FinishWork(msg.key)
282+
dataManagementService ! FinishWork(msg.key)
282283
}
283284
.recover {
284285
// if there is no lease, reissue it and retry immediately
@@ -296,11 +297,8 @@ class EtcdWorker(etcdClient: EtcdClient, leaseService: ActorRef)(implicit val ec
296297

297298
}
298299

299-
private def sendMessageToSelfAfter(msg: Any, retryInterval: FiniteDuration): Future[Unit] = {
300-
akka.pattern.after(retryInterval, actorSystem.scheduler) {
301-
self ! msg
302-
Future.successful({})
303-
}
300+
private def sendMessageToSelfAfter(msg: Any, retryInterval: FiniteDuration) = {
301+
actorSystem.scheduler.scheduleOnce(retryInterval, self, msg)
304302
}
305303
}
306304

common/scala/src/main/scala/org/apache/openwhisk/core/service/LeaseKeepAliveService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ case object NoData extends KeepAliveServiceData
66
case class Lease(id: Long, ttl: Long) extends KeepAliveServiceData
77

88
// Events received by the actor
9-
case object ReGrantLease
9+
case object RegrantLease
1010
case object GetLease
1111
case object GrantLease
1212

common/scala/src/main/scala/org/apache/openwhisk/core/service/WatcherService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ case class WatchEndpoint(key: String,
66
isPrefix: Boolean,
77
name: String,
88
listenEvents: Set[EtcdEvent] = Set.empty)
9-
case class UnWatchEndpoint(watchKey: String, isPrefix: Boolean, watchName: String, needFeedback: Boolean = false)
9+
case class UnwatchEndpoint(watchKey: String, isPrefix: Boolean, watchName: String, needFeedback: Boolean = false)
1010

1111
/**
1212
* The watchKey and key can be different when it is for prefixed watch.

0 commit comments

Comments
 (0)