andygrove commented on code in PR #2889:
URL:
https://github.com/apache/datafusion-ballista/pull/2889#discussion_r4643005114
##########
ballista/scheduler/src/state/cache_linker.rs:
##########
@@ -316,7 +352,54 @@ impl CacheLinker {
let linked = inner.inflight.contains_key(job)
|| inner.pending.contains_key(job)
|| inner.dependents.contains_key(job);
- (reads, linked)
+ // Every orphan is checked, not just the builds `job` read: a read
moves
+ // to a rebuild's output, so the build it read before is read by no
one.
+ let orphaned = std::mem::take(&mut inner.orphaned);
Review Comment:
Small question. When `input_rebuilt` moves a read to a new build, the old
orphaned build is only freed at the next `job_ended` anywhere. On an idle
scheduler that could be a while. I think that's fine. Maybe worth a line in the
doc comment so it reads as intentional?
##########
ballista/scheduler/src/state/cache_linker.rs:
##########
@@ -734,6 +879,9 @@ impl<T: 'static + AsLogicalPlan, U: 'static +
AsExecutionPlan> SchedulerState<T,
inputs: &[usize],
sender: &EventSender<QueryStageSchedulerEvent>,
) -> std::result::Result<(), String> {
+ if job_reads.session_closed {
Review Comment:
Nice job on the `session_closed` flag, it reads cleanly and the new test
pins down the main path. One small window I noticed. The check in
`rebuild_lost_inputs` runs once on entry, against a snapshot of the reads. If
the session is removed during the awaits before `prepare_caches` tracks the
rebuild, the removal loop has nothing to cancel and the rebuild records a fresh
entry. The new branch in `provide_input` drops `read.key` then, which is good.
But a nested cache rebuilt along with it would stay pinned under the removed
session. Could we check `reads_of(job_id)` again just before `prepare_caches`?
Or add a short comment saying the window is known? I don't think any test
reaches the `provide_input` branch yet either.
##########
ballista/scheduler/src/state/cache_linker.rs:
##########
@@ -694,6 +784,61 @@ impl<T: 'static + AsLogicalPlan, U: 'static +
AsExecutionPlan> SchedulerState<T,
}
}
+ /// Drops the `DataFrame::cache()` data of `session_id`, which is being
+ /// removed. Its built caches are gone at once for new queries, and their
+ /// data is cleaned up once no running query reads it. Its builds still in
+ /// flight are cancelled, and what waits on them fails. Using the session
+ /// again builds its caches anew.
+ pub(crate) async fn remove_session_caches(
+ &self,
+ session_id: &str,
+ sender: &EventSender<QueryStageSchedulerEvent>,
+ ) -> Result<()> {
+ // First, so a query reading one of these caches that loses it from now
+ // on fails rather than rebuild it for the removed session.
+ self.cache_linker.close_session_reads(session_id);
+ // A build fails with what waits on it, held builds included, so look
+ // again each time rather than walk a list taken up front.
+ //
+ // A submission on this session between claiming a build (`track`) and
+ // holding it (`register`) has its claim given back and its build job
+ // cancelled before that job is queued. The submission then submits the
+ // build anyway, whose output is cleaned up as an unclaimed job's, and
+ // its query fails with a cache-miss error asking for a retry. A narrow
+ // race, left as is.
+ while let Some((build, key)) =
self.cache_linker.inflight_of(session_id) {
+ match self.cache_linker.cancel(&build) {
+ Some(held) => self.fail_pending(&held, SESSION_CLOSED,
sender).await,
+ None => {
+ self.fail_cache_job(&build, Some(&key), SESSION_CLOSED,
sender)
+ .await;
+ let event =
QueryStageSchedulerEvent::JobCancel(build.clone());
Review Comment:
Quick question. The builds cancelled by session removal go through
`JobCancel`. Will they show up as user-cancelled jobs in the metrics and the
UI? Totally fine if so, just checking that's expected.
--
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]