Skip to content

Populate bid pricing details on job creation#4949

Merged
JamesMurkin merged 7 commits into
masterfrom
jobdb_bid_snapshot
Jun 10, 2026
Merged

Populate bid pricing details on job creation#4949
JamesMurkin merged 7 commits into
masterfrom
jobdb_bid_snapshot

Conversation

@JamesMurkin

@JamesMurkin JamesMurkin commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Previously we'd only populate the price as part of the scheduler cycle.

This meant newly created jobs would have an empty price until it was populated as part of the scheduler cycle.

This was previously completely fine, but we plan to have an async scheduling cycle where we can't guarentee the scheduler cycle will have set the price on the jobs before the scheduling sees the jobs

  • This change should mean at all times the jobs in the jobdb that have the same queue/priceband consistently have the prices set
  • This will mean the async scheduling cycle can safely assume job prices are set

The approach chosen was to simply set a price snapshot on the jobdb, it can then use this to get the price, this approach was chosen because:

  • It is simple
  • It leads the way for if we want to be smarter about what jobs we update on snapshot updates
    • Now we have the previous snapshot used on the jobdb, we could compare the diff and only update jobs impacted by the changes. Which would be far more efficient than now - which simply updates all jobs regardless of if the bids change

Previously we'd only populate the price as part of the scheduler cycle.

This meant newly created jobs would have an empty price until it was populated as part of the scheduler cycle.

This was previously completely fine, but we plan to have an async scheduling cycle where we can't guarentee the scheduler cycle will have set the price on the jobs before the scheduling sees the jobs
 - This change should mean at all times the jobs in the jobdb that have the same queue/priceband consistently have the prices set
 - This will mean the async scheduling cycle can safely assume job prices are set

The approach chosen was to simply set a price snapshot on the jobdb, I can then use this to get the price
 - This was chosen because it is simple
 - It leads the way for if we want to be smarter about what jobs we update on snapshot updates
   - Now we have the previous snapshot used on the jobdb, we could compare the diff and only update jobs impacted by the changes. Which would be far more efficient than now - which simply updates all jobs regardless of if the bids change

Signed-off-by: JamesMurkin <jamesmurkin@hotmail.com>
Signed-off-by: JamesMurkin <jamesmurkin@hotmail.com>
@JamesMurkin JamesMurkin marked this pull request as ready for review June 8, 2026 13:21
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR populates bid pricing details on job creation by storing a BidPriceSnapshot in the JobDb and reading from it during NewJob. Previously, jobs had empty prices until the scheduler cycle ran, which will be unsafe for a planned async scheduling model.

  • jobdb.go: Adds bidPriceSnapshot *pricing.BidPriceSnapshot to JobDb and Txn, propagates it through ReadTxn/WriteTxn/DryRunTxn/Clone, and uses it in NewJob to pre-populate bidPricesPool (with a defensive maps.Clone). New GetBidPriceSnapshot/SetBidPriceSnapshot methods allow transactional updates.
  • scheduler.go: After computing updatedBids, the scheduler also calls txn.SetBidPriceSnapshot so existing jobs and the snapshot stay in sync across the same commit.
  • schedulerapp.go: Adds populateInitialBidPrices to seed the snapshot before the scheduler loop starts, and fixes the previously swallowed bidPriceCache.Initialise error to return instead of just logging.

Confidence Score: 5/5

Safe to merge — the change is well-scoped, the snapshot is applied defensively with a map clone, and all new code paths are covered by tests.

The snapshot is stored and committed through the existing transactional model, so there are no new concurrency hazards. The previously swallowed initialisation error is now correctly propagated. NewJob always initialises bidPricesPool to a non-nil empty map when no matching snapshot entry exists, which is the safe default. Tests cover commit/abort semantics and all edge cases for price population.

No files require special attention.

Important Files Changed

Filename Overview
internal/scheduler/jobdb/jobdb.go Adds BidPriceSnapshot to JobDb/Txn, propagates through clone/txn paths, applies to NewJob with defensive map clone — implementation is correct.
internal/scheduler/jobdb/jobdb_test.go New tests cover snapshot commit/abort semantics and all edge cases for NewJob price population — good coverage.
internal/scheduler/scheduler.go Adds SetBidPriceSnapshot call after updating prices in updateJobPrices, keeping snapshot and job state in sync within the same transaction commit.
internal/scheduler/scheduler_test.go Updates expectedJobBid from nil to {} to reflect that NewJob now always initialises bidPricesPool to an empty map rather than leaving it nil.
internal/scheduler/schedulerapp.go Adds populateInitialBidPrices before scheduler.Run() and fixes the previously swallowed Initialise error — both changes are correct.

Sequence Diagram

sequenceDiagram
    participant App as schedulerapp.Run()
    participant PPC as BidPriceProvider
    participant JDB as JobDb
    participant Sched as Scheduler.updateJobPrices()
    participant Recon as reconciliation.NewJob()

    App->>PPC: Initialise()
    App->>PPC: GetBidPrices() [populateInitialBidPrices]
    PPC-->>App: BidPriceSnapshot
    App->>JDB: WriteTxn → SetBidPriceSnapshot → Commit

    loop Scheduler cycle
        Sched->>PPC: GetBidPrices()
        PPC-->>Sched: updatedBids
        Sched->>JDB: txn.Upsert(updatedJobs)
        Sched->>JDB: txn.SetBidPriceSnapshot → Commit
    end

    loop Job reconciliation
        Recon->>JDB: NewJob(queue, priceBand, ...)
        JDB->>JDB: read bidPriceSnapshot.GetPrice(queue, band)
        JDB-->>Recon: "Job{bidPricesPool: clonedPrices}"
    end
Loading

Reviews (5): Last reviewed commit: "Merge branch 'master' into jobdb_bid_sna..." | Re-trigger Greptile

Comment thread internal/scheduler/jobdb/jobdb.go
JamesMurkin and others added 4 commits June 8, 2026 14:59
Signed-off-by: JamesMurkin <jamesmurkin@hotmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Signed-off-by: JamesMurkin <jamesmurkin@hotmail.com>
Signed-off-by: JamesMurkin <jamesmurkin@hotmail.com>
geaere
geaere previously approved these changes Jun 10, 2026
Signed-off-by: JamesMurkin <jamesmurkin@hotmail.com>

# Conflicts:
#	internal/scheduler/schedulerapp.go
@JamesMurkin JamesMurkin merged commit 8d050b6 into master Jun 10, 2026
18 checks passed
@JamesMurkin JamesMurkin deleted the jobdb_bid_snapshot branch June 10, 2026 13:28
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