ryan-johnson-databricks commented on code in PR #40982:
URL: https://github.com/apache/spark/pull/40982#discussion_r1191678570
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala:
##########
@@ -1576,8 +1576,13 @@ object CodeGenerator extends Logging {
* they are explicitly removed. A Cache on the other hand is generally
configured to evict entries
* automatically, in order to constrain its memory footprint. Note that
this cache does not use
* weak keys/values and thus does not respond to memory pressure.
+ *
+ * We wrap Guava Cache with NonFateSharingCache: tasks for similar queries
that run concurrently
+ * can hit the same codegen cache key at the same time. If one query fails
or gets canceled while
+ * some of its tasks are doing codegen, it will cause spurious failures in
all other queries with
+ * tasks that wait on the same cache key. See NonFateSharingCache for more
details.
Review Comment:
If we move some of this to the NonFateSharingCache doc comment, it might
suffice to say something simpler here, like:
> Codegen can be slow. Use a non fate sharing cache in case a query gets
canceled during code gen while other queries wait on the same code, so that
those other queries don't get wrongly aborted. See [[NonFateSharingCache]] for
more details.
##########
core/src/main/scala/org/apache/spark/util/NonFateSharingCache.scala:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.util
+
+import java.util.concurrent.Callable
+
+import com.google.common.cache.Cache
+import com.google.common.cache.LoadingCache
+
+/**
+ * SPARK-43300: Guava cache fate-sharing behavior might lead to unexpected
cascade failure:
+ * when multiple threads access the same key in the cache at the same time
when the key is not in
+ * the cache, Guava cache will block all requests and load the data only once.
If the loading fails,
+ * all requests will fail immediately without retry. Therefore individual
failure will also fail
+ * other irrelevant queries who are waiting for the same key.
Review Comment:
Maybe add a final connection like:
> Given that spark can cancel tasks at arbitrary times for many different
reasons, fate sharing means that a task which gets canceled while populating a
cache entry can cause spurious failures in tasks from unrelated jobs -- even
though those tasks would have successfully populated the cache if they had been
allowed to try.
--
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]