PHILO-HE commented on code in PR #8143: URL: https://github.com/apache/incubator-gluten/pull/8143#discussion_r1872533814
########## gluten-core/src/main/scala/org/apache/gluten/backend/Component.scala: ########## @@ -0,0 +1,251 @@ +/* + * 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.gluten.backend + +import org.apache.gluten.extension.columnar.transition.ConventionFunc +import org.apache.gluten.extension.injector.Injector + +import org.apache.spark.SparkContext +import org.apache.spark.annotation.Experimental +import org.apache.spark.api.plugin.PluginContext + +import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger} + +import scala.collection.mutable + +/** + * The base API to inject user-defined logic to Gluten. To register a component, its implementations + * should be placed to Gluten's classpath with a Java service file. Gluten will discover all the + * component implementations then register them at the booting time. + * + * Experimental: This is not expected to be used in production yet. Use [[Backend]] instead. + */ +@Experimental +trait Component { + import Component._ + + private val uid = nextUid.getAndIncrement() + private val isRegistered = new AtomicBoolean(false) + + def ensureRegistered(): Unit = { + if (!isRegistered.compareAndSet(false, true)) { + return + } + graph.add(this) + dependencies().foreach(req => graph.declareDependency(this, req)) + } + + /** Base information. */ + def name(): String + def buildInfo(): BuildInfo + def dependencies(): Seq[Class[_ <: Component]] + + /** Spark listeners. */ + def onDriverStart(sc: SparkContext, pc: PluginContext): Unit = {} + def onDriverShutdown(): Unit = {} + def onExecutorStart(pc: PluginContext): Unit = {} + def onExecutorShutdown(): Unit = {} + + /** + * Overrides [[org.apache.gluten.extension.columnar.transition.ConventionFunc]] Gluten is using to + * determine the convention (its row-based processing / columnar-batch processing support) of a + * plan with a user-defined function that accepts a plan then returns convention type it outputs, + * and input conventions it requires. + */ + def convFuncOverride(): ConventionFunc.Override = ConventionFunc.Override.Empty + + /** Query planner rules. */ + def injectRules(injector: Injector): Unit +} + +object Component { + private val nextUid = new AtomicInteger() + private val graph: Graph = new Graph() + + // format: off + /** + * Apply topology sort on all registered components in graph to get an ordered list of + * components. The root nodes will be on the head side of the list, while leaf nodes + * will be on the tail side of the list. + * + * Say if component-A depends on component-B while component-C requires nothing, then the + * output order will be one of the following: + * + * 1. [component-B, component-A, component-C] + * 2. [component-C, component-B, component-A] + * 3. [component-B, component-C, component-A] Review Comment: Just some questions need clarification from my superficial understanding. 1. The class loading order potentially decides the occurrence of any one of the above ordered legal combination? 2. If A depends on both B & C and there is no dependency between B and C, I assume the above 2nd/3rd combinations are acceptable. Is it possible that they produce different behaviors? For example, both B and C override some rule in A. The order of B and C will determine which one actually overrides that rule? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
