-
Notifications
You must be signed in to change notification settings - Fork 130
Drainer support plugin framework #977
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
Open
tsthght
wants to merge
3
commits into
pingcap:master
Choose a base branch
from
tsthght:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package sync | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/pingcap/log" | ||
| "github.com/pingcap/tidb-binlog/drainer/loopbacksync" | ||
| "github.com/pingcap/tidb-binlog/drainer/relay" | ||
| "github.com/pingcap/tidb-binlog/drainer/translator" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| //SyncerDemo is a syncer demo | ||
| type SyncerDemo struct { | ||
| *baseSyncer | ||
| } | ||
|
|
||
| //Sync is the method that interface must implement | ||
| func (sd *SyncerDemo) Sync(item *Item) error { | ||
| //demo | ||
| log.Info("item", zap.String("%s", fmt.Sprintf("%v", item))) | ||
| sd.success <- item | ||
| return nil | ||
| } | ||
|
|
||
| //Close is the method that interface must implement | ||
| func (sd *SyncerDemo) Close() error { | ||
| return nil | ||
| } | ||
|
|
||
| //SetSafeMode is the method that interface must implement | ||
| func (sd *SyncerDemo) SetSafeMode(mode bool) bool { | ||
| return false | ||
| } | ||
|
|
||
| //NewSyncerDemo is a syncer demo | ||
| func NewSyncerDemo( | ||
| cfg *DBConfig, | ||
| file string, | ||
| tableInfoGetter translator.TableInfoGetter, | ||
| worker int, | ||
| batchSize int, | ||
| queryHistogramVec *prometheus.HistogramVec, | ||
| sqlMode *string, | ||
| destDBType string, | ||
| relayer relay.Relayer, | ||
| info *loopbacksync.LoopBackSync, | ||
| enableDispatch bool, | ||
| enableCausility bool, | ||
| ) (Syncer, error) { | ||
| log.Info("call NewSyncerDemo()") | ||
| executor := &SyncerDemo{} | ||
| executor.baseSyncer = newBaseSyncer(tableInfoGetter) | ||
| return executor, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package syncplg | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "plugin" | ||
|
|
||
| "github.com/pingcap/tidb-binlog/drainer/loopbacksync" | ||
| "github.com/pingcap/tidb-binlog/drainer/relay" | ||
| "github.com/pingcap/tidb-binlog/drainer/sync" | ||
| "github.com/pingcap/tidb-binlog/drainer/translator" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| const ( | ||
| //NewPlugin is the name of exported function by syncer plugin | ||
| NewPlugin = "NewPluginFactory" | ||
| ) | ||
|
|
||
| //FactoryInterface is interface of Factory | ||
| type FactoryInterface interface { | ||
| NewSyncerPlugin( | ||
| cfg *sync.DBConfig, | ||
| file string, | ||
| tableInfoGetter translator.TableInfoGetter, | ||
| worker int, | ||
| batchSize int, | ||
| queryHistogramVec *prometheus.HistogramVec, | ||
| sqlMode *string, | ||
| destDBType string, | ||
| relayer relay.Relayer, | ||
| info *loopbacksync.LoopBackSync, | ||
| enableDispatch bool, | ||
| enableCausility bool, | ||
| ) (sync.Syncer, error) | ||
| } | ||
|
|
||
| //NewSyncerFunc is a function type which syncer plugin must implement | ||
| type NewSyncerFunc func( | ||
| cfg *sync.DBConfig, | ||
| file string, | ||
| tableInfoGetter translator.TableInfoGetter, | ||
| worker int, | ||
| batchSize int, | ||
| queryHistogramVec *prometheus.HistogramVec, | ||
| sqlMode *string, | ||
| destDBType string, | ||
| relayer relay.Relayer, | ||
| info *loopbacksync.LoopBackSync, | ||
| enableDispatch bool, | ||
| enableCausility bool, | ||
| ) (sync.Syncer, error) | ||
|
|
||
| //LoadPlugin load syncer plugin | ||
| func LoadPlugin(path, name string) (NewSyncerFunc, error) { | ||
| fp := path + "/" + name | ||
| p, err := plugin.Open(fp) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("faile to Open %s . err: %s", fp, err.Error()) | ||
| } | ||
|
|
||
| sym, err := p.Lookup(NewPlugin) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| newFactory, ok := sym.(func() interface{}) | ||
| if !ok { | ||
| return nil, errors.New("function type is incorrect") | ||
| } | ||
| fac := newFactory() | ||
| plg, ok := fac.(FactoryInterface) | ||
| if !ok { | ||
| return nil, errors.New("not implement FactoryInterface") | ||
| } | ||
| return plg.NewSyncerPlugin, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| plugin: | ||
| go build -o syncerdemo.so -buildmode=plugin syncerdemo.go | ||
| clean: | ||
| rm -rf syncerdemo.so |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/pingcap/log" | ||
| "github.com/pingcap/tidb-binlog/drainer/loopbacksync" | ||
| "github.com/pingcap/tidb-binlog/drainer/relay" | ||
| "github.com/pingcap/tidb-binlog/drainer/sync" | ||
| "github.com/pingcap/tidb-binlog/drainer/translator" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| ) | ||
|
|
||
| //PluginFactory is the Factory struct | ||
| type PluginFactory struct{} | ||
|
|
||
| //NewPluginFactory is factory function of plugin | ||
| func NewPluginFactory() interface{} { | ||
| log.Info("call NewPluginFactory") | ||
| return PluginFactory{} | ||
| } | ||
|
|
||
| //NewSyncerPlugin return A syncer instance which implemented interface of sync.Syncer | ||
| func (pf PluginFactory) NewSyncerPlugin( | ||
| cfg *sync.DBConfig, | ||
| file string, | ||
| tableInfoGetter translator.TableInfoGetter, | ||
| worker int, | ||
| batchSize int, | ||
| queryHistogramVec *prometheus.HistogramVec, | ||
| sqlMode *string, | ||
| destDBType string, | ||
| relayer relay.Relayer, | ||
| info *loopbacksync.LoopBackSync, | ||
| enableDispatch bool, | ||
| enableCausility bool, | ||
| ) (sync.Syncer, error) { | ||
| return sync.NewSyncerDemo(cfg, file, tableInfoGetter, worker, batchSize, queryHistogramVec, sqlMode, | ||
| destDBType, relayer, info, enableDispatch, enableCausility) | ||
| } | ||
|
|
||
| var _ PluginFactory | ||
| var _ = NewPluginFactory() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
how about adding some comments for how to use these arguments? For example, I don't know what the
fileused for.Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks, I had writen a README.md. PTAL @WangXiangUSTC