mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
added sqlversion config option
This commit is contained in:
parent
2ca7b107d2
commit
5176b7ff03
6 changed files with 26 additions and 14 deletions
|
|
@ -111,6 +111,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) {
|
|||
flags.DurationVar((*time.Duration)(&srv.Config.Postgres.WriteTimeout), "postgres.write-timeout", time.Duration(srv.Config.Postgres.WriteTimeout), "Timeout for writes on a postgres connection. (set 0 to disable)")
|
||||
flags.Uint32Var(&srv.Config.Postgres.MaxStartupSize, "postgres.max-startup-size", srv.Config.Postgres.MaxStartupSize, "Maximum acceptable size of a postgres startup packet, in bytes. (set 0 to disable)")
|
||||
flags.Uint16Var(&srv.Config.Postgres.ConnectionLimit, "postgres.connection-limit", srv.Config.Postgres.ConnectionLimit, "Maximum number of simultaneous postgres connections to allow. (set 0 to disable)")
|
||||
flags.Uint16Var(&srv.Config.Postgres.SqlVersion, "postgres.sql-version", srv.Config.Postgres.SqlVersion, "Molecula Sql Handling Version (default 1)")
|
||||
|
||||
// Disk and Memory usage cache for ui/usage endpoint
|
||||
flags.Float64Var(&srv.Config.UsageDutyCycle, "usage-duty-cycle", srv.Config.UsageDutyCycle, "Sets the percentage of time that is spent recalculating the disk and memory usage cache. 100.0 for always-running, 0 disables the cache and the /ui/usage endpoint.")
|
||||
|
|
|
|||
4
go.mod
4
go.mod
|
|
@ -29,7 +29,7 @@ require (
|
|||
github.com/molecula/apophenia v0.0.0-20190827192002-68b7a14a478b
|
||||
github.com/opentracing/opentracing-go v1.1.0
|
||||
github.com/pelletier/go-toml v1.4.0
|
||||
github.com/pilosa/pilosa/v2 v2.0.0-alpha.1
|
||||
github.com/pilosa/pilosa/v2 v2.0.0-alpha.1 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.0.0
|
||||
github.com/prometheus/client_model v0.1.0
|
||||
|
|
@ -55,7 +55,7 @@ require (
|
|||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
|
||||
golang.org/x/text v0.3.5 // indirect
|
||||
google.golang.org/grpc v1.28.0
|
||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
modernc.org/mathutil v1.0.0
|
||||
modernc.org/strutil v1.0.0
|
||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||
|
|
|
|||
|
|
@ -1043,7 +1043,7 @@ func (s *Server) handleQuery(w message.Writer, query Query, cancelNotify <-chan
|
|||
te: s.TypeEngine,
|
||||
tag: "SELECT",
|
||||
}
|
||||
|
||||
vprint.VV("handle Query: (%v)", query)
|
||||
// Dispatch the query handler.
|
||||
qerr := s.QueryHandler.HandleQuery(ctx, qwriter, query)
|
||||
if qerr != nil {
|
||||
|
|
|
|||
|
|
@ -200,6 +200,9 @@ type Config struct {
|
|||
// Setting this to 0 disables the limit.
|
||||
// This mostly exists because other DBs seem to have it.
|
||||
ConnectionLimit uint16 `toml:"max-connections"`
|
||||
// SqlVersion is which type of sqlhandling to be applied.
|
||||
// The constant SqlV2 can be used to try the new experimental Molecula SQL handling
|
||||
SqlVersion uint16 `toml:"sql-version"`
|
||||
} `toml:"postgres"`
|
||||
|
||||
// Storage.Backend determines which Tx implementation the holder/Index will
|
||||
|
|
|
|||
26
server/pg.go
26
server/pg.go
|
|
@ -46,14 +46,20 @@ type PostgresServer struct {
|
|||
s pg.Server
|
||||
stop context.CancelFunc
|
||||
}
|
||||
type SqlVersion uint16
|
||||
|
||||
const (
|
||||
SqlV1 SqlVersion = 0
|
||||
SqlV2 SqlVersion = 2
|
||||
)
|
||||
|
||||
// NewPostgresServer creates a postgres server.
|
||||
func NewPostgresServer(api *pilosa.API, logger logger.Logger, tls *tls.Config) *PostgresServer {
|
||||
func NewPostgresServer(api *pilosa.API, logger logger.Logger, tls *tls.Config, sqlVersion SqlVersion) *PostgresServer {
|
||||
return &PostgresServer{
|
||||
api: api,
|
||||
logger: logger,
|
||||
s: pg.Server{
|
||||
QueryHandler: NewPostgresHandler(api, logger),
|
||||
QueryHandler: NewPostgresHandler(api, logger, sqlVersion),
|
||||
TypeEngine: pg.PrimitiveTypeEngine{},
|
||||
StartupTimeout: 5 * time.Second,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
|
|
@ -69,11 +75,12 @@ func NewPostgresServer(api *pilosa.API, logger logger.Logger, tls *tls.Config) *
|
|||
}
|
||||
|
||||
// NewPostgresHandler creates a postgres query handler wrapping the pilosa API.
|
||||
func NewPostgresHandler(api *pilosa.API, logger logger.Logger) pg.QueryHandler {
|
||||
func NewPostgresHandler(api *pilosa.API, logger logger.Logger, sqlVersion SqlVersion) pg.QueryHandler {
|
||||
return &QueryDecodeHandler{
|
||||
Child: &PilosaQueryHandler{
|
||||
Api: api,
|
||||
logger: logger,
|
||||
Api: api,
|
||||
logger: logger,
|
||||
sqlVersion: sqlVersion,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -143,8 +150,9 @@ func pgDecodePQL(str string) (q pg.Query, err error) {
|
|||
}
|
||||
|
||||
type PilosaQueryHandler struct {
|
||||
Api *pilosa.API
|
||||
logger logger.Logger
|
||||
Api *pilosa.API
|
||||
logger logger.Logger
|
||||
sqlVersion SqlVersion
|
||||
}
|
||||
|
||||
func pgWriteRow(w pg.QueryResultWriter, row *pilosa.Row) error {
|
||||
|
|
@ -549,9 +557,9 @@ func (pqh *PilosaQueryHandler) HandleQuery(ctx context.Context, w pg.QueryResult
|
|||
return errors.Wrap(pgWriteResult(w, resp.Results[0]), "writing query result")
|
||||
|
||||
case pg.SimpleQuery:
|
||||
sql2 := true
|
||||
if sql2 {
|
||||
if pqh.sqlVersion == SqlV2 {
|
||||
stmt, err := pqh.Api.Plan(ctx, string(q))
|
||||
vprint.VV("SQL2Plan: (%v) (%v)", string(q), err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import (
|
|||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/molecula/featurebase/v2"
|
||||
pilosa "github.com/molecula/featurebase/v2"
|
||||
"github.com/molecula/featurebase/v2/boltdb"
|
||||
"github.com/molecula/featurebase/v2/encoding/proto"
|
||||
petcd "github.com/molecula/featurebase/v2/etcd"
|
||||
|
|
@ -265,7 +265,7 @@ func (m *Command) Start() (err error) {
|
|||
}
|
||||
tlsConf = conf
|
||||
}
|
||||
m.pgserver = NewPostgresServer(m.API, m.logger, tlsConf)
|
||||
m.pgserver = NewPostgresServer(m.API, m.logger, tlsConf, SqlVersion(m.Config.Postgres.SqlVersion))
|
||||
m.pgserver.s.StartupTimeout = time.Duration(m.Config.Postgres.StartupTimeout)
|
||||
m.pgserver.s.ReadTimeout = time.Duration(m.Config.Postgres.ReadTimeout)
|
||||
m.pgserver.s.WriteTimeout = time.Duration(m.Config.Postgres.WriteTimeout)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue