address ExternalLookup review comments

This commit is contained in:
Nia Weiss 2021-03-29 08:22:41 -04:00
parent e9b92e1cd4
commit c4aad290ed
No known key found for this signature in database
GPG key ID: 895E83409BFDA1BB
6 changed files with 13 additions and 12 deletions

View file

@ -67,7 +67,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) {
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.ExternalDB, "externaldb", "", "external (postgres) database DSN to use for ExternalQuery calls")
flags.StringVar(&srv.Config.ExternalDBDSN, "external-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.")

View file

@ -4042,10 +4042,11 @@ func (e *executor) executeExternalLookup(ctx context.Context, qcx *Qcx, index st
if err != nil {
return ExtractedTable{}, errors.Wrap(err, "translating query result")
}
argRow := qr[0].(*Row)
argRow, ok := qr[0].(*Row)
if !ok {
return ExtractedTable{}, errors.Errorf("argument call result is a %T but expected a row", qr[0])
}
if !argRow.Any() {
// If we attempt to substitute in an empty slice, the substitution will fail.
// Do not attempt to execute the query.
return ExtractedTable{}, nil
}

View file

@ -243,7 +243,7 @@ type HolderConfig struct {
RBFConfig *rbfcfg.Config
AntiEntropyInterval time.Duration
ExternalDB string
ExternalDBDSN string
}
func DefaultHolderConfig() *HolderConfig {
@ -733,10 +733,10 @@ func (h *Holder) Open() error {
h.txf.blueGreenOnIfRunningBlueGreen()
if h.cfg.ExternalDB != "" {
if h.cfg.ExternalDBDSN != "" {
h.Logger.Printf("connecting to external DB")
db, err := sql.Open("postgres", h.cfg.ExternalDB)
db, err := sql.Open("postgres", h.cfg.ExternalDBDSN)
if err != nil {
return errors.Wrap(err, "connecting to external database")
}

View file

@ -403,7 +403,7 @@ func OptServerDisCo(disCo disco.DisCo,
// OptServerExternalDB configures a connection to an external postgres database.
func OptServerExternalDB(dsn string) ServerOption {
return func(s *Server) error {
s.holderConfig.ExternalDB = dsn
s.holderConfig.ExternalDBDSN = dsn
return nil
}
}

View file

@ -223,8 +223,8 @@ type Config struct {
// result combines the history from all nodes.
QueryHistoryLength int `toml:"query-history-length"`
// ExternalDB is an external database to connect to for `ExternalLookup` queries.
ExternalDB string `toml:"external-db"`
// ExternalDBDSN is an external database to connect to for `ExternalLookup` queries.
ExternalDBDSN string `toml:"external-db-dsn"`
}
// MustValidate checks that all ports in a Config are unique and not zero.

View file

@ -429,8 +429,8 @@ func (m *Command) SetupServer() error {
discoOpt,
}
if m.Config.ExternalDB != "" {
serverOptions = append(serverOptions, pilosa.OptServerExternalDB(m.Config.ExternalDB))
if m.Config.ExternalDBDSN != "" {
serverOptions = append(serverOptions, pilosa.OptServerExternalDB(m.Config.ExternalDBDSN))
}
serverOptions = append(serverOptions, m.serverOptions...)