Skip to content

Commit 8d12dbf

Browse files
committed
feat(orchestrator): support creating batches
Add a pre-processing batch state and make downstream readers safely tolerate batches whose reverse indexes are still being initialized. Jira Issues: CODEM-304
1 parent b0f22d8 commit 8d12dbf

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

submitqueue/entity/batch.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ type BatchState string
2222
const (
2323
// BatchStateUnknown is the unreachable state. It is set by default when the structure is initialized. It should never be seen in the system.
2424
BatchStateUnknown BatchState = ""
25-
// BatchStateCreated is the state of a batch that has been created for processing.
25+
// BatchStateCreating indicates that the batch has been persisted but its dependency reverse indexes may not yet be fully initialized.
26+
// A Creating batch is not eligible to be referenced as a dependency.
27+
BatchStateCreating BatchState = "creating"
28+
// BatchStateCreated indicates that the batch and its dependency reverse indexes are fully initialized and ready for processing.
2629
BatchStateCreated BatchState = "created"
2730
// BatchStateSpeculating is the state of a batch that is undergoing speculative execution.
2831
BatchStateSpeculating BatchState = "speculating"
@@ -67,9 +70,8 @@ func IsBatchStateHalted(s BatchState) bool {
6770
return s.IsTerminal() || s == BatchStateCancelling
6871
}
6972

70-
// ActiveBatchStates returns every non-terminal batch state that must be considered in-flight.
71-
// Use this when callers need to find batches that still own a request, including Cancelling
72-
// batches that cancel redelivery must be able to resolve.
73+
// ActiveBatchStates returns batch states eligible for active pipeline and cancellation lookups.
74+
// Creating is excluded because its reverse-index structure may still be incomplete.
7375
func ActiveBatchStates() []BatchState {
7476
return []BatchState{
7577
BatchStateCreated,

submitqueue/entity/batch_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestBatchState_IsTerminal(t *testing.T) {
2828
terminal bool
2929
}{
3030
{name: "unknown", state: BatchStateUnknown, terminal: false},
31+
{name: "creating", state: BatchStateCreating, terminal: false},
3132
{name: "created", state: BatchStateCreated, terminal: false},
3233
{name: "speculating", state: BatchStateSpeculating, terminal: false},
3334
{name: "merging", state: BatchStateMerging, terminal: false},
@@ -44,6 +45,14 @@ func TestBatchState_IsTerminal(t *testing.T) {
4445
}
4546
}
4647

48+
func TestActiveBatchStates_ExcludesCreating(t *testing.T) {
49+
assert.NotContains(t, ActiveBatchStates(), BatchStateCreating)
50+
}
51+
52+
func TestDependencyBatchStates_ExcludesCreating(t *testing.T) {
53+
assert.NotContains(t, DependencyBatchStates(), BatchStateCreating)
54+
}
55+
4756
func TestBatch_SerializationRoundTrip(t *testing.T) {
4857
tests := []struct {
4958
name string

submitqueue/extension/storage/batch_dependent_store.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@ import (
2525
// BatchDependentStore is an interface that defines methods for managing batch dependent information in the database.
2626
//
2727
// A BatchDependent is a reverse index ("batches that depend on me") paired one-to-one with a Batch.
28-
// The batch-creation flow always calls Create here before creating the Batch itself, so every active
29-
// Batch is guaranteed to have a corresponding BatchDependent row. Lookups via Get are only performed
30-
// for batch IDs returned from the active-batch set, meaning a missing row indicates data corruption or
31-
// out-of-band manipulation rather than a normal "not found" outcome. ErrNotFound is therefore part of
32-
// the contract for completeness but is not expected to be returned in steady-state operation.
28+
// The batch-creation flow creates this row while the Batch is Creating and before making the Batch eligible for pipeline processing.
29+
// A Creating Batch can briefly exist without its row; every Batch that reaches Created is guaranteed to have one.
3330
type BatchDependentStore interface {
3431
// Get retrieves the batch dependent by batch ID.
3532
// If the batch contains no dependents, the returned BatchDependent will have an empty Dependents list.
36-
// Returns ErrNotFound if the batch itself is not found, which should never happen in steady-state system and
37-
// therefore does not need a special handling.
33+
// Returns ErrNotFound if no reverse-index row exists for the batch.
3834
Get(ctx context.Context, batchID string) (entity.BatchDependent, error)
3935

4036
// Create creates a new batch dependent.

0 commit comments

Comments
 (0)