I'm running a Spark 3.4 long running structured streaming job. Whenever the job starts, an application directory of the form app-xxxxxxxxxx is created for the job in the work directory. However within that directory, additional directories are created, the first being named 0, the second named 1 and so on.
My first question is, why are these directories being created? Over the course of the structured streaming job, the micro batch may get triggered 20 times but only 4 of these sub directories under the app-xxxxxxxxxx directory are created, the point being that the creation of these sub directories doesn't correspond to execution of a micro batch. So, I'm not sure why they're being created.
My second related question is, how can I configure Spark to delete these folders after a certain amount of time? Each contains the application .jar and stderr and stdout files, so over time they take up a significant amount of space. My understanding is that setting spark.worker.cleanup.enabled=true only enables cleanup for stopped applications. However in my case, I have a long running application which I would like to enable cleanup for.