mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: remove dbmem (#18803)
Remove the in-memory database. Addresses #15109.
This commit is contained in:
+30
-36
@@ -77,7 +77,6 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/awsiamrds"
|
||||
"github.com/coder/coder/v2/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/v2/coderd/database/dbmem"
|
||||
"github.com/coder/coder/v2/coderd/database/dbmetrics"
|
||||
"github.com/coder/coder/v2/coderd/database/dbpurge"
|
||||
"github.com/coder/coder/v2/coderd/database/migrations"
|
||||
@@ -423,7 +422,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
|
||||
|
||||
builtinPostgres := false
|
||||
// Only use built-in if PostgreSQL URL isn't specified!
|
||||
if !vals.InMemoryDatabase && vals.PostgresURL == "" {
|
||||
if vals.PostgresURL == "" {
|
||||
var closeFunc func() error
|
||||
cliui.Infof(inv.Stdout, "Using built-in PostgreSQL (%s)", config.PostgresPath())
|
||||
customPostgresCacheDir := ""
|
||||
@@ -726,42 +725,37 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
|
||||
// nil, that case of the select will just never fire, but it's important not to have a
|
||||
// "bare" read on this channel.
|
||||
var pubsubWatchdogTimeout <-chan struct{}
|
||||
if vals.InMemoryDatabase {
|
||||
// This is only used for testing.
|
||||
options.Database = dbmem.New()
|
||||
options.Pubsub = pubsub.NewInMemory()
|
||||
} else {
|
||||
sqlDB, dbURL, err := getAndMigratePostgresDB(ctx, logger, vals.PostgresURL.String(), codersdk.PostgresAuth(vals.PostgresAuth), sqlDriver)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("connect to postgres: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = sqlDB.Close()
|
||||
}()
|
||||
|
||||
if options.DeploymentValues.Prometheus.Enable {
|
||||
// At this stage we don't think the database name serves much purpose in these metrics.
|
||||
// It requires parsing the DSN to determine it, which requires pulling in another dependency
|
||||
// (i.e. https://github.com/jackc/pgx), but it's rather heavy.
|
||||
// The conn string (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) can
|
||||
// take different forms, which make parsing non-trivial.
|
||||
options.PrometheusRegistry.MustRegister(collectors.NewDBStatsCollector(sqlDB, ""))
|
||||
}
|
||||
|
||||
options.Database = database.New(sqlDB)
|
||||
ps, err := pubsub.New(ctx, logger.Named("pubsub"), sqlDB, dbURL)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("create pubsub: %w", err)
|
||||
}
|
||||
options.Pubsub = ps
|
||||
if options.DeploymentValues.Prometheus.Enable {
|
||||
options.PrometheusRegistry.MustRegister(ps)
|
||||
}
|
||||
defer options.Pubsub.Close()
|
||||
psWatchdog := pubsub.NewWatchdog(ctx, logger.Named("pswatch"), ps)
|
||||
pubsubWatchdogTimeout = psWatchdog.Timeout()
|
||||
defer psWatchdog.Close()
|
||||
sqlDB, dbURL, err := getAndMigratePostgresDB(ctx, logger, vals.PostgresURL.String(), codersdk.PostgresAuth(vals.PostgresAuth), sqlDriver)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("connect to postgres: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = sqlDB.Close()
|
||||
}()
|
||||
|
||||
if options.DeploymentValues.Prometheus.Enable {
|
||||
// At this stage we don't think the database name serves much purpose in these metrics.
|
||||
// It requires parsing the DSN to determine it, which requires pulling in another dependency
|
||||
// (i.e. https://github.com/jackc/pgx), but it's rather heavy.
|
||||
// The conn string (https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) can
|
||||
// take different forms, which make parsing non-trivial.
|
||||
options.PrometheusRegistry.MustRegister(collectors.NewDBStatsCollector(sqlDB, ""))
|
||||
}
|
||||
|
||||
options.Database = database.New(sqlDB)
|
||||
ps, err := pubsub.New(ctx, logger.Named("pubsub"), sqlDB, dbURL)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("create pubsub: %w", err)
|
||||
}
|
||||
options.Pubsub = ps
|
||||
if options.DeploymentValues.Prometheus.Enable {
|
||||
options.PrometheusRegistry.MustRegister(ps)
|
||||
}
|
||||
defer options.Pubsub.Close()
|
||||
psWatchdog := pubsub.NewWatchdog(ctx, logger.Named("pswatch"), ps)
|
||||
pubsubWatchdogTimeout = psWatchdog.Timeout()
|
||||
defer psWatchdog.Close()
|
||||
|
||||
if options.DeploymentValues.Prometheus.Enable && options.DeploymentValues.Prometheus.CollectDBMetrics {
|
||||
options.Database = dbmetrics.NewQueryMetrics(options.Database, options.Logger, options.PrometheusRegistry)
|
||||
|
||||
@@ -59,9 +59,6 @@ import (
|
||||
)
|
||||
|
||||
func dbArg(t *testing.T) string {
|
||||
if !dbtestutil.WillUsePostgres() {
|
||||
return "--in-memory"
|
||||
}
|
||||
dbURL, err := dbtestutil.Open(t)
|
||||
require.NoError(t, err)
|
||||
return "--postgres-url=" + dbURL
|
||||
|
||||
-3
@@ -462,9 +462,6 @@ enableSwagger: false
|
||||
# to be configured as a shared directory across coderd/provisionerd replicas.
|
||||
# (default: [cache dir], type: string)
|
||||
cacheDir: [cache dir]
|
||||
# Controls whether data will be stored in an in-memory database.
|
||||
# (default: <unset>, type: bool)
|
||||
inMemoryDatabase: false
|
||||
# Controls whether Coder data, including built-in Postgres, will be stored in a
|
||||
# temporary directory and deleted when the server is stopped.
|
||||
# (default: <unset>, type: bool)
|
||||
|
||||
Reference in New Issue
Block a user