server

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 62 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SASLMechanism_SCRAM_SHA_256      = "SCRAM-SHA-256"
	SASLMechanism_SCRAM_SHA_256_PLUS = "SCRAM-SHA-256-PLUS"
)

These are mechanisms that are used for SASL authentication.

View Source
const (
	Version = "0.14.1"

	DefUserName  = "postres"
	DefUserEmail = "postgres@somewhere.com"
	DoltgresDir  = "postgres"
)
View Source
const PrintErrorStackTracesEnvKey = "DOLTGRES_PRINT_ERROR_STACK_TRACES"

Variables

View Source
var EnableAuthentication = true

EnableAuthentication handles whether authentication is enabled. If enabled, it verifies that the given user exists, and checks that the encrypted password is derivable from the stored encrypted password.

View Source
var HandlePanics = true

HandlePanics determines whether panics should be handled in the connection handler. See |disablePanicHandlingEnvVar|.

Functions

func NewListener

func NewListener(listenerCfg mysql.ListenerConfig) (server.ProtocolListener, error)

NewListener creates a new Listener.

func NewListenerWithOpts added in v0.5.0

func NewListenerWithOpts(listenerCfg mysql.ListenerConfig, opts ...ListenerOpt) (server.ProtocolListener, error)

func RunInMemory

func RunInMemory(cfg *servercfg.DoltgresConfig) (*svcs.Controller, error)

RunInMemory starts the server based on the given args, while also using RAM as the backing store. The returned WaitGroup may be used to wait for the server to close.

func RunOnDisk

func RunOnDisk(ctx context.Context, cfg *servercfg.DoltgresConfig, dEnv *env.DoltEnv) (*svcs.Controller, error)

RunOnDisk starts the server based on the given args, while also using the local disk as the backing store. The returned WaitGroup may be used to wait for the server to close.

func VitessTypeToObjectID added in v0.12.0

func VitessTypeToObjectID(typ query.Type) (uint32, error)

VitessTypeToObjectID returns a type, as defined by Vitess, into a type as defined by Postgres. OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`

Types

type ConnectionHandler added in v0.4.0

type ConnectionHandler struct {
	// contains filtered or unexported fields
}

ConnectionHandler is responsible for the entire lifecycle of a user connection: receiving messages they send, executing queries, sending the correct messages in return, and terminating the connection when appropriate.

func NewConnectionHandler added in v0.4.0

func NewConnectionHandler(conn net.Conn, handler mysql.Handler) *ConnectionHandler

NewConnectionHandler returns a new ConnectionHandler for the connection provided

func (*ConnectionHandler) Conn added in v0.4.0

func (h *ConnectionHandler) Conn() net.Conn

Conn returns the underlying net.Conn for this connection.

func (*ConnectionHandler) HandleConnection added in v0.4.0

func (h *ConnectionHandler) HandleConnection()

HandleConnection handles a connection's session, reading messages, executing queries, and sending responses. Expected to run in a goroutine per connection.

type ConvertedQuery added in v0.2.0

type ConvertedQuery struct {
	String       string
	AST          vitess.Statement
	StatementTag string
}

ConvertedQuery represents a query that has been converted from the Postgres representation to the Vitess representation. String may contain the string version of the converted query. AST will contain the tree version of the converted query, and is the recommended form to use. If AST is nil, then use the String version, otherwise always prefer to AST.

type DoltgresHandler added in v0.12.0

type DoltgresHandler struct {
	// contains filtered or unexported fields
}

DoltgresHandler is a handler uses SQLe engine directly running Doltgres specific queries.

func (*DoltgresHandler) ComBind added in v0.12.0

func (h *DoltgresHandler) ComBind(ctx context.Context, c *mysql.Conn, query string, parsedQuery mysql.ParsedQuery, bindVars map[string]sqlparser.Expr) (mysql.BoundQuery, []pgproto3.FieldDescription, error)

ComBind implements the Handler interface.

func (*DoltgresHandler) ComExecuteBound added in v0.12.0

func (h *DoltgresHandler) ComExecuteBound(ctx context.Context, conn *mysql.Conn, query string, boundQuery mysql.BoundQuery, callback func(*Result) error) error

ComExecuteBound implements the Handler interface.

func (*DoltgresHandler) ComPrepareParsed added in v0.12.0

ComPrepareParsed implements the Handler interface.

func (*DoltgresHandler) ComQuery added in v0.12.0

func (h *DoltgresHandler) ComQuery(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, callback func(*Result) error) error

ComQuery implements the Handler interface.

func (*DoltgresHandler) ComResetConnection added in v0.12.0

func (h *DoltgresHandler) ComResetConnection(c *mysql.Conn) error

ComResetConnection implements the Handler interface.

func (*DoltgresHandler) ConnectionClosed added in v0.12.0

func (h *DoltgresHandler) ConnectionClosed(c *mysql.Conn)

ConnectionClosed implements the Handler interface.

func (*DoltgresHandler) NewConnection added in v0.12.0

func (h *DoltgresHandler) NewConnection(c *mysql.Conn)

NewConnection implements the Handler interface.

func (*DoltgresHandler) NewContext added in v0.12.0

func (h *DoltgresHandler) NewContext(ctx context.Context, c *mysql.Conn, query string) (*sql.Context, error)

NewContext implements the Handler interface.

type ErrorResponseSeverity added in v0.12.0

type ErrorResponseSeverity string

ErrorResponseSeverity represents the severity of an ErrorResponse message.

const (
	ErrorResponseSeverity_Error   ErrorResponseSeverity = "ERROR"
	ErrorResponseSeverity_Fatal   ErrorResponseSeverity = "FATAL"
	ErrorResponseSeverity_Panic   ErrorResponseSeverity = "PANIC"
	ErrorResponseSeverity_Warning ErrorResponseSeverity = "WARNING"
	ErrorResponseSeverity_Notice  ErrorResponseSeverity = "NOTICE"
	ErrorResponseSeverity_Debug   ErrorResponseSeverity = "DEBUG"
	ErrorResponseSeverity_Info    ErrorResponseSeverity = "INFO"
	ErrorResponseSeverity_Log     ErrorResponseSeverity = "LOG"
)

type Handler added in v0.12.0

type Handler interface {
	// ComBind is called when a connection receives a request to bind a prepared statement to a set of values.
	ComBind(ctx context.Context, c *mysql.Conn, query string, parsedQuery mysql.ParsedQuery, bindVars map[string]sqlparser.Expr) (mysql.BoundQuery, []pgproto3.FieldDescription, error)
	// ComExecuteBound is called when a connection receives a request to execute a prepared statement that has already bound to a set of values.
	ComExecuteBound(ctx context.Context, conn *mysql.Conn, query string, boundQuery mysql.BoundQuery, callback func(*Result) error) error
	// ComPrepareParsed is called when a connection receives a prepared statement query that has already been parsed.
	ComPrepareParsed(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement) (mysql.ParsedQuery, []pgproto3.FieldDescription, error)
	// ComQuery is called when a connection receives a query. Note the contents of the query slice may change
	// after the first call to callback. So the DoltgresHandler should not hang on to the byte slice.
	ComQuery(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, callback func(*Result) error) error
	// ComResetConnection resets the connection's session, clearing out any cached prepared statements, locks, user and
	// session variables. The currently selected database is preserved.
	ComResetConnection(c *mysql.Conn) error
	// ConnectionClosed reports that a connection has been closed.
	ConnectionClosed(c *mysql.Conn)
	// NewConnection reports that a new connection has been established.
	NewConnection(c *mysql.Conn)
	// NewContext creates a new sql.Context instance for the connection |c|. The
	// optional |query| can be specified to populate the sql.Context's query field.
	NewContext(ctx context.Context, c *mysql.Conn, query string) (*sql.Context, error)
}

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener listens for connections to process PostgreSQL requests into Dolt requests.

func (*Listener) Accept

func (l *Listener) Accept()

Accept handles incoming connections.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the address that the listener is listening on.

func (*Listener) Close

func (l *Listener) Close()

Close stops the handling of incoming connections.

type ListenerOpt added in v0.5.0

type ListenerOpt func(*Listener)

func WithCertificate added in v0.5.0

func WithCertificate(cert tls.Certificate) ListenerOpt

type PortalData added in v0.4.0

type PortalData struct {
	Query        ConvertedQuery
	IsEmptyQuery bool
	Fields       []pgproto3.FieldDescription
	BoundPlan    sql.Node
}

type PreparedStatementData added in v0.4.0

type PreparedStatementData struct {
	Query        ConvertedQuery
	ReturnFields []pgproto3.FieldDescription
	BindVarTypes []uint32
}

type QueryExecutor added in v0.12.0

type QueryExecutor func(ctx *sql.Context, query string, parsed sqlparser.Statement, analyzed sql.Node) (sql.Schema, sql.RowIter, *sql.QueryFlags, error)

QueryExecutor is a function that executes a query and returns the result as a schema and iterator. Either of |parsed| or |analyzed| can be nil depending on the use case

type ReadyForQueryTransactionIndicator added in v0.12.0

type ReadyForQueryTransactionIndicator byte

ReadyForQueryTransactionIndicator indicates the state of the transaction related to the query.

const (
	ReadyForQueryTransactionIndicator_Idle                   ReadyForQueryTransactionIndicator = 'I'
	ReadyForQueryTransactionIndicator_TransactionBlock       ReadyForQueryTransactionIndicator = 'T'
	ReadyForQueryTransactionIndicator_FailedTransactionBlock ReadyForQueryTransactionIndicator = 'E'
)

type Result added in v0.12.0

type Result struct {
	Fields       []pgproto3.FieldDescription `json:"fields"`
	Rows         []Row                       `json:"rows"`
	RowsAffected uint64                      `json:"rows_affected"`
}

Result represents a query result.

type Row added in v0.12.0

type Row struct {
	// contains filtered or unexported fields
}

Row represents a single row value in bytes format. |val| represents array of a single row elements, which each element value is in byte array format.

type SASLBindingFlag added in v0.12.0

type SASLBindingFlag string

SASLBindingFlag are the flags for gs2-cbind-flag, used in SASL authentication.

const (
	SASLBindingFlag_NoClientSupport        SASLBindingFlag = "n"
	SASLBindingFlag_AssumedNoServerSupport SASLBindingFlag = "y"
	SASLBindingFlag_Used                   SASLBindingFlag = "p"
)

type SASLContinue added in v0.12.0

type SASLContinue struct {
	Nonce      string
	Salt       string // Base64 encoded salt
	Iterations uint32
}

SASLContinue is the structured form of the output for *pgproto3.SASLInitialResponse.

func (SASLContinue) Encode added in v0.12.0

Encode returns the struct as an AuthenticationSASLContinue message.

type SASLInitial added in v0.12.0

type SASLInitial struct {
	Flag     SASLBindingFlag
	BindName string // Only set when Flag is SASLBindingFlag_Used
	Binding  string // Base64 encoding of cbind-input
	Authzid  string // Authorization ID, currently ignored in favor of the startup message's username
	Username string // Prepared using SASLprep, currently ignored in favor of the startup message's username
	Nonce    string
	RawData  []byte // The bytes that were received in the message
}

SASLInitial is the structured form of the input given by *pgproto3.SASLInitialResponse.

func (SASLInitial) Base64Header added in v0.12.0

func (si SASLInitial) Base64Header() string

Base64Header returns the base64-encoded GS2 header and channel binding data.

func (SASLInitial) MessageBare added in v0.13.0

func (si SASLInitial) MessageBare() []byte

MessageBare returns the message without the GS2 header.

type SASLResponse added in v0.12.0

type SASLResponse struct {
	GS2Header   string
	Nonce       string
	ClientProof string // Base64 encoded
	RawData     []byte // The bytes that were received in the message
}

SASLResponse is the structured form of the input given by *pgproto3.SASLResponse.

func (SASLResponse) MessageWithoutProof added in v0.13.0

func (sr SASLResponse) MessageWithoutProof() []byte

MessageWithoutProof returns the client-final-message-without-proof.

Directories

Path Synopsis
Package settings provides utility functions for working with settings, such as the search_path setting.
Package settings provides utility functions for working with settings, such as the search_path setting.
oid

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL