-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server,autoconfig: automatic configuration via config tasks
This change introduces "auto config tasks", a mechanism through which configuration payloads ("tasks") can be injected into a running SQL service. This is driven via the "auto config runner" job that was introduced in the previous commit. The job listens for the arrival of new environment/task definitions via a `Provider` interface. When new environments are known, it spans "env runner" jobs; each waiting for its own tasks. When new tasks are known, and previous tasks have completed, the "env runner" job creates a new separate job for the first next task. Release note: None
- Loading branch information
Showing
27 changed files
with
1,651 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "acprovider", | ||
srcs = ["provider.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/server/autoconfig/acprovider", | ||
visibility = ["//visibility:public"], | ||
deps = ["//pkg/server/autoconfig/autoconfigpb"], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package acprovider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/server/autoconfig/autoconfigpb" | ||
) | ||
|
||
// Provider is an interface through which the auto config runner | ||
// can receive new tasks to run. | ||
// For more details, see the package-level documentation for | ||
// package "autoconfig". | ||
type Provider interface { | ||
// EnvUpdate returns a channel that receives a message any time the | ||
// current set of environments change. The channel receives an | ||
// initial event immediately. | ||
EnvUpdate() <-chan struct{} | ||
|
||
// ActiveEnvironments returns the IDs of environments that have | ||
// tasks available for execution. | ||
ActiveEnvironments() []autoconfigpb.EnvironmentID | ||
|
||
// Peek will block waiting for the first task the provider believes | ||
// still needs to be run for the given environment. It will return | ||
// an error if the context is canceled while waiting. It will | ||
// return ErrNoMoreTasks to indicate the caller does not need | ||
// to process tasks for this environment any more. | ||
Peek(ctx context.Context, env autoconfigpb.EnvironmentID) (autoconfigpb.Task, error) | ||
|
||
// Pop will report the completion of all tasks with ID up to | ||
// completed for the given environment. | ||
Pop(ctx context.Context, env autoconfigpb.EnvironmentID, completed autoconfigpb.TaskID) error | ||
} | ||
|
||
type errNoMoreTasks struct{} | ||
|
||
func (errNoMoreTasks) Error() string { return "no more tasks" } | ||
|
||
// ErrNoMoreTasks can be checked with errors.Is on the result of Peek | ||
// when an environment is not providing tasks for the foreseeable future. | ||
var ErrNoMoreTasks error = errNoMoreTasks{} | ||
|
||
// NoTaskProvider is a stub provider which delivers no tasks. | ||
type NoTaskProvider struct{} | ||
|
||
var _ Provider = NoTaskProvider{} | ||
|
||
// EnvUpdate is part of the Provider interface. | ||
func (NoTaskProvider) EnvUpdate() <-chan struct{} { | ||
ch := make(chan struct{}, 1) | ||
ch <- struct{}{} | ||
return ch | ||
} | ||
|
||
// ActiveEnvironments is part of the Provider interface. | ||
func (NoTaskProvider) ActiveEnvironments() []autoconfigpb.EnvironmentID { return nil } | ||
|
||
// Peek is part of the Provider interface. | ||
func (NoTaskProvider) Peek( | ||
ctx context.Context, _ autoconfigpb.EnvironmentID, | ||
) (autoconfigpb.Task, error) { | ||
return autoconfigpb.Task{}, ErrNoMoreTasks | ||
} | ||
|
||
// Pop is part of the Provider interface. | ||
func (NoTaskProvider) Pop(context.Context, autoconfigpb.EnvironmentID, autoconfigpb.TaskID) error { | ||
return nil | ||
} |
Oops, something went wrong.