server

package
v0.55.5 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 77 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 (
	PrintErrorStackTracesEnvKey = "DOLTGRES_PRINT_ERROR_STACK_TRACES"
	ForceTextWireFormatEnvKey   = "DOLTGRES_FORCE_TEXT_WIRE_FORMAT"
)
View Source
const (
	Version = "0.55.5"

	DefUserName         = "postres"
	DefUserEmail        = "[email protected]"
	DefUserEmailFmt     = "%[email protected]"
	DefaultDbNameEnvVar = "DOLTGRES_DB"
)

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 (
	ForceTextWireFormat = false
)
View Source
var HandlePanics = true

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

Functions

func NewListener

NewListener creates a new Listener.

func NewListenerWithOpts added in v0.5.0

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

func RunInMemory

func RunInMemory(cfg *servercfg.DoltgresConfig, protocolListenerFactory server.ProtocolListenerFunc) (*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 sql.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 BindVariables added in v0.16.0

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

BindVariables represents arrays of types, format codes and parameters used to convert given parameters to binding variables map.

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, sel server.ServerEventListener) *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 BindVariables, formatCodes []int16) (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, formatCodes []int16, callback func(*sql.Context, *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(*sql.Context, *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) InitSessionParameterDefault added in v0.52.0

func (h *DoltgresHandler) InitSessionParameterDefault(ctx context.Context, c *mysql.Conn, name, value string) error

InitSessionParameterDefault sets a default value to specified parameter for a session.

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 BindVariables, formatCodes []int16) (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, formatCodes []int16, callback func(*sql.Context, *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(*sql.Context, *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
	FormatCodes  []int16
}

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.

type WireRW added in v0.55.5

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

WireRW handles all read and write operations for the Postgres binary wire format. This should only be used for interacting with the wire format, and not for internal use (utils.Reader and utils.Writer exist for internal use).

func NewWireReader added in v0.55.5

func NewWireReader(data []byte) *WireRW

NewWireReader creates a new WireRW for reading from data previously written by either a valid Postgres server or a WireRW instance. This is intended strictly for reading the binary wire format that Postgres expects, and should not be used for internal read operations (utils.Reader is for internal use).

func NewWireWriter added in v0.55.5

func NewWireWriter() *WireRW

NewWireWriter creates a new WireRW for writing to. This is intended strictly for writing to the binary wire format that Postgres expects, and should not be used for internal write operations (utils.Writer is for internal use).

func (*WireRW) BufferData added in v0.55.5

func (rw *WireRW) BufferData() []byte

BufferData returns the data in the buffer. This does not make a copy.

func (*WireRW) BufferSize added in v0.55.5

func (rw *WireRW) BufferSize() uint64

BufferSize returns the number of bytes in the buffer.

func (*WireRW) ReadBool added in v0.55.5

func (rw *WireRW) ReadBool() bool

ReadBool reads a 1-byte bool.

func (*WireRW) ReadBytes added in v0.55.5

func (rw *WireRW) ReadBytes(n uint32) []byte

ReadBytes reads the next N bytes.

func (*WireRW) ReadFloat32 added in v0.55.5

func (rw *WireRW) ReadFloat32() float32

ReadFloat32 reads a float32.

func (*WireRW) ReadFloat64 added in v0.55.5

func (rw *WireRW) ReadFloat64() float64

ReadFloat64 reads a float64.

func (*WireRW) ReadInt8 added in v0.55.5

func (rw *WireRW) ReadInt8() int8

ReadInt8 reads an int8.

func (*WireRW) ReadInt16 added in v0.55.5

func (rw *WireRW) ReadInt16() int16

ReadInt16 reads an int16.

func (*WireRW) ReadInt32 added in v0.55.5

func (rw *WireRW) ReadInt32() int32

ReadInt32 reads an int32.

func (*WireRW) ReadInt64 added in v0.55.5

func (rw *WireRW) ReadInt64() int64

ReadInt64 reads an int64.

func (*WireRW) ReadString added in v0.55.5

func (rw *WireRW) ReadString(n uint32) string

ReadString reads the next N bytes as a string.

func (*WireRW) ReadUint8 added in v0.55.5

func (rw *WireRW) ReadUint8() uint8

ReadUint8 reads a uint8.

func (*WireRW) ReadUint16 added in v0.55.5

func (rw *WireRW) ReadUint16() uint16

ReadUint16 reads a uint16.

func (*WireRW) ReadUint32 added in v0.55.5

func (rw *WireRW) ReadUint32() uint32

ReadUint32 reads a uint32.

func (*WireRW) ReadUint64 added in v0.55.5

func (rw *WireRW) ReadUint64() uint64

ReadUint64 reads a uint64.

func (*WireRW) Reserve added in v0.55.5

func (rw *WireRW) Reserve(n uint64)

Reserve ensures that there are at least N bytes in the buffer, which can prevent reallocations if the space needed is known upfront.

func (*WireRW) WriteBool added in v0.55.5

func (rw *WireRW) WriteBool(val bool) *WireRW

WriteBool writes a 1-byte bool.

func (*WireRW) WriteBytes added in v0.55.5

func (rw *WireRW) WriteBytes(val []byte) *WireRW

WriteBytes writes the bytes given.

func (*WireRW) WriteFloat32 added in v0.55.5

func (rw *WireRW) WriteFloat32(val float32) *WireRW

WriteFloat32 writes a float32.

func (*WireRW) WriteFloat64 added in v0.55.5

func (rw *WireRW) WriteFloat64(val float64) *WireRW

WriteFloat64 writes a float64.

func (*WireRW) WriteInt8 added in v0.55.5

func (rw *WireRW) WriteInt8(val int8) *WireRW

WriteInt8 writes an int8.

func (*WireRW) WriteInt16 added in v0.55.5

func (rw *WireRW) WriteInt16(val int16) *WireRW

WriteInt16 writes an int16.

func (*WireRW) WriteInt32 added in v0.55.5

func (rw *WireRW) WriteInt32(val int32) *WireRW

WriteInt32 writes an int32.

func (*WireRW) WriteInt64 added in v0.55.5

func (rw *WireRW) WriteInt64(val int64) *WireRW

WriteInt64 writes an int64.

func (*WireRW) WriteString added in v0.55.5

func (rw *WireRW) WriteString(val string) *WireRW

WriteString writes the raw string bytes.

func (*WireRW) WriteUint8 added in v0.55.5

func (rw *WireRW) WriteUint8(val uint8) *WireRW

WriteUint8 writes a uint8.

func (*WireRW) WriteUint16 added in v0.55.5

func (rw *WireRW) WriteUint16(val uint16) *WireRW

WriteUint16 writes a uint16.

func (*WireRW) WriteUint32 added in v0.55.5

func (rw *WireRW) WriteUint32(val uint32) *WireRW

WriteUint32 writes a uint32.

func (*WireRW) WriteUint64 added in v0.55.5

func (rw *WireRW) WriteUint64(val uint64) *WireRW

WriteUint64 writes a uint64.

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.

Jump to

Keyboard shortcuts

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