-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathplugin.go
More file actions
76 lines (69 loc) · 1.8 KB
/
plugin.go
File metadata and controls
76 lines (69 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
}