utils

package
v0.0.0-...-5e932ec Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MainTree                = "main"
	CteTrees                = "ctes"
	Children                = "children"
	Duration                = "duration"
	Time                    = "time"
	Diagnosis               = "diagnosis"
	RootGroupExecInfo       = "rootGroupExecInfo"
	RootBasicExecInfo       = "rootBasicExecInfo"
	OperatorInfo            = "operatorInfo"
	OperatorName            = "name"
	CopExecInfo             = "copExecInfo"
	CacheHitRatio           = "cacheHitRatio"
	TaskType                = "taskType"
	StoreType               = "storeType"
	DiskBytes               = "diskBytes"
	MemoryBytes             = "memoryBytes"
	ActRows                 = "actRows"
	EstRows                 = "estRows"
	AccessObjects           = "accessObjects"
	ScanObject              = "scanObject"
	DynamicpartitionObjects = "dynamicpartitionObjects"
	OtherObject             = "otherObject"
	DiscardedDueToTooLong   = "discardedDueToTooLong"
	BuildSide               = "buildSide"
	ProbeSide               = "probeSide"

	JoinTaskThreshold = 10000

	// role tag.
	HighEstError               = "high_est_error"
	DiskSpill                  = "disk_spill"
	PseudoEst                  = "pseudo_est"
	GoodFilterOnTableFullScan  = "good_filter_on_table_fullscan"
	BadIndexForIndexLookUp     = "bad_index_for_index_lookup"
	IndexJoinBuildSideTooLarge = "index_join_build_side_too_large"
	TiKVHugeTableScan          = "tikv_huge_table_scan"
)
View Source
const (
	Default operator = iota
	IndexJoin
	IndexMergeJoin
	IndexHashJoin
	Apply
	Shuffle
	ShuffleReceiver
	IndexLookUpReader
	IndexMergeReader
	IndexFullScan
	IndexRangeScan
	TableFullScan
	TableRangeScan
	TableRowIDScan
	Selection
)
View Source
const (
	// The key that attached the SessionUser in the gin Context.
	SessionUserKey = "user"
)
View Source
const SessionVersion = 2

Variables

View Source
var (
	NgmErrNS       = errorx.NewNamespace("ngm")
	ErrNgmNotStart = NgmErrNS.NewType("ngm_not_started")
)
View Source
var ErrExpNotEnabled = ErrNS.NewType("experimental_feature_not_enabled")
View Source
var ErrNS = errorx.NewNamespace("error.api")

Functions

func CloseTiDBConnection

func CloseTiDBConnection(db *gorm.DB) error

func DownloadByToken

func DownloadByToken(token, tokenNamespace string, c *gin.Context)

FIXME: Remove or refine this function, as it is not general.

func ExportCSV

func ExportCSV(data [][]string, filename, tokenNamespace string) (token string, err error)

TODO: Better to be a streaming interface.

func GenerateBinaryPlan

func GenerateBinaryPlan(v string) (*tipb.ExplainData, error)

GenerateBinaryPlan generate visual plan from raw data.

func GenerateBinaryPlanJSON

func GenerateBinaryPlanJSON(b string) (string, error)

func GenerateBinaryPlanText

func GenerateBinaryPlanText(db *gorm.DB, b string) (string, error)

func GenerateCSVFromRaw

func GenerateCSVFromRaw(rawData []interface{}, fields []string, timeFields []string) (data [][]string)

TODO: Better to be a streaming interface.

func GetGormColumnName

func GetGormColumnName(gormStr string) string

func GetTiDBConnection

func GetTiDBConnection(c *gin.Context) *gorm.DB

GetTiDBConnection gets the TiDB connection stored in the gin context by `MWConnectTiDB` middleware.

The connection will be closed automatically after all handlers are finished. Thus you must not use it outside the request lifetime. If you want to extend the lifetime, use `TakeTiDBConnection`.

func IsSubsetICaseInsensitive

func IsSubsetICaseInsensitive(a []string, b []string) bool

func MWConnectTiDB

func MWConnectTiDB(tidbClient *tidb.Client) gin.HandlerFunc

MWConnectTiDB creates a middleware that attaches TiDB connection to the context, according to the identity information attached in the context. If a connection cannot be established, subsequent handlers will be skipped and errors will be generated.

This middleware must be placed after the `MWAuthRequired()` middleware, otherwise it will panic.

func MWForbidByExperimentalFlag

func MWForbidByExperimentalFlag(enableExp bool) gin.HandlerFunc

func NewJWTString

func NewJWTString(issuer string, data string) (string, error)

NewJWTString create a JWT string by given data, expire in 24 hours.

func NewJWTStringWithExpire

func NewJWTStringWithExpire(issuer string, data string, expireIn time.Duration) (string, error)

func ParseJWTString

func ParseJWTString(requiredIssuer string, tokenStr string) (string, error)

ParseJWTString parse the JWT string and return the raw data.

func TakeTiDBConnection

func TakeTiDBConnection(c *gin.Context) *gorm.DB

TakeTiDBConnection takes out the TiDB connection stored in the gin context by `MWConnectTiDB` middleware. Subsequent handlers in this context cannot access the TiDB connection any more.

The TiDB connection will no longer be closed automatically after all handlers are finished. You must manually close the taken out connection.

Types

type AuthType

type AuthType int

type Claims

type Claims struct {
	Data string `json:"data"`
	jwt.StandardClaims
}

Claims is a struct that will be encoded to a JWT.

type NgmProxy

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

func NewNgmProxy

func NewNgmProxy(lc fx.Lifecycle, etcdClient *clientv3.Client, config *config.Config) (*NgmProxy, error)

func (*NgmProxy) Route

func (n *NgmProxy) Route(targetPath string) gin.HandlerFunc

type NgmState

type NgmState string
const (
	NgmStateNotSupported NgmState = "not_supported"
	NgmStateNotStarted   NgmState = "not_started"
	NgmStateStarted      NgmState = "started"
)

type SessionUser

type SessionUser struct {
	// Must be 2. This field is used to invalidate outdated sessions after schema change.
	Version int

	DisplayName string

	HasTiDBAuth  bool
	TiDBUsername string
	TiDBPassword string

	// This field only exists for CodeAuth.
	SharedSessionExpireAt time.Time `msgpack:"-" json:",omitempty"`

	// This field only exists for SSOAuth
	OIDCIDToken string `json:",omitempty"`

	// These fields should not be updated by individual authenticators.
	AuthFrom AuthType `msgpack:"-" json:",omitempty"`

	// TODO: Make them table fields
	IsShareable bool
	IsWriteable bool
}

The content of this structure will be encrypted and stored as both Session Token and Sharing Token. For fields that don't need to be cloned during session sharing, mark fields as `msgpack:"-"`.

func GetSession

func GetSession(c *gin.Context) *SessionUser

Jump to

Keyboard shortcuts

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