diff --git a/entity/BUILD.bazel b/entity/BUILD.bazel index 0a562dbb..0bb84766 100644 --- a/entity/BUILD.bazel +++ b/entity/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "build.go", "change_provider.go", "request.go", + "speculation_tree.go", ], importpath = "github.com/uber/submitqueue/entity", visibility = ["//visibility:public"], diff --git a/entity/speculation_tree.go b/entity/speculation_tree.go new file mode 100644 index 00000000..f90a36f9 --- /dev/null +++ b/entity/speculation_tree.go @@ -0,0 +1,37 @@ +package entity + +// SpeculationPathAction defines the possible actions for a speculation path. +type SpeculationPathAction string + +const ( + // SpeculationPathActionUnknown is the default zero value for SpeculationPathAction. + SpeculationPathActionUnknown SpeculationPathAction = "" + // TODO: Add comprehensive list of actions +) + +// SpeculationInfo represents metadata about a single speculation path, including the path through the dependency graph, its current state, and the predicted build score. +type SpeculationInfo struct { + // Path represents the speculation path; which is an ordered list of batches. + Path []string + // Action is a state that this path is in. + Action SpeculationPathAction + // Score is score for this speculation path. + Score float32 +} + +// SpeculationTree represents the set of speculation paths constructed for a batch based on its dependency graph. +type SpeculationTree struct { + // BatchID is the batch for which this speculation tree is constructed. + BatchID string + // Speculations is a list of speculation paths for this batch based on a graph of its + // dependents. + // + // For e.g - Consider batches - queueA/batch/1, queueA/batch/2, queueA/batch/3 + // such that - queueA/batch/2 and queueA/batch/3 depend on queueA/batch/1 + // + // Speculations for queueA/batch/1 - [{Path: []string{"queueA/batch/1"}, State: "scheduled", Score: 0.1}] + // Speculations for queueA/batch/2 - [{Path: []string{"queueA/batch/2"}, State: "scheduled", Score: 0.9}, {Path: []string{"queueA/batch/1", "queueA/batch/2"}, State: "scheduled", Score: 0.3}] + // Speculations for queueA/batch/3 - [{Path: []string{"queueA/batch/3"}, State: "scheduled", Score: 0.9}, {Path: []string{"queueA/batch/1", "queueA/batch/3"}, State: "scheduled", Score: 0.3}] + // + Speculations []SpeculationInfo +} diff --git a/extension/storage/mysql/schema/speculation_tree.sql b/extension/storage/mysql/schema/speculation_tree.sql new file mode 100644 index 00000000..5b1d3a19 --- /dev/null +++ b/extension/storage/mysql/schema/speculation_tree.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS speculation_tree ( + batch_id VARCHAR(255) NOT NULL, + speculations JSON NOT NULL, + PRIMARY KEY (batch_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;