如何访问应该从 DAGScheduler 缓存的 RDD?

How to access RDDs that are supposed to be cached from the DAGScheduler?

有谁知道如何从 DAGScheduler 中提取应该缓存的 RDD。不是真正缓存的那些,而是那些打算在阶段开始执行之前缓存的。

您可以使用 SparkContext.getPersistentRDDs:

spark.sparkContext.getPersistentRDDs: Map[Int, RDD[_]]

Returns an immutable map of RDDs that have marked themselves as persistent via cache() call.

DAGScheduler

DAGScheduler 不参与缓存 RDD(并且很少参与任务执行)。

DAGScheduler 是一个 "function",它接受 RDD 谱系(因此 RDD 依赖项的 DAG 的前缀 DAG)并生成具有任务的阶段的 DAG(如 TaskSets ) 并且仅针对缺少的分区执行任务(即 BlockManager 没有 RDD 块)。

话虽如此,我会立即将你关于从 DAGScheduler 访问缓存 RDD 的问题标记为无效。

getPersistentRDDs

您可以使用 SparkContext.getPersistentRDDs(如 指出的那样),但它为您提供了 请求 为 cached/persisted 的 RDD(但是要么还没有,要么永远不会)。

cachepersist 方法是惰性的,因此只有当您执行操作时,RDD 块存储在执行程序的 BlockManagers 中(因此无需再次从源读取数据即可访问) .

持久化 RDD 也可能会失败(例如内存不足),但内部注册表仍然可以引用缓存的 RDD。


(仍在研究 cache/persist 会失败的用例)