You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/10/09 19:07:28 UTC
[GitHub] [openwhisk] chetanmeh commented on a change in pull request #4677:
Switch to Cosmos SDK v3 for Cache Invalidator Service
chetanmeh commented on a change in pull request #4677: Switch to Cosmos SDK v3 for Cache Invalidator Service
URL: https://github.com/apache/openwhisk/pull/4677#discussion_r333183870
##########
File path: core/cosmosdb/cache-invalidator/src/main/scala/org/apache/openwhisk/core/database/cosmosdb/cache/ChangeFeedConsumer.scala
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.openwhisk.core.database.cosmosdb.cache
+
+import java.util
+
+import akka.Done
+import akka.event.slf4j.SLF4JLogging
+import com.azure.data.cosmos.internal.changefeed.implementation.ChangeFeedProcessorBuilderImpl
+import com.azure.data.cosmos.internal.changefeed.{ChangeFeedObserverCloseReason, ChangeFeedObserverContext}
+import com.azure.data.cosmos.{
+ ChangeFeedProcessor,
+ ChangeFeedProcessorOptions,
+ ConnectionPolicy,
+ CosmosClient,
+ CosmosContainer,
+ CosmosItemProperties
+}
+import reactor.core.publisher.Mono
+
+import scala.collection.JavaConverters._
+import scala.collection.immutable.Seq
+import scala.compat.java8.FutureConverters._
+import scala.concurrent.{ExecutionContext, Future}
+
+trait ChangeFeedObserver {
+ def process(context: ChangeFeedObserverContext, docs: Seq[CosmosItemProperties]): Future[Done]
+}
+
+class ChangeFeedConsumer(collName: String, config: CacheInvalidatorConfig, observer: ChangeFeedObserver)(
+ implicit ec: ExecutionContext)
+ extends SLF4JLogging {
+ import ChangeFeedConsumer._
+
+ log.info(s"Watching changes in $collName with lease managed in ${config.feedConfig.leaseCollection}")
+
+ private val clients = scala.collection.mutable.Map[ConnectionInfo, CosmosClient]().withDefault(createCosmosClient)
+ private val targetContainer = getContainer(collName)
+ private val leaseContainer = getContainer(config.feedConfig.leaseCollection, createIfNotExist = true)
+ private val (processor, startFuture) = {
+ val clusterId = config.invalidatorConfig.clusterId
+ val prefix = clusterId.map(id => s"$id-$collName").getOrElse(collName)
+
+ val feedOpts = new ChangeFeedProcessorOptions
+ feedOpts.leasePrefix(prefix)
+
+ val builder = ChangeFeedProcessor.Builder
+ .hostName(config.feedConfig.hostname)
+ .feedContainer(targetContainer)
+ .leaseContainer(leaseContainer)
+ .options(feedOpts)
+ .asInstanceOf[ChangeFeedProcessorBuilderImpl] //observerFactory is not exposed hence need to cast to impl
Review comment:
Opened Azure/azure-sdk-for-java#5744 to expose the proper api so that we do not have to rely on implementation details
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services