From 9bc1b23b7e9fca369b8a2ef2c592aa2f2216b3a0 Mon Sep 17 00:00:00 2001 From: Nia Weiss Date: Mon, 29 Mar 2021 12:54:29 -0400 Subject: [PATCH] change "External" DB to "Lookup" DB --- ctl/server.go | 4 ++-- executor.go | 4 ++-- executor_test.go | 2 +- holder.go | 20 ++++++++++---------- server.go | 6 +++--- server/config.go | 4 ++-- server/server.go | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ctl/server.go b/ctl/server.go index b43c8d907..6c885d213 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -66,8 +66,8 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { flags.StringVar(&srv.Config.Etcd.ClusterURL, "etcd.cluster-url", srv.Config.Etcd.ClusterURL, "Cluster URL to join.") flags.StringVar(&srv.Config.Etcd.InitCluster, "etcd.initial-cluster", srv.Config.Etcd.InitCluster, "Initial cluster name1=apurl1,name2=apurl2") - // External DB - flags.StringVar(&srv.Config.ExternalDBDSN, "external-db-dsn", "", "external (postgres) database DSN to use for ExternalLookup calls") + // External postgres database for ExternalLookup + flags.StringVar(&srv.Config.LookupDBDSN, "lookup-db-dsn", "", "external (postgres) database DSN to use for ExternalLookup calls") // AntiEntropy flags.DurationVar((*time.Duration)(&srv.Config.AntiEntropy.Interval), "anti-entropy.interval", (time.Duration)(srv.Config.AntiEntropy.Interval), "Interval at which to run anti-entropy routine.") diff --git a/executor.go b/executor.go index c6252c7ba..9cd5cccf9 100644 --- a/executor.go +++ b/executor.go @@ -4007,7 +4007,7 @@ var ( ) func (e *executor) executeExternalLookup(ctx context.Context, qcx *Qcx, index string, c *pql.Call, shards []uint64, opt *execOptions) (res ExtractedTable, err error) { - if e.Holder.externalDB == nil { + if e.Holder.lookupDB == nil { return ExtractedTable{}, errors.New("external DB connection is not configured") } @@ -4057,7 +4057,7 @@ func (e *executor) executeExternalLookup(ctx context.Context, qcx *Qcx, index st arg = argRow.Columns() } - result, err := e.Holder.externalDB.QueryContext(ctx, query, pq.Array(arg)) + result, err := e.Holder.lookupDB.QueryContext(ctx, query, pq.Array(arg)) if err != nil { return ExtractedTable{}, errors.Wrapf(err, "SQL query failed") } diff --git a/executor_test.go b/executor_test.go index 8f2abd09c..48ce5200d 100644 --- a/executor_test.go +++ b/executor_test.go @@ -8020,7 +8020,7 @@ func TestExternalLookup(t *testing.T) { }() // Start up a Pilosa cluster with access to the DB. - c := test.MustRunCluster(t, 3, []server.CommandOption{server.OptCommandServerOptions(pilosa.OptServerExternalDB(dbDSN))}) + c := test.MustRunCluster(t, 3, []server.CommandOption{server.OptCommandServerOptions(pilosa.OptServerLookupDB(dbDSN))}) defer c.Close() // Populate a field with some data that can be used in queries. diff --git a/holder.go b/holder.go index 3f960433f..766d82a7d 100644 --- a/holder.go +++ b/holder.go @@ -151,7 +151,7 @@ type Holder struct { txf *TxFactory - externalDB *sql.DB + lookupDB *sql.DB // a separate lock out for indexes, to avoid the deadlock/race dilema // on holding mu. @@ -243,7 +243,7 @@ type HolderConfig struct { RBFConfig *rbfcfg.Config AntiEntropyInterval time.Duration - ExternalDBDSN string + LookupDBDSN string } func DefaultHolderConfig() *HolderConfig { @@ -733,15 +733,15 @@ func (h *Holder) Open() error { h.txf.blueGreenOnIfRunningBlueGreen() - if h.cfg.ExternalDBDSN != "" { - h.Logger.Printf("connecting to external DB") + if h.cfg.LookupDBDSN != "" { + h.Logger.Printf("connecting to lookup DB") - db, err := sql.Open("postgres", h.cfg.ExternalDBDSN) + db, err := sql.Open("postgres", h.cfg.LookupDBDSN) if err != nil { - return errors.Wrap(err, "connecting to external database") + return errors.Wrap(err, "connecting to lookup database") } - h.externalDB = db + h.lookupDB = db } h.Logger.Printf("open holder: complete") @@ -854,12 +854,12 @@ func (h *Holder) Close() error { h.SnapshotQueue = nil } - if h.externalDB != nil { - err := h.externalDB.Close() + if h.lookupDB != nil { + err := h.lookupDB.Close() if err != nil { return errors.Wrap(err, "closing DB") } - h.externalDB = nil + h.lookupDB = nil } _ = testhook.Closed(h.Auditor, h, nil) diff --git a/server.go b/server.go index 38a77dd39..018d13eec 100644 --- a/server.go +++ b/server.go @@ -400,10 +400,10 @@ func OptServerDisCo(disCo disco.DisCo, } } -// OptServerExternalDB configures a connection to an external postgres database. -func OptServerExternalDB(dsn string) ServerOption { +// OptServerLookupDB configures a connection to an external postgres database for ExternalLookup queries. +func OptServerLookupDB(dsn string) ServerOption { return func(s *Server) error { - s.holderConfig.ExternalDBDSN = dsn + s.holderConfig.LookupDBDSN = dsn return nil } } diff --git a/server/config.go b/server/config.go index 484a4b0f1..074dbdc07 100644 --- a/server/config.go +++ b/server/config.go @@ -223,8 +223,8 @@ type Config struct { // result combines the history from all nodes. QueryHistoryLength int `toml:"query-history-length"` - // ExternalDBDSN is an external database to connect to for `ExternalLookup` queries. - ExternalDBDSN string `toml:"external-db-dsn"` + // LookupDBDSN is an external database to connect to for `ExternalLookup` queries. + LookupDBDSN string `toml:"lookup-db-dsn"` } // MustValidate checks that all ports in a Config are unique and not zero. diff --git a/server/server.go b/server/server.go index 556e7b6b6..58827eca0 100644 --- a/server/server.go +++ b/server/server.go @@ -429,8 +429,8 @@ func (m *Command) SetupServer() error { discoOpt, } - if m.Config.ExternalDBDSN != "" { - serverOptions = append(serverOptions, pilosa.OptServerExternalDB(m.Config.ExternalDBDSN)) + if m.Config.LookupDBDSN != "" { + serverOptions = append(serverOptions, pilosa.OptServerLookupDB(m.Config.LookupDBDSN)) } serverOptions = append(serverOptions, m.serverOptions...)