[SPARK-3161][MLLIB] Adding a node Id caching mechanism for training deci...

...sion trees. @jkbradley @mengxr @chouqin Please review this.
The current implementation should be correct. When we compute `nodeIds` (this is where `nodeIds` gets materialized), `prevNodeIds` should be cached. So after the computation, we have both RDDs cached. `count()` doesn't help here. `take(1)` may only cache the first partition.

One thing to watch is the closure size of those RDDs. If we happen to reference lots of stuff, it will increase the storage requirement on the driver, who needs to remember how to re-compute each RDD.