v0.0.0-...-3633c1a Latest Latest

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 18 Imported by: 0




View Source
const (
	// LibrarySuffix defines TiDB plugin's file suffix.
	LibrarySuffix = ".so"
	// ManifestSymbol defines TiDB plugin's entrance symbol.
	// Plugin take manifest info from this symbol.
	ManifestSymbol = "PluginManifest"


This section is empty.


func ForeachPlugin

func ForeachPlugin(kind Kind, fn func(plugin *Plugin) error) error

ForeachPlugin loops all ready plugins.

func GetAll

func GetAll() map[Kind][]Plugin

GetAll finds and returns all plugins.

func Init

func Init(ctx context.Context, cfg Config) (err error)

Init initializes the loaded plugin by config param. This method must be called after `Load` but before any other plugin method call, so it call got TiDB domain info.

func IsEnable

func IsEnable(kind Kind) bool

IsEnable checks plugin's enable state.

func Load

func Load(ctx context.Context, cfg Config) (err error)

Load load plugin by config param. This method need be called before domain init to inject global variable info during bootstrap.

func NotifyFlush

func NotifyFlush(dom *domain.Domain, pluginName string) error

NotifyFlush notify plugins to do flush logic.

func Shutdown

func Shutdown(ctx context.Context)

Shutdown cleanups all plugin resources. Notice: it just cleanups the resource of plugin, but cannot unload plugins(limited by go plugin).


type AuditManifest

type AuditManifest struct {
	// OnConnectionEvent will be called when TiDB receive or disconnect from client.
	// return error will ignore and close current connection.
	OnConnectionEvent func(ctx context.Context, identity *auth.UserIdentity, event ConnectionEvent, info *variable.ConnectionInfo) error
	// OnGeneralEvent will be called during TiDB execution.
	OnGeneralEvent func(ctx context.Context, sctx *variable.SessionVars, event GeneralEvent, cmd string)
	// OnGlobalVariableEvent will be called when Change GlobalVariable.
	OnGlobalVariableEvent func(ctx context.Context, sctx *variable.SessionVars, varName, varValue string)
	// OnParseEvent will be called around parse logic.
	OnParseEvent func(ctx context.Context, sctx *variable.SessionVars, event ParseEvent) error

AuditManifest presents a sub-manifest that every audit plugin must provide.

func DeclareAuditManifest

func DeclareAuditManifest(m *Manifest) *AuditManifest

DeclareAuditManifest declares manifest as AuditManifest.

type AuthenticationManifest

type AuthenticationManifest struct {
	AuthenticateUser             func()
	GenerateAuthenticationString func()
	ValidateAuthenticationString func()
	SetSalt                      func()

AuthenticationManifest presents a sub-manifest that every audit plugin must provide.

func DeclareAuthenticationManifest

func DeclareAuthenticationManifest(m *Manifest) *AuthenticationManifest

DeclareAuthenticationManifest declares manifest as AuthenticationManifest.

type Config

type Config struct {
	Plugins        []string
	PluginDir      string
	GlobalSysVar   *map[string]*variable.SysVar
	PluginVarNames *[]string
	SkipWhenFail   bool
	EnvVersion     map[string]uint16
	EtcdClient     *clientv3.Client

Config presents the init configuration for plugin framework.

type ConnectionEvent

type ConnectionEvent byte

ConnectionEvent presents TiDB connection event.

const (
	// Connected presents new connection establish event(finish auth).
	Connected ConnectionEvent = iota
	// Disconnect presents disconnect event.
	// ChangeUser presents change user.
	// PreAuth presents event before start auth.

func (ConnectionEvent) String

func (c ConnectionEvent) String() string

type DaemonManifest

type DaemonManifest struct {

DaemonManifest presents a sub-manifest that every DaemonManifest plugins must provide.

func DeclareDaemonManifest

func DeclareDaemonManifest(m *Manifest) *DaemonManifest

DeclareDaemonManifest declares manifest as DaemonManifest.

type GeneralEvent

type GeneralEvent byte

GeneralEvent presents TiDB generate event.

const (
	// Log presents log event.
	Log GeneralEvent = iota
	// Error presents error event.
	// Result presents result event.
	// Status presents status event.

type ID

type ID string

ID present plugin identity.

func (ID) Decode

func (n ID) Decode() (name string, version string, err error)

Decode decodes a plugin id into name, version parts.

type Kind

type Kind uint8

Kind presents the kind of plugin.

const (
	// Audit indicates it is a Audit plugin.
	Audit Kind = 1 + iota
	// Authentication indicate it is a Authentication plugin.
	// Schema indicate a plugin that can change TiDB schema.
	// Daemon indicate a plugin that can run as daemon task.

func (Kind) String

func (k Kind) String() (str string)

type Manifest

type Manifest struct {
	Kind           Kind
	Name           string
	Description    string
	Version        uint16
	RequireVersion map[string]uint16
	License        string
	BuildTime      string
	SysVars        map[string]*variable.SysVar
	// Validate defines the validate logic for plugin.
	// returns error will stop load plugin process and TiDB startup.
	Validate func(ctx context.Context, manifest *Manifest) error
	// OnInit defines the plugin init logic.
	// it will be called after domain init.
	// return error will stop load plugin process and TiDB startup.
	OnInit func(ctx context.Context, manifest *Manifest) error
	// OnShutDown defines the plugin cleanup logic.
	// return error will write log and continue shutdown.
	OnShutdown func(ctx context.Context, manifest *Manifest) error
	// OnFlush defines flush logic after executed `flush tidb plugins`.
	// it will be called after OnInit.
	// return error will write log and continue watch following flush.
	OnFlush func(ctx context.Context, manifest *Manifest) error
	// contains filtered or unexported fields

Manifest describes plugin info and how it can do by plugin itself.

func ExportManifest

func ExportManifest(m interface{}) *Manifest

ExportManifest exports a manifest to TiDB as a known format. it just casts sub-manifest to manifest.

type ParseEvent

type ParseEvent byte

ParseEvent presents events happen around parser.

const (
	// PreParse presents event before parse.
	PreParse ParseEvent = 1 + iota
	// PostParse presents event after parse.

type Plugin

type Plugin struct {

	State State
	Path  string
	// contains filtered or unexported fields

Plugin presents a TiDB plugin.

func Get

func Get(kind Kind, name string) *Plugin

Get finds and returns plugin by kind and name parameters.

type SchemaManifest

type SchemaManifest struct {

SchemaManifest presents a sub-manifest that every schema plugins must provide.

func DeclareSchemaManifest

func DeclareSchemaManifest(m *Manifest) *SchemaManifest

DeclareSchemaManifest declares manifest as SchemaManifest.

type State

type State uint8

State present the state of plugin.

const (
	// Uninitialized indicates plugin is uninitialized.
	Uninitialized State = iota
	// Ready indicates plugin is ready to work.
	// Dying indicates plugin will be close soon.
	// Disable indicate plugin is disabled.

func (State) String

func (s State) String() (str string)


Path Synopsis

Jump to

Keyboard shortcuts

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