Skip to content

Make BSA stage transitions and retries explicit - #3302

Open
CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:bsa-explicit-stage-fsm
Open

CydeWeys wants to merge 1 commit into
google:masterfrom
CydeWeys:bsa-explicit-stage-fsm

Conversation

@CydeWeys

@CydeWeys CydeWeys commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

BSA download and refresh pipelines currently rely on ordinal Enum.compareTo checks for stage advancement, silently discard updated schedule state mid-run, miscompute maxNopInterval on retried downloads, ignore non-2xx daily upload failures, and retry permanent 4xx HTTP responses as if they were transient. These gaps allow illegal transitions such as DONE -> NOP and stage skips, risk wiping previous completed download metadata, hide failed daily uploads behind success notifications, and burn retry budgets under the global BSA lock on permanent client errors.

Replacing ordinal comparisons with explicit transition tables and fixing the state-handling and HTTP classification bugs ensures every BSA stage transition is validated, stale schedule handles cannot overwrite a concurrent worker's progress, metadata and checksums stay consistent across download stages, failed daily uploads surface immediately, and permanent 4xx responses fail fast without starving retries.

Changes

  • Replace ordinal Enum.compareTo checks in DownloadSchedule and RefreshSchedule with explicit ImmutableMultimap allowed-transition tables, forbid DONE -> NOP and illegal stage skips, verify the persisted DB stage still matches this.stage() to reject stale schedule handles, fix the swapped format arguments in transition verification messages, and preserve latestCompleted and alwaysDownload when returning updated schedules.
  • Capture returned schedules across stage transitions in BsaDownloadAction and BsaRefreshAction so in-memory stage and metadata stay synchronized with persisted state.
  • Fix DownloadScheduler to evaluate maxNopInterval against the previous completed job rather than the in-progress job when resuming downloads.
  • Inspect HTTP response status via Response.isSuccessful() in UploadBsaUnavailableDomainsAction so non-2xx responses fail and report errors (sanitizing CR/LF characters before logging at SEVERE), and move ReservedList.loadReservedLists outside replicaTm().transact(...) to avoid nesting primary tm() cache-miss transactions inside replica transactions.
  • Classify HTTP status codes in BsaException.isRetriableHttpStatus (retrying 408, 429, and 5xx while failing fast on permanent 4xx and unexpected status codes) across BsaReportSender, BlockListFetcher, and BsaCredential, guard getResponseMessage() against IOException across all three clients and disconnect in a finally block in BlockListFetcher.tryFetch, sanitize CR/LF characters when logging BSA report responses to prevent log injection, and log non-retriable BsaExceptions at SEVERE in BsaDownloadAction and BsaRefreshAction.
  • Add unit and functional tests covering all legal/illegal stage transitions, stale schedule rejection, metadata preservation, resumed maxNopInterval checks, non-2xx daily uploads, non-nested reserved-list loading, 4xx vs 5xx retry classification, BlockListFetcher disconnect ordering and cleanup, and log-injection sanitization.

BUG= http://b/591075515


This change is Reviewable

@CydeWeys
CydeWeys force-pushed the bsa-explicit-stage-fsm branch from 6d1ca35 to 8c2de6c Compare November 27, 2026 20:30
@CydeWeys
CydeWeys requested a review from weiminyu December 4, 2026 20:02
@CydeWeys
CydeWeys enabled auto-merge December 4, 2026 20:04
@CydeWeys
CydeWeys force-pushed the bsa-explicit-stage-fsm branch 3 times, most recently from 5503198 to 770023f Compare December 4, 2026 20:33
BSA download and refresh pipelines currently rely on ordinal
Enum.compareTo checks for stage advancement, silently discard updated
schedule state mid-run, miscompute maxNopInterval on retried downloads,
ignore non-2xx daily upload failures, and retry permanent 4xx HTTP
responses as if they were transient. These gaps allow illegal
transitions such as DONE -> NOP and stage skips, risk wiping previous
completed download metadata, hide failed daily uploads behind success
notifications, and burn retry budgets under the global BSA lock on
permanent client errors.

Replacing ordinal comparisons with explicit transition tables and fixing
the state-handling and HTTP classification bugs ensures every BSA stage
transition is validated, stale schedule handles cannot overwrite a
concurrent worker's progress, metadata and checksums stay consistent
across download stages, failed daily uploads surface immediately, and
permanent 4xx responses fail fast without starving retries.

Changes:
- Replace ordinal Enum.compareTo checks in DownloadSchedule and
  RefreshSchedule with explicit ImmutableMultimap allowed-transition
  tables, forbid DONE -> NOP and illegal stage skips, verify the
  persisted DB stage still matches this.stage() to reject stale
  schedule handles, fix the swapped format arguments in transition
  verification messages, and preserve latestCompleted and
  alwaysDownload when returning updated schedules.
- Capture returned schedules across stage transitions in
  BsaDownloadAction and BsaRefreshAction so in-memory stage and metadata
  stay synchronized with persisted state.
- Fix DownloadScheduler to evaluate maxNopInterval against the previous
  completed job rather than the in-progress job when resuming downloads.
- Inspect HTTP response status via Response.isSuccessful() in
  UploadBsaUnavailableDomainsAction so non-2xx responses fail and report
  errors (sanitizing CR/LF characters before logging at SEVERE), and
  move ReservedList.loadReservedLists outside replicaTm().transact(...)
  to avoid nesting primary tm() cache-miss transactions inside replica
  transactions.
- Classify HTTP status codes in BsaException.isRetriableHttpStatus
  (retrying 408, 429, and 5xx while failing fast on permanent 4xx and
  unexpected status codes) across BsaReportSender, BlockListFetcher, and
  BsaCredential, guard getResponseMessage() against IOException across
  all three clients and disconnect in a finally block in
  BlockListFetcher.tryFetch, sanitize CR/LF characters when logging BSA
  report responses to prevent log injection, and log non-retriable
  BsaExceptions at SEVERE in BsaDownloadAction and BsaRefreshAction.
- Add unit and functional tests covering all legal/illegal stage
  transitions, stale schedule rejection, metadata preservation, resumed
  maxNopInterval checks, non-2xx daily uploads, non-nested
  reserved-list loading, 4xx vs 5xx retry classification,
  BlockListFetcher disconnect ordering and cleanup, and log-injection
  sanitization.

BUG= http://b/591075515
@CydeWeys
CydeWeys force-pushed the bsa-explicit-stage-fsm branch from 770023f to a79566a Compare December 4, 2026 20:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants