clientinteractor

package
v0.0.0-...-a56bf6c Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: PostgreSQL Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASC = iota
	DESC
)
View Source
const DOUBLEOID = 701

DOUBLEOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L223

View Source
const INTOID = 20

INTOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L55

View Source
const TEXTOID = 25

TEXTOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L81

Variables

This section is empty.

Functions

func FloatOidFD

func FloatOidFD(stmt string) pgproto3.FieldDescription

FloatOidFD generates a pgproto3.FieldDescription object of FLOAT8 type with the provided statement text.

Parameters: - stmt (string): The statement text to use in the FieldDescription.

Returns: - A pgproto3.FieldDescription object initialized with the provided statement text and default values.

func GetColumnsMap

func GetColumnsMap(desc TableDesc) map[string]int

GetColumnsMap generates a map that maps column names to their respective indices in the table description header.

Parameters: - desc (TableDesc): The table description.

Returns: - map[string]int: A map that maps column names to their respective indices in the table description header.

func IntOidFD

func IntOidFD(stmt string) pgproto3.FieldDescription

IntOidFD generates a pgproto3.FieldDescription object of INT type with the provided statement text.

Parameters: - stmt (string): The statement text to use in the FieldDescription.

Returns: - A pgproto3.FieldDescription object initialized with the provided statement text and default values.

func MatchRow

func MatchRow(row []string, nameToIndex map[string]int, condition spqrparser.WhereClauseNode) (bool, error)

MatchRow checks if a row matches a given condition in a WHERE clause.

Parameters: - row ([]string): The row of data to be checked. - nameToIndex (map[string]int): A map that maps column names to their respective indices in the row. - condition (spqrparser.WhereClauseNode): The condition to be checked against the row.

Returns: - bool: True if the row matches the condition, false otherwise. - error: An error if there was a problem evaluating the condition.

func TextOidFD

func TextOidFD(stmt string) pgproto3.FieldDescription

TextOidFD generates a pgproto3.FieldDescription object with the provided statement text.

Parameters: - stmt (string): The statement text to use in the FieldDescription.

Returns: - A pgproto3.FieldDescription object initialized with the provided statement text and default values.

Types

type ClientDesc

type ClientDesc struct {
}

func (ClientDesc) GetHeader

func (ClientDesc) GetHeader() []string

GetHeader returns the header row for the client description.

Parameters: - None.

Returns: - []string: The header row, which consists of the following elements:

  • "client_id" (string): The ID of the client.
  • "user" (string): The user of the client.
  • "dbname" (string): The database of the client.
  • "server_id" (string): The server ID.
  • "router_address" (string): The router address.
  • "router_time_<quantile>" (string): The header for the quantile time for the router.
  • "shard_time_<quantile>" (string): The header for the quantile time for the shard.

func (ClientDesc) GetRow

func (ClientDesc) GetRow(cl client.Client, hostname string, rAddr string) []string

GetRow retrieves a row of data for a given client, hostname, and rAddr.

Parameters: - cl (client.Client): The client object. - hostname (string): The hostname. - rAddr (string): The rAddr.

Returns: - []string: The row data, which consists of the following elements:

  • ID (int): The ID of the client.
  • Usr (string): The user of the client.
  • DB (string): The database of the client.
  • Hostname (string): The hostname.
  • RAddr (string): The rAddr.
  • Quantiles ([]float64): The quantiles of time statistics for the client.
  • TimeQuantileRouter (float64): The time quantile for the router.
  • TimeQuantileShard (float64): The time quantile for the shard.

type Interactor

type Interactor interface {
	ProcClient(ctx context.Context, nconn net.Conn, pt port.RouterPortType) error
}

type PSQLInteractor

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

func NewPSQLInteractor

func NewPSQLInteractor(cl client.Client) *PSQLInteractor

NewPSQLInteractor creates a new instance of the PSQLInteractor struct.

Parameters: - cl (client.Client): The client.Client object to be associated with the PSQLInteractor.

Returns: - A pointer to the newly created PSQLInteractor object.

func (*PSQLInteractor) AddDistribution

func (pi *PSQLInteractor) AddDistribution(ctx context.Context, ks *distributions.Distribution) error

AddDistribution adds a distribution to the PSQL client.

Parameters: - ctx (context.Context): The context for the operation. - ks (*distributions.Distribution): The distribution to add.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) AddShard

func (pi *PSQLInteractor) AddShard(shard *datashards.DataShard) error

AddShard sends the row description message for adding a data shard, followed by a data row indicating the creation of the specified data shard, and completes the message.

Parameters: - shard (*datashards.DataShard): The datashards.DataShard object to be added.

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) AlterDistributionAttach

func (pi *PSQLInteractor) AlterDistributionAttach(ctx context.Context, id string, ds []*distributions.DistributedRelation) error

AlterDistributionAttach attaches tables to a distribution in the PSQL client.

Parameters: - ctx (context.Context): The context for the operation. - id (string): The ID of the distribution to attach tables to. - ds ([]*distributions.DistributedRelation): The list of distributed relations to attach.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) AlterDistributionDetach

func (pi *PSQLInteractor) AlterDistributionDetach(_ context.Context, id string, relName string) error

AlterDistributionDetach detaches a relation from a distribution in the PSQL client.

Parameters: - _ (context.Context): The context for the operation. (Unused) - id (string): The ID of the distribution to detach the relation from. - relName (string): The name of the relation to detach.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) BackendConnections

func (pi *PSQLInteractor) BackendConnections(_ context.Context, shs []shard.Shardinfo, stmt *spqrparser.Show) error

BackendConnections writes backend connection information to the PSQL client.

Parameters: - _ (context.Context): The context for the operation. - shs ([]shard.Shardinfo): The list of shard information. - stmt (*spqrparser.Show): The query itself.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) Clients

func (pi *PSQLInteractor) Clients(ctx context.Context, clients []client.ClientInfo, query *spqrparser.Show) error

Clients retrieves client information based on provided client information, filtering conditions and writes the data to the PSQL client.

Parameters: - ctx (context.Context): The context for the operation. - clients ([]client.ClientInfo): The list of client information to process. - condition (spqrparser.WhereClauseNode): The condition to filter the client information.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) CompleteMsg

func (pi *PSQLInteractor) CompleteMsg(rowCnt int) error

CompleteMsg sends the completion message with the specified row count.

Parameters: - rowCnt (int): The row count to include in the completion message.

Returns:

  • error: An error if sending the message fails, otherwise nil.

func (*PSQLInteractor) CreateKeyRange

func (pi *PSQLInteractor) CreateKeyRange(ctx context.Context, keyRange *kr.KeyRange) error

CreateKeyRange sends the row description message for adding a key range, followed by a data row indicating the creation of the specified key range, and completes the message.

Parameters: - ctx (context.Context): The context parameter. - keyRange (*kr.KeyRange): The *kr.KeyRange object to be created.

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) Databases

func (pi *PSQLInteractor) Databases(dbs []string) error

Databases sends the row description message for the "show databases" statement, followed by data rows containing the provided database names, and finally completes the message with the number of rows sent.

Parameters: - dbs ([]string): The list of database names to include in the data rows.

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) Distributions

func (pi *PSQLInteractor) Distributions(_ context.Context, distributions []*distributions.Distribution) error

Distributions sends distribution data to the PSQL client.

Parameters: - _ (context.Context): The context for the operation. - distributions ([]*distributions.Distribution): The list of distribution data to send.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) DropDistribution

func (pi *PSQLInteractor) DropDistribution(ctx context.Context, ids []string) error

DropDistribution drops distributions with the specified IDs in the PSQL client.

Parameters: - ctx (context.Context): The context for the operation. - ids ([]string): The list of distribution IDs to drop.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) DropKeyRange

func (pi *PSQLInteractor) DropKeyRange(ctx context.Context, ids []string) error

StopTraceMessages stops tracing of messages in the PSQL client.

Parameters: - ctx (context.Context): The context for the operation.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) DropShard

func (pi *PSQLInteractor) DropShard(id string) error

DropShard sends the row description message for dropping a shard, followed by a data row indicating the dropping of the specified shard, and completes the message.

Parameters: - id (string): The ID of the shard to be dropped (string).

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) DropTaskGroup

func (pi *PSQLInteractor) DropTaskGroup(_ context.Context) error

DropTaskGroup drops all tasks in the task group.

Parameters: - _ (context.Context): The context parameter.

Returns: - error: An error if there was a problem dropping the tasks.

func (*PSQLInteractor) KeyRanges

func (pi *PSQLInteractor) KeyRanges(krs []*kr.KeyRange) error

KeyRanges sends the row description message for key ranges, followed by data rows containing details of each key range, and completes the message.

Parameters: - krs ([]*kr.KeyRange): The list of *kr.KeyRange objects containing the key range information.

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) KillClient

func (pi *PSQLInteractor) KillClient(clientID uint) error

KillClient kills a client in the PSQL client.

Parameters: - clientID (uint): The ID of the client to kill.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) LockKeyRange

func (pi *PSQLInteractor) LockKeyRange(ctx context.Context, krid string) error

LockKeyRange sends the row description message for locking a key range with the specified ID, followed by a data row indicating the locking of the key range, and completes the message.

Parameters: - ctx (context.Context): The context parameter. - krid (string): The ID of the key range to be locked (string).

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) MergeKeyRanges

func (pi *PSQLInteractor) MergeKeyRanges(_ context.Context, unite *kr.UniteKeyRange) error

MergeKeyRanges merges two key ranges in the PSQL client.

Parameters: - _ (context.Context): The context for the operation. - unite (*kr.UniteKeyRange): The key range to merge.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) MoveKeyRange

func (pi *PSQLInteractor) MoveKeyRange(_ context.Context, move *kr.MoveKeyRange) error

MoveKeyRange moves a key range to a specific shard in the PSQL client.

Parameters: - _ (context.Context): The context for the operation. - move (*kr.MoveKeyRange): The key range and shard information for the move operation.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) MoveTaskGroup

func (pi *PSQLInteractor) MoveTaskGroup(_ context.Context, ts *tasks.MoveTaskGroup) error

MoveTaskGroup sends the list of move tasks to the client.

Parameters: - ctx (context.Context): The context parameter. - ts ([]*tasks.MoveTask): A slice of *tasks.MoveTask objects representing the move tasks.

Returns: - error: An error if sending the tasks fails, otherwise nil.

func (*PSQLInteractor) Pools

func (pi *PSQLInteractor) Pools(_ context.Context, ps []pool.Pool) error

Pools sends the row description message for pool information, followed by data rows containing details of each pool, and completes the message with the number of pools sent.

Parameters: - _ (context.Context): The context parameter (not used in the function). - ps ([]pool.Pool): The list of pool.Pool objects containing the pool information.

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) PreparedStatements

func (pi *PSQLInteractor) PreparedStatements(ctx context.Context, shs []shard.PreparedStatementsMgrDescriptor) error

func (*PSQLInteractor) Quantiles

func (pi *PSQLInteractor) Quantiles(_ context.Context) error

Quantiles sends the row description message for total time quantiles of queries in router and in shard.

Parameters: - _ (context.Context): The context parameter (not used in the function).

Returns:

  • error: An error if sending the messages fails, otherwise nil.

TODO: unit tests

func (*PSQLInteractor) RedistributeKeyRange

func (pi *PSQLInteractor) RedistributeKeyRange(_ context.Context, stmt *spqrparser.RedistributeKeyRange) error

RedistributeKeyRange moves key range to a specified shard in the PSQL client. Data moves are done by batches of the given size.

Parameters: - _ (context.Context): The context for the operation. - redistribute (*kr.MoveKeyRange): The key range and shard information for the redistribution operation.

Returns: - error: An error if any occurred. TODO : unit tests

func (*PSQLInteractor) RegisterRouter

func (pi *PSQLInteractor) RegisterRouter(ctx context.Context, id string, addr string) error

RegisterRouter registers a router with the specified ID and address.

Parameters: - ctx (context.Context): The context for the operation. - id (string): The ID of the router to register. - addr (string): The address of the router to register.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) Relations

func (pi *PSQLInteractor) Relations(dsToRels map[string][]*distributions.DistributedRelation, condition spqrparser.WhereClauseNode) error

Relations sends information about attached relations that satisfy conditions in WHERE-clause Relations writes relation information to the PSQL client based on the given distribution-to-relations map and condition.

Parameters: - dsToRels (map[string][]*distributions.DistributedRelation): The map of distribution names to their corresponding distributed relations. - condition (spqrparser.WhereClauseNode): The condition for filtering the relations.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) ReportError

func (pi *PSQLInteractor) ReportError(err error) error

ReportError sends an error response to the PSQL client in case of an error.

Parameters: - err (error): The error to report.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) ReportStmtRoutedToAllShards

func (pi *PSQLInteractor) ReportStmtRoutedToAllShards(ctx context.Context) error

ReportStmtRoutedToAllShards reports that a statement has been routed to all shards in the PSQL client.

Parameters: - ctx (context.Context): The context for the operation.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) Routers

func (pi *PSQLInteractor) Routers(resp []*topology.Router) error

Routers sends information about routers to the PSQL client.

Parameters: - resp ([]*topology.Router): The list of router information to send.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) Shards

func (pi *PSQLInteractor) Shards(ctx context.Context, shards []*datashards.DataShard) error

Shards lists the data shards.

Parameters: - ctx (context.Context): The context parameter. - shards ([]*datashards.DataShard): The list of data shards to be listed.

Returns: - error: An error if there was a problem listing the data shards.

func (*PSQLInteractor) SplitKeyRange

func (pi *PSQLInteractor) SplitKeyRange(ctx context.Context, split *kr.SplitKeyRange) error

SplitKeyRange sends the row description message for splitting a key range, followed by a data row indicating the split of the key range, and completes the message.

Parameters: - ctx (context.Context): The context parameter. - split (*kr.SplitKeyRange): The *kr.SplitKeyRange object containing information about the split.

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) StartTraceMessages

func (pi *PSQLInteractor) StartTraceMessages(ctx context.Context) error

StartTraceMessages initiates tracing of messages in the PSQL client.

Parameters: - ctx (context.Context): The context for the operation.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) StopTraceMessages

func (pi *PSQLInteractor) StopTraceMessages(ctx context.Context) error

StopTraceMessages stops tracing of messages in the PSQL client.

Parameters: - ctx (context.Context): The context for the operation.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) UnlockKeyRange

func (pi *PSQLInteractor) UnlockKeyRange(ctx context.Context, krid string) error

UnlockKeyRange sends the row description message for unlocking a key range with the specified ID, followed by a data row indicating the unlocking of the key range, and completes the message.

Parameters: - ctx (context.Context): The context parameter. - krid (string): The ID of the key range to be unlocked (string).

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) UnregisterRouter

func (pi *PSQLInteractor) UnregisterRouter(id string) error

UnregisterRouter unregisters a router with the specified ID.

Parameters: - id (string): The ID of the router to unregister.

Returns: - error: An error if any occurred during the operation.

func (*PSQLInteractor) Version

func (pi *PSQLInteractor) Version(_ context.Context) error

Version sends the row description message for the SPQR version and a data row with the SPQR version revision.

Parameters: - _ (context.Context): The context parameter (not used in the function).

Returns:

  • error: An error if sending the messages fails, otherwise nil.

func (*PSQLInteractor) WriteDataRow

func (pi *PSQLInteractor) WriteDataRow(msgs ...string) error

WriteDataRow sends the data row message with the specified values.

Parameters: - msgs ([]string): The list of string values to include in the DataRow message.

Returns:

  • error: An error if sending the message fails, otherwise nil.

func (*PSQLInteractor) WriteHeader

func (pi *PSQLInteractor) WriteHeader(stmts ...string) error

WriteHeader sends the row description message with the specified field descriptions.

Parameters: - stmts ([]string): The list of statement texts to use as field names in the RowDescription message.

Returns:

  • error: An error if sending the message fails, otherwise nil.

type SortableWithContext

type SortableWithContext struct {
	Data      [][]string
	Col_index int
	Order     int
}

func (SortableWithContext) Len

func (a SortableWithContext) Len() int

func (SortableWithContext) Less

func (a SortableWithContext) Less(i, j int) bool

func (SortableWithContext) Swap

func (a SortableWithContext) Swap(i, j int)

type TableDesc

type TableDesc interface {
	GetHeader() []string
}

Jump to

Keyboard shortcuts

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