featurebase/dax/controller/config.go
Matthew Jaffee 8fe73146c8
Sqldb rip boltdb (#2341)
* serverless sqldb use same env for test config as normal

* rip boltdb implementation of controller backend out

it was replaced by postgres and no longer works properly.

This involved migrating a number of tests which only worked with
boltdb, which exposed several ways in which the postgres
implementation had slightly different behavior from the bolt
one:
1. ordering of results in some cases, and
2. (more importantly) erroring when a record to delete was not
found. The bolt implementation silently ignored it when things to
delete weren't found, so we make some changes to match that behavior.

Also stopped propagating CreatedAt and UpdatedAt from DB tables into
dax types. These were breaking existing tests. Perhaps it would be
better to actually use them, but for now they will only exist at the
DB level.

This change set also moves the insertion of the directive_versions
record out of migrations and into the startup/connection code. Having
this in the migrations was a bit ugly because you couldn't just
truncate all the tables and have everything work from
scratch. Inserting it during startup is fairly innocuous, and will
just continue on if it already exists.

* update directive_version test

I changed the initial value to 0 so that the first version that gets
sent out is 1
2023-03-22 08:54:13 -05:00

81 lines
2.6 KiB
Go

package controller
import (
"time"
"github.com/featurebasedb/featurebase/v3/logger"
)
type NewBalancerFn func(string, logger.Logger) Balancer
// TODO honestly, I think a lot of this stuff should be moved into the
// service package. It's config for specific implementations of things
// that are going to be injected into the controller.
type Config struct {
Director Director
// Poller
PollInterval time.Duration `toml:"poll-interval"`
// Storage
StorageMethod string `toml:"storage-method"`
SQLDB *SQLDBConfig `toml:"sqldb"`
SnapshotterDir string `toml:"snapshotter-dir"`
WriteloggerDir string `toml:"writelogger-dir"`
// RegistrationBatchTimeout is the time that the controller will
// wait after a node registers itself to see if any more nodes
// will register before sending out directives to all nodes which
// have been registered.
RegistrationBatchTimeout time.Duration
// SnappingTurtleTimeout is the period on which the automatic
// snapshotting routine will run. If performing all the snapshots
// takes longer than this amount of time, snapshotting will run
// continuously. If it finishes before the timeout, it will wait
// until the timeout expires to start another round of snapshots.
SnappingTurtleTimeout time.Duration
Logger logger.Logger `toml:"-"`
}
type SQLDBConfig struct {
// Dialect is the pop dialect to use. Example: "postgres" or "sqlite3" or "mysql"
Dialect string
// The name of your database. Example: "foo_development"
Database string
// The host of your database. Example: "127.0.0.1"
Host string
// The port of your database. Example: 1234
// Will default to the "default" port for each dialect.
Port string
// The username of the database user. Example: "root"
User string
// The password of the database user. Example: "password"
Password string
// Instead of specifying each individual piece of the
// connection you can instead just specify the URL of the
// database. Example: "postgres://postgres:postgres@localhost:5432/pop_test?sslmode=disable"
URL string
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetMaxOpenConns
Pool int
// Defaults to 2. See https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns
IdlePool int
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime
ConnMaxLifetime time.Duration
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime
ConnMaxIdleTime time.Duration
}
func NewSQLDBConfig() *SQLDBConfig {
return &SQLDBConfig{
Dialect: "postgres",
Database: "controller",
Host: "127.0.0.1",
Pool: 0,
IdlePool: 2,
}
}