kunal642 commented on a change in pull request #3177: 
[CARBONDATA-3337][CARBONDATA-3306] Distributed index server
URL: https://github.com/apache/carbondata/pull/3177#discussion_r278407987
 
 

 ##########
 File path: 
integration/spark2/src/main/scala/org/apache/carbondata/indexserver/IndexServer.scala
 ##########
 @@ -0,0 +1,136 @@
+/*
+ * 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.carbondata.indexserver
+
+import java.net.InetSocketAddress
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.ipc.{ProtocolInfo, RPC}
+import org.apache.spark.SparkConf
+import org.apache.spark.scheduler.{SparkListener, SparkListenerApplicationEnd}
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.util.SparkSQLUtil
+
+import org.apache.carbondata.common.logging.LogServiceFactory
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.datamap.DistributableDataMapFormat
+import org.apache.carbondata.core.exception.InvalidConfigurationException
+import org.apache.carbondata.core.indexstore.ExtendedBlocklet
+import org.apache.carbondata.core.util.CarbonProperties
+
+@ProtocolInfo(protocolName = "Server", protocolVersion = 1)
+trait ServerInterface {
+  def getSplits(request: DistributableDataMapFormat): Array[ExtendedBlocklet]
+
+  def invalidateCache(request: DistributableDataMapFormat): Unit
+
+  def showCache(tableName: String) : Seq[String]
+}
+
+object IndexServer extends ServerInterface {
+
+  val isDistributedPruning: Boolean =
+    CarbonProperties.getInstance().isDistributedPruningEnabled("", "")
+
+  private val LOGGER = LogServiceFactory.getLogService(this.getClass.getName)
+
+  private val serverIp: String = 
CarbonProperties.getInstance().getIndexServerIP
+
+  private val serverPort: Int = 
CarbonProperties.getInstance().getIndexServerPort
+
+  /**
+   * Getting sparkSession from ActiveSession because in case of embedded mode 
the session would
+   * have already been created whereas in case of distributed mode the session 
would be
+   * created by the main method after some validations.
+   */
+  private var sparkSession: SparkSession = SparkSQLUtil.getSparkSession
+
+  def getSplits(request: DistributableDataMapFormat): Array[ExtendedBlocklet] 
= {
+    val splits = new DistributedPruneRDD(sparkSession, request).collect()
+    DistributedRDDUtils.updateExecutorCacheSize(splits.map(_._1).toSet)
+    splits.map(_._2)
+  }
+
+  override def invalidateCache(request: DistributableDataMapFormat): Unit = {
+    val splits = new DistributedPruneRDD(sparkSession, request).collect()
+    DistributedRDDUtils.updateExecutorCacheSize(splits.map(_._1).toSet)
+    if (request.isJobToClearDataMaps) {
+      
DistributedRDDUtils.invalidateCache(request.getCarbonTable.getTableUniqueName)
+    }
+  }
+
+  override def showCache(tableName: String = ""): Seq[String] = {
+    new DistributedShowCacheRDD(sparkSession, tableName).collect().toSeq
+  }
+
+  def main(args: Array[String]): Unit = {
+    if (serverIp.isEmpty) {
+      throw new RuntimeException(s"Please set the server IP to use Index Cache 
Server")
+    } else if (!isDistributedPruning) {
+      throw new RuntimeException(
+        s"Please set ${ CarbonCommonConstants.CARBON_ENABLE_INDEX_SERVER }" +
+        s" as true to use index server")
+    } else {
+      val (storePath, masterURL) = if (args.length == 1) {
+        (args.head, "local")
+      } else if (args.length == 2) {
+        (args.head, args.tail.head)
+      } else {
+        (null, "local")
+      }
+      sparkSession = createCarbonSession(storePath, masterURL)
+      LOGGER.info("Starting Index Cache Server")
+      val conf = new Configuration()
+      val server: RPC.Server = new RPC.Builder(conf).setInstance(this)
+        .setBindAddress(serverIp)
+        .setPort(serverPort)
+        .setProtocol(classOf[ServerInterface]).build
+      server.start()
+      sparkSession.sparkContext.addSparkListener(new SparkListener {
+        override def onApplicationEnd(applicationEnd: 
SparkListenerApplicationEnd): Unit = {
+          LOGGER.info("Spark Application has ended. Stopping the Index Server")
+          server.stop()
+        }
+      })
+      LOGGER.info(s"Index cache server running on ${ server.getPort } port")
+    }
+  }
+
+  private def createCarbonSession(storePath: String, masterURL: String): 
SparkSession = {
+    import org.apache.spark.sql.CarbonSession._
+    val master = System.getProperty("spark.master.url", masterURL)
+    if (master == null) {
+      throw new InvalidConfigurationException("Spark master URL is not set.")
+    }
+    val spark = SparkSession
+      .builder().config(new SparkConf())
 
 Review comment:
   yes they can be set in spark-defaults.conf.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to