cmd

package
v1.4.0-nextgen.202510.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatNative         = "native"
	FormatAuditLogPlugin = "audit_log_plugin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditLogPluginDecoder

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

func NewAuditLogPluginDecoder

func NewAuditLogPluginDecoder() *AuditLogPluginDecoder

func (*AuditLogPluginDecoder) Decode

func (decoder *AuditLogPluginDecoder) Decode(reader LineReader) (*Command, error)

func (*AuditLogPluginDecoder) SetCommandStartTime

func (decoder *AuditLogPluginDecoder) SetCommandStartTime(t time.Time)

func (*AuditLogPluginDecoder) SetIDAllocator

func (decoder *AuditLogPluginDecoder) SetIDAllocator(alloc *ConnIDAllocator)

func (*AuditLogPluginDecoder) SetPSCloseStrategy

func (decoder *AuditLogPluginDecoder) SetPSCloseStrategy(s PSCloseStrategy)

type CmdDecoder

type CmdDecoder interface {
	Decode(reader LineReader) (c *Command, err error)

	SetCommandStartTime(t time.Time)
}

func NewCmdDecoder

func NewCmdDecoder(format string) CmdDecoder

type CmdEncoder

type CmdEncoder interface {
	Encode(c *Command, writer *bytes.Buffer) error
}

func NewCmdEncoder

func NewCmdEncoder(_ string) CmdEncoder

type Command

type Command struct {
	PreparedStmt string
	// CapturedPsID is the prepared statement ID in capture.
	// The Execute command needs to update the prepared statement ID in replay.
	CapturedPsID uint32
	Params       []any

	// Payload starts with command type so that replay can reuse this byte array.
	Payload []byte
	StartTs time.Time
	// For audit log plugin, the decoder will allocate a new id to avoid id collision. To make it easier
	// to debug, we keep the upstream connection id here to store it in the exception report.
	UpstreamConnID uint64
	ConnID         uint64
	Type           pnet.Command
	// The place in the traffic file, used to report.
	FileName string
	Line     int
	// Logged only in audit log.
	StmtType string
	// Logged only in native log.
	Success bool
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(packet []byte, startTs time.Time, connID uint64) *Command

func (*Command) Digest

func (c *Command) Digest() string

func (*Command) Equal

func (c *Command) Equal(that *Command) bool

func (*Command) QueryText

func (c *Command) QueryText() string

func (*Command) Validate

func (c *Command) Validate(filename string, lineIdx int) error

type ConnIDAllocator

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

ConnIDAllocator allocates connection IDs for new connections. It uses the first 10bits to distinguish different decoders, and the last 54bits are auto-incremented.

func NewConnIDAllocator

func NewConnIDAllocator(decoderID int) (*ConnIDAllocator, error)

NewConnIDAllocator creates a new ConnIDAllocator.

type LineReader

type LineReader interface {
	String() string
	ReadLine() ([]byte, string, int, error)
	Read([]byte) (string, int, error)
	Close()
}

type NativeDecoder

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

func NewNativeDecoder

func NewNativeDecoder() *NativeDecoder

func (*NativeDecoder) Decode

func (rw *NativeDecoder) Decode(reader LineReader) (c *Command, err error)

func (*NativeDecoder) SetCommandStartTime

func (rw *NativeDecoder) SetCommandStartTime(t time.Time)

type NativeEncoder

type NativeEncoder struct {
}

func NewNativeEncoder

func NewNativeEncoder() *NativeEncoder

func (*NativeEncoder) Encode

func (rw *NativeEncoder) Encode(c *Command, writer *bytes.Buffer) error

type PSCloseStrategy

type PSCloseStrategy string

PSCloseStrategy defines when to close the prepared statements.

const (
	// PSCloseStrategyAlways means a prepared statement is closed right after it's executed.
	PSCloseStrategyAlways PSCloseStrategy = "always"
	// PSCloseStrategyNever means a prepared statement is never closed. It's re-used if the same statement
	// occurs again in the connection.
	PSCloseStrategyNever PSCloseStrategy = "never"
	// PSCloseStrategyDirected means a prepared statement is closed only when there's close command in the
	// traffic file.
	PSCloseStrategyDirected PSCloseStrategy = "directed"
)

Jump to

Keyboard shortcuts

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