-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin: introduce plugin framework #8788
Conversation
@lysu Good job! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you split this PR into small parts?
For example, document and example can be a separate one;
show plugins
and config related things could comes after the plugin package core.
Smaller PR is more friendly to reviewers.
return | ||
} | ||
p := tiPlugins.plugins[kind][i] | ||
if err = p.OnInit(ctx, p.Manifest); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we defer panic for plugin init, thus plugin panic will not make TiDB panic ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, it's better let framework user to decide panic or do other things - -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tiancaiamao PR has be splitted.
Codecov Report
@@ Coverage Diff @@
## master #8788 +/- ##
==========================================
- Coverage 67.63% 67.41% -0.22%
==========================================
Files 364 370 +6
Lines 75471 75732 +261
==========================================
+ Hits 51043 51057 +14
- Misses 19929 20176 +247
Partials 4499 4499
Continue to review full report at Codecov.
|
plugin/plugin.go
Outdated
return errors.Errorf("plugin %s isn't loaded so can not reload", p.Name) | ||
} | ||
if len(p.SysVars) != len(oldPlugin.SysVars) { | ||
return errors.Errorf("reload plugin with different sysVar is unsupported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best to define a plugin error category that we will need it sooner or later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's little confuse, so we should make plugin rely on parser's predefine error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tiancaiamao @jackysp message move to parser, please review parser first pingcap/parser#173
type ID string | ||
|
||
// Decode decodes a plugin id into name, version parts. | ||
func (n ID) Decode() (name string, version string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Plugin name should not contain '-'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decode has check a42f8e9#diff-51012a4c21599aa07955e2f374958792R40, refine msg in new commit, and pluginpkg also add a check 5bbc246
plugin/spi.go
Outdated
// ExportManifest exports a manifest to TiDB as a known format. | ||
// it just casts sub-manifest to manifest. | ||
func ExportManifest(m interface{}) *Manifest { | ||
return (*Manifest)((*(*iface)(unsafe.Pointer(&m))).Data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Manifest is not the first field in the extended manifest struct, this code broke.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but only tidb developer can add new kind of manifest, this can be restricted by code review(and it also has be documented); for plugin develop only touch toml configuration with predefine manifest
/run-all-tests |
LGTM |
ok~ @tiancaiamao now this PR use my parser branch so CI fail on tidy check, after parser PR shipped this will pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
What problem does this PR solve?
introduce plugin framework to tidb
What is changed and how it works?
How to use
here just a simple describe how to write a new plugin, later will give a full developer guide.
manifest.toml
like example onevalidate
,init
,destory
method which is needed for all plugincmd/pluginpkg
to build plugin binary, and put plugin binary into plugin deploy folder-plugin-dir
and-plugin-load
parametershow plugin
to check it's load statusWhat change
add a new plugin pkg, the design detail described in a proposal doc
Check List
Tests
Code changes
Side effects
Related changes
Code Review Guide
This change is