You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by GitBox <gi...@apache.org> on 2019/03/20 10:35:23 UTC

[GitHub] [carbondata] NamanRastogi commented on a change in pull request #3146: [CARBONDATA-3318] Added PreAgg & Bloom Event-Listener for ShowCacheCommmand

NamanRastogi commented on a change in pull request #3146: [CARBONDATA-3318]  Added PreAgg & Bloom Event-Listener for ShowCacheCommmand
URL: https://github.com/apache/carbondata/pull/3146#discussion_r267274209
 
 

 ##########
 File path: integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/cache/DropCacheEventListeners.scala
 ##########
 @@ -0,0 +1,135 @@
+/*
+* 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.spark.sql.execution.command.cache
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.CarbonEnv
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.execution.command.cache.DropCachePreAggEventListener.LOGGER
+
+import org.apache.carbondata.common.logging.LogServiceFactory
+import org.apache.carbondata.core.cache.{Cacheable, CacheProvider}
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.datamap.DataMapStoreManager
+import org.apache.carbondata.datamap.bloom.{BloomCacheKeyValue, BloomCoarseGrainDataMapFactory}
+import org.apache.carbondata.events.{DropCacheEvent, Event, OperationContext, OperationEventListener}
+import org.apache.carbondata.processing.merger.CarbonDataMergerUtil
+
+object DropCachePreAggEventListener extends OperationEventListener {
+
+  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
+
+  /**
+   * Called on a specified event occurrence
+   *
+   * @param event
+   * @param operationContext
+   */
+  override protected def onEvent(event: Event, operationContext: OperationContext): Unit = {
+    event match {
+      case dropCacheEvent: DropCacheEvent =>
+        val carbonTable = dropCacheEvent.carbonTable
+        val sparkSession = dropCacheEvent.sparkSession
+        val internalCall = dropCacheEvent.internalCall
+        if (carbonTable.isChildDataMap && !internalCall) {
+          throw new UnsupportedOperationException("Operation not allowed on child table.")
+        }
+
+        if (carbonTable.hasDataMapSchema) {
+          val childrenSchemas = carbonTable.getTableInfo.getDataMapSchemaList.asScala
+            .filter(_.getRelationIdentifier != null)
+          for (childSchema <- childrenSchemas) {
+            val childTable =
+              CarbonEnv.getCarbonTable(
+                TableIdentifier(childSchema.getRelationIdentifier.getTableName,
+                  Some(childSchema.getRelationIdentifier.getDatabaseName)))(sparkSession)
+            try {
+              val dropCacheCommandForChildTable =
+                CarbonDropCacheCommand(
+                  TableIdentifier(childTable.getTableName, Some(childTable.getDatabaseName)),
+                  internalCall = true)
+              dropCacheCommandForChildTable.processMetadata(sparkSession)
+            }
+            catch {
+              case e: Exception =>
+                LOGGER.error(
+                  s"Clean cache for PreAgg table ${childTable.getTableName} failed.", e)
+            }
+          }
+        }
+    }
+  }
+}
+
+
+object DropCacheBloomEventListener extends OperationEventListener {
+
+  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
+
+  /**
+   * Called on a specified event occurrence
+   *
+   * @param event
+   * @param operationContext
+   */
+  override protected def onEvent(event: Event, operationContext: OperationContext): Unit = {
+    event match {
+      case dropCacheEvent: DropCacheEvent =>
+        val carbonTable = dropCacheEvent.carbonTable
+        val sparkSession = dropCacheEvent.sparkSession
+        val cache = CacheProvider.getInstance().getCarbonCache
+        val currentTableSizeMap = operationContext.getProperty(carbonTable.getTableUniqueName)
+          .asInstanceOf[mutable.Map[String, (String, Long, Long)]]
+
+        val datamaps = DataMapStoreManager.getInstance().getDataMapSchemasOfTable(carbonTable)
+          .asScala
+        val segments = CarbonDataMergerUtil
+          .getValidSegmentList(carbonTable.getAbsoluteTableIdentifier).asScala
+
+        datamaps.foreach {
+          datamap =>
+            try {
+              val shardPaths = segments.flatMap {
 
 Review comment:
   Done.

----------------------------------------------------------------
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