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_r281058472 ########## File path: integration/spark2/src/main/scala/org/apache/carbondata/indexserver/IndexServer.scala ########## @@ -0,0 +1,175 @@ +/* + * 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 java.security.PrivilegedAction + +import org.apache.hadoop.conf.Configuration +import org.apache.hadoop.ipc.{ProtocolInfo, RPC} +import org.apache.hadoop.net.NetUtils +import org.apache.hadoop.security.{KerberosInfo, SecurityUtil, UserGroupInformation} +import org.apache.spark.SparkConf +import org.apache.spark.scheduler.{SparkListener, SparkListenerApplicationEnd} +import org.apache.spark.sql.{CarbonSession, 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.datastore.impl.FileFactory +import org.apache.carbondata.core.indexstore.ExtendedBlocklet +import org.apache.carbondata.core.util.CarbonProperties + +@ProtocolInfo(protocolName = "Server", protocolVersion = 1) +@KerberosInfo(serverPrincipal = "spark.carbon.indexserver.principal", + clientPrincipal = "spark.carbon.indexserver.principal") +trait ServerInterface { + /** + * Used to prune and cache the datamaps for the table. + */ + def getSplits(request: DistributableDataMapFormat): Array[ExtendedBlocklet] + + /** + * Invalidate the cache for the provided table. + */ + def invalidateCache(request: DistributableDataMapFormat): Unit + + /** + * Get the cache size for the specified table. + */ + def showCache(tableName: String) : Array[String] + + /** + * Invalidate the cache for the specified segments only. Used in case of compaction/Update/Delete. + */ + def invalidateSegmentCache(databaseName: String, + tableName: String, + segmentIds: Array[String]): Unit +} + +/** + * An instance of a distributed Index Server which will be used for: + * 1. Pruning the datamaps in a distributed way by using the executors. + * 2. Caching the pruned datamaps in executor size to be reused in the next query. + * 3. Getting the size of the datamaps cached in the executors. + * 4. Clearing the datamaps for a table or for the specified invalid segments. + * + * Start using ./bin/start-indexserver.sh + * Stop using ./bin/stop-indexserver.sh + */ +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 lazy 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 lazy val sparkSession: SparkSession = SparkSQLUtil.getSparkSession + + private def doAs[T](f: => T): T = { + UserGroupInformation.getLoginUser.doAs(new PrivilegedAction[T] { + override def run(): T = { + f + } + }) + } + + def getSplits(request: DistributableDataMapFormat): Array[ExtendedBlocklet] = doAs { + val splits = new DistributedPruneRDD(sparkSession, request).collect() + DistributedRDDUtils.updateExecutorCacheSize(splits.map(_._1).toSet) + splits.map(_._2) + } + + override def invalidateCache(request: DistributableDataMapFormat): Unit = doAs { + val splits = new DistributedPruneRDD(sparkSession, request).collect() + DistributedRDDUtils.updateExecutorCacheSize(splits.map(_._1).toSet) + if (request.isJobToClearDataMaps) { + DistributedRDDUtils.invalidateCache(request.getCarbonTable.getTableUniqueName) + } + } + + override def invalidateSegmentCache(databaseName: String, tableName: String, + segmentIds: Array[String]): Unit = doAs { + new InvalidateSegmentCacheRDD(sparkSession, databaseName, tableName, segmentIds.toList) + .collect() + } + + override def showCache(tableName: String = ""): Array[String] = doAs { + new DistributedShowCacheRDD(sparkSession, tableName).collect() + } + + 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 { + createCarbonSession() + 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() Review comment: Thirft also defines HIVE_SERVER2_THRIFT_MIN_WORKER_THREADS(default 5) and the default for max is 500. ---------------------------------------------------------------- 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: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |