Skip to content

Commit bfcec56

Browse files
committed
fix: Return to pending if paused execution receives a response and unpauses
1 parent 78f5ed0 commit bfcec56

4 files changed

Lines changed: 387 additions & 17 deletions

File tree

crates/concepts/src/storage.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,61 @@ pub enum PendingState {
16611661
Finished(PendingStateFinished),
16621662
}
16631663

1664+
pub enum PendingStateMergedPause {
1665+
Locked {
1666+
state: PendingStateLocked,
1667+
paused: bool,
1668+
},
1669+
PendingAt {
1670+
state: PendingStatePendingAt,
1671+
paused: bool,
1672+
},
1673+
BlockedByJoinSet {
1674+
state: PendingStateBlockedByJoinSet,
1675+
paused: bool,
1676+
},
1677+
Finished(PendingStateFinished),
1678+
}
1679+
impl From<PendingState> for PendingStateMergedPause {
1680+
fn from(state: PendingState) -> Self {
1681+
match state {
1682+
PendingState::Locked(s) => PendingStateMergedPause::Locked {
1683+
state: s,
1684+
paused: false,
1685+
},
1686+
1687+
PendingState::PendingAt(s) => PendingStateMergedPause::PendingAt {
1688+
state: s,
1689+
paused: false,
1690+
},
1691+
1692+
PendingState::BlockedByJoinSet(s) => PendingStateMergedPause::BlockedByJoinSet {
1693+
state: s,
1694+
paused: false,
1695+
},
1696+
1697+
PendingState::Paused(paused) => match paused {
1698+
PendingStatePaused::Locked(s) => PendingStateMergedPause::Locked {
1699+
state: s,
1700+
paused: true,
1701+
},
1702+
PendingStatePaused::PendingAt(s) => PendingStateMergedPause::PendingAt {
1703+
state: s,
1704+
paused: true,
1705+
},
1706+
PendingStatePaused::BlockedByJoinSet(s) => {
1707+
PendingStateMergedPause::BlockedByJoinSet {
1708+
state: s,
1709+
paused: true,
1710+
}
1711+
}
1712+
},
1713+
1714+
PendingState::Finished(s) => PendingStateMergedPause::Finished(s),
1715+
}
1716+
}
1717+
}
1718+
16641719
#[derive(Debug, Clone, derive_more::Display, PartialEq, Eq, Serialize)]
16651720
#[display("Locked(`{lock_expires_at}`, {}, {})", locked_by.executor_id, locked_by.run_id)]
16661721
pub struct PendingStateLocked {

crates/db-postgres/src/postgres_dao.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use concepts::{
1818
ListLogsResponse, LockPendingResponse, Locked, LockedBy, LockedExecution, LogEntry,
1919
LogEntryRow, LogFilter, LogInfoAppendRow, LogLevel, LogStreamType, Pagination,
2020
PendingState, PendingStateBlockedByJoinSet, PendingStateFinished,
21-
PendingStateFinishedResultKind, PendingStateLocked, PendingStatePaused,
22-
PendingStatePendingAt, ResponseCursor, ResponseWithCursor, STATE_BLOCKED_BY_JOIN_SET,
23-
STATE_FINISHED, STATE_LOCKED, STATE_PENDING_AT, TimeoutOutcome, Version, VersionType,
24-
WasmBacktrace,
21+
PendingStateFinishedResultKind, PendingStateLocked, PendingStateMergedPause,
22+
PendingStatePaused, PendingStatePendingAt, ResponseCursor, ResponseWithCursor,
23+
STATE_BLOCKED_BY_JOIN_SET, STATE_FINISHED, STATE_LOCKED, STATE_PENDING_AT, TimeoutOutcome,
24+
Version, VersionType, WasmBacktrace,
2525
},
2626
};
2727
use deadpool_postgres::{Client, ManagerConfig, Pool, RecyclingMethod};
@@ -2830,11 +2830,16 @@ async fn append_response(
28302830
let combined_state = get_combined_state(tx, execution_id).await?;
28312831
debug!("previous_pending_state: {combined_state:?}");
28322832

2833-
let mut notifier = if let PendingState::BlockedByJoinSet(PendingStateBlockedByJoinSet {
2834-
join_set_id: found_join_set_id,
2835-
lock_expires_at,
2836-
closing: _,
2837-
}) = combined_state.execution_with_state.pending_state
2833+
let mut notifier = if let PendingStateMergedPause::BlockedByJoinSet {
2834+
state:
2835+
PendingStateBlockedByJoinSet {
2836+
join_set_id: found_join_set_id,
2837+
lock_expires_at, // Set to a future time if the worker is keeping the execution warm waiting for the result.
2838+
closing: _,
2839+
},
2840+
paused: _,
2841+
} =
2842+
PendingStateMergedPause::from(combined_state.execution_with_state.pending_state)
28382843
&& *join_set_id == found_join_set_id
28392844
{
28402845
let scheduled_at = std::cmp::max(lock_expires_at, event.created_at);

crates/db-sqlite/src/sqlite_dao.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ use concepts::{
1818
ListLogsResponse, LockPendingResponse, Locked, LockedBy, LockedExecution, LogEntry,
1919
LogEntryRow, LogFilter, LogInfoAppendRow, LogLevel, LogStreamType, Pagination,
2020
PendingState, PendingStateBlockedByJoinSet, PendingStateFinished,
21-
PendingStateFinishedResultKind, PendingStateLocked, PendingStatePaused,
22-
PendingStatePendingAt, ResponseCursor, ResponseWithCursor, STATE_BLOCKED_BY_JOIN_SET,
23-
STATE_FINISHED, STATE_LOCKED, STATE_PENDING_AT, TimeoutOutcome, Version, VersionType,
21+
PendingStateFinishedResultKind, PendingStateLocked, PendingStateMergedPause,
22+
PendingStatePaused, PendingStatePendingAt, ResponseCursor, ResponseWithCursor,
23+
STATE_BLOCKED_BY_JOIN_SET, STATE_FINISHED, STATE_LOCKED, STATE_PENDING_AT, TimeoutOutcome,
24+
Version, VersionType,
2425
},
2526
};
2627
use const_format::formatcp;
@@ -2928,11 +2929,16 @@ impl SqlitePool {
29282929
// if the execution is going to be unblocked by this response...
29292930
let combined_state = Self::get_combined_state(tx, execution_id)?;
29302931
debug!("previous_pending_state: {combined_state:?}");
2931-
let mut notifier = if let PendingState::BlockedByJoinSet(PendingStateBlockedByJoinSet {
2932-
join_set_id: found_join_set_id,
2933-
lock_expires_at, // Set to a future time if the worker is keeping the execution warm waiting for the result.
2934-
closing: _,
2935-
}) = combined_state.execution_with_state.pending_state
2932+
let mut notifier = if let PendingStateMergedPause::BlockedByJoinSet {
2933+
state:
2934+
PendingStateBlockedByJoinSet {
2935+
join_set_id: found_join_set_id,
2936+
lock_expires_at, // Set to a future time if the worker is keeping the execution warm waiting for the result.
2937+
closing: _,
2938+
},
2939+
paused: _,
2940+
} =
2941+
PendingStateMergedPause::from(combined_state.execution_with_state.pending_state)
29362942
&& *join_set_id == found_join_set_id
29372943
{
29382944
// PendingAt should be set to current time if called from expired_timers_watcher,

0 commit comments

Comments
 (0)