mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 20:07:51 +00:00
Switch Serverless from using BoltDB to Postgres as metadata store. Previously, the controller stored all metadata to BoltDB. This implements SQLDB (currently Postgres flavored) as the backing store for metadata. This will allow us to have multiple instances of the controller running for HA, and to easily inspect and repair the contents of the metadata store. Unfortunately, it was not straightforward to keep the BoltDB implementation working alongside the SQL one, so it will be removed in a later patch. Once that's done, the SQL implementation should allow for a number of simplifications of the schemar and balancer interfaces. Database migration is built directly into the application by embedding the migration files and logic from the `soda` command line tool. When connecting to the RDBMS, the app will always attempt to create the necessary database and apply any outstanding migrations. Integration tests truncate all tables upon start, but *not* at the end, so the state of the database can be inspected after integration tests. Had to refactor some of the controller's background tasks to make sure they get properly shut down on controller exit.
82 lines
2.6 KiB
Go
82 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"`
|
|
DataDir string `toml:"-"`
|
|
|
|
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,
|
|
}
|
|
}
|