@@ -24,7 +24,7 @@ import (
24
24
"github.com/gin-gonic/gin"
25
25
"github.com/pingcap/errors"
26
26
"github.com/pingcap/log"
27
- tidbkv "github.com/pingcap/tidb/kv"
27
+ "github.com/pingcap/tidb/kv"
28
28
"github.com/pingcap/tiflow/cdc/api"
29
29
"github.com/pingcap/tiflow/cdc/capture"
30
30
"github.com/pingcap/tiflow/cdc/model"
@@ -57,30 +57,34 @@ func (h *OpenAPIV2) createChangefeed(c *gin.Context) {
57
57
_ = c .Error (cerror .WrapError (cerror .ErrAPIInvalidParam , err ))
58
58
return
59
59
}
60
+ var pdClient pd.Client
61
+ var kvStorage kv.Storage
62
+ // if PDAddrs is empty, use the default pdClient
60
63
if len (cfg .PDAddrs ) == 0 {
61
64
up , err := getCaptureDefaultUpstream (h .capture )
62
65
if err != nil {
63
66
_ = c .Error (err )
64
67
return
65
68
}
66
- cfg .PDConfig = getUpstreamPDConfig (up )
67
- }
68
- credential := cfg .PDConfig .toCredential ()
69
-
70
- timeoutCtx , cancel := context .WithTimeout (ctx , 30 * time .Second )
71
- defer cancel ()
72
- pdClient , err := h .helpers .getPDClient (timeoutCtx , cfg .PDAddrs , credential )
73
- if err != nil {
74
- _ = c .Error (cerror .WrapError (cerror .ErrAPIGetPDClientFailed , err ))
75
- return
76
- }
77
- defer pdClient .Close ()
78
-
79
- // verify tables todo: del kvstore
80
- kvStorage , err := h .helpers .createTiStore (cfg .PDAddrs , credential )
81
- if err != nil {
82
- _ = c .Error (cerror .WrapError (cerror .ErrNewStore , err ))
83
- return
69
+ pdClient = up .PDClient
70
+ kvStorage = up .KVStorage
71
+ } else {
72
+ credential := cfg .PDConfig .toCredential ()
73
+ timeoutCtx , cancel := context .WithTimeout (ctx , 30 * time .Second )
74
+ defer cancel ()
75
+ var err error
76
+ pdClient , err = h .helpers .getPDClient (timeoutCtx , cfg .PDAddrs , credential )
77
+ if err != nil {
78
+ _ = c .Error (cerror .WrapError (cerror .ErrAPIGetPDClientFailed , err ))
79
+ return
80
+ }
81
+ defer pdClient .Close ()
82
+ // verify tables todo: del kvstore
83
+ kvStorage , err = h .helpers .createTiStore (cfg .PDAddrs , credential )
84
+ if err != nil {
85
+ _ = c .Error (cerror .WrapError (cerror .ErrNewStore , err ))
86
+ return
87
+ }
84
88
}
85
89
// We should not close kvStorage since all kvStorage in cdc is the same one.
86
90
// defer kvStorage.Close()
@@ -245,21 +249,25 @@ func (h *OpenAPIV2) verifyTable(c *gin.Context) {
245
249
_ = c .Error (cerror .WrapError (cerror .ErrAPIInvalidParam , err ))
246
250
return
247
251
}
252
+ var kvStore kv.Storage
253
+ // if PDAddrs is empty, use the default upstream
248
254
if len (cfg .PDAddrs ) == 0 {
249
255
up , err := getCaptureDefaultUpstream (h .capture )
250
256
if err != nil {
251
257
_ = c .Error (err )
252
258
return
253
259
}
254
- cfg .PDConfig = getUpstreamPDConfig (up )
260
+ kvStore = up .KVStorage
261
+ } else {
262
+ credential := cfg .PDConfig .toCredential ()
263
+ var err error
264
+ kvStore , err = h .helpers .createTiStore (cfg .PDAddrs , credential )
265
+ if err != nil {
266
+ _ = c .Error (errors .Trace (err ))
267
+ return
268
+ }
255
269
}
256
- credential := cfg .PDConfig .toCredential ()
257
270
258
- kvStore , err := h .helpers .createTiStore (cfg .PDAddrs , credential )
259
- if err != nil {
260
- _ = c .Error (err )
261
- return
262
- }
263
271
replicaCfg := cfg .ReplicaConfig .ToInternalReplicaConfig ()
264
272
ineligibleTables , eligibleTables , err := h .helpers .
265
273
getVerfiedTables (replicaCfg , kvStore , cfg .StartTs )
@@ -353,7 +361,7 @@ func (h *OpenAPIV2) updateChangefeed(c *gin.Context) {
353
361
return
354
362
}
355
363
356
- var storage tidbkv .Storage
364
+ var storage kv .Storage
357
365
// if PDAddrs is not empty, use it to create a new kvstore
358
366
// Note: upManager is nil in some unit test cases
359
367
if len (updateCfConfig .PDAddrs ) != 0 || upManager == nil {
@@ -789,48 +797,55 @@ func (h *OpenAPIV2) synced(c *gin.Context) {
789
797
cfg .ReplicaConfig .SyncedStatus .CheckpointInterval = status .CheckpointInterval
790
798
cfg .ReplicaConfig .SyncedStatus .SyncedCheckInterval = status .SyncedCheckInterval
791
799
}
800
+ if c .Request .Body != nil && c .Request .ContentLength > 0 {
801
+ if err := c .BindJSON (cfg ); err != nil {
802
+ _ = c .Error (cerror .WrapError (cerror .ErrAPIInvalidParam , err ))
803
+ return
804
+ }
805
+ }
792
806
793
807
// try to get pd client to get pd time, and determine synced status based on the pd time
808
+ var pdClient pd.Client
794
809
if len (cfg .PDAddrs ) == 0 {
795
810
up , err := getCaptureDefaultUpstream (h .capture )
796
811
if err != nil {
797
812
_ = c .Error (err )
798
813
return
799
814
}
800
- cfg .PDConfig = getUpstreamPDConfig (up )
801
- }
802
- credential := cfg .PDConfig .toCredential ()
803
-
804
- timeoutCtx , cancel := context .WithTimeout (ctx , timeout )
805
- defer cancel ()
815
+ pdClient = up .PDClient
816
+ } else {
817
+ credential := cfg .PDConfig .toCredential ()
818
+ timeoutCtx , cancel := context .WithTimeout (ctx , timeout )
819
+ defer cancel ()
806
820
807
- pdClient , err := h .helpers .getPDClient (timeoutCtx , cfg .PDAddrs , credential )
808
- if err != nil {
809
- // case 1. we can't get pd client, pd may be unavailable.
810
- // if pullerResolvedTs - checkpointTs > checkpointInterval, data is not synced
811
- // otherwise, if pd is unavailable, we decide data whether is synced based on
812
- // the time difference between current time and lastSyncedTs.
813
- var message string
814
- if (oracle .ExtractPhysical (status .PullerResolvedTs ) - oracle .ExtractPhysical (status .CheckpointTs )) >
815
- cfg .ReplicaConfig .SyncedStatus .CheckpointInterval * 1000 {
816
- message = fmt .Sprintf ("%s. Besides the data is not finish syncing" , err .Error ())
817
- } else {
818
- message = fmt .Sprintf ("%s. You should check the pd status first. If pd status is normal, means we don't finish sync data. " +
819
- "If pd is offline, please check whether we satisfy the condition that " +
820
- "the time difference from lastSyncedTs to the current time from the time zone of pd is greater than %v secs. " +
821
- "If it's satisfied, means the data syncing is totally finished" , err , cfg .ReplicaConfig .SyncedStatus .SyncedCheckInterval )
821
+ pdClient , err = h .helpers .getPDClient (timeoutCtx , cfg .PDAddrs , credential )
822
+ if err != nil {
823
+ // case 1. we can't get pd client, pd may be unavailable.
824
+ // if pullerResolvedTs - checkpointTs > checkpointInterval, data is not synced
825
+ // otherwise, if pd is unavailable, we decide data whether is synced based on
826
+ // the time difference between current time and lastSyncedTs.
827
+ var message string
828
+ if (oracle .ExtractPhysical (status .PullerResolvedTs ) - oracle .ExtractPhysical (status .CheckpointTs )) >
829
+ cfg .ReplicaConfig .SyncedStatus .CheckpointInterval * 1000 {
830
+ message = fmt .Sprintf ("%s. Besides the data is not finish syncing" , err .Error ())
831
+ } else {
832
+ message = fmt .Sprintf ("%s. You should check the pd status first. If pd status is normal, means we don't finish sync data. " +
833
+ "If pd is offline, please check whether we satisfy the condition that " +
834
+ "the time difference from lastSyncedTs to the current time from the time zone of pd is greater than %v secs. " +
835
+ "If it's satisfied, means the data syncing is totally finished" , err , cfg .ReplicaConfig .SyncedStatus .SyncedCheckInterval )
836
+ }
837
+ c .JSON (http .StatusOK , SyncedStatus {
838
+ Synced : false ,
839
+ SinkCheckpointTs : model .JSONTime (oracle .GetTimeFromTS (status .CheckpointTs )),
840
+ PullerResolvedTs : model .JSONTime (oracle .GetTimeFromTS (status .PullerResolvedTs )),
841
+ LastSyncedTs : model .JSONTime (oracle .GetTimeFromTS (status .LastSyncedTs )),
842
+ NowTs : model .JSONTime (time .Unix (0 , 0 )),
843
+ Info : message ,
844
+ })
845
+ return
822
846
}
823
- c .JSON (http .StatusOK , SyncedStatus {
824
- Synced : false ,
825
- SinkCheckpointTs : model .JSONTime (oracle .GetTimeFromTS (status .CheckpointTs )),
826
- PullerResolvedTs : model .JSONTime (oracle .GetTimeFromTS (status .PullerResolvedTs )),
827
- LastSyncedTs : model .JSONTime (oracle .GetTimeFromTS (status .LastSyncedTs )),
828
- NowTs : model .JSONTime (time .Unix (0 , 0 )),
829
- Info : message ,
830
- })
831
- return
847
+ defer pdClient .Close ()
832
848
}
833
- defer pdClient .Close ()
834
849
// get time from pd
835
850
physicalNow , _ , _ := pdClient .GetTS (ctx )
836
851
@@ -950,12 +965,3 @@ func getCaptureDefaultUpstream(cp capture.Capture) (*upstream.Upstream, error) {
950
965
}
951
966
return up , nil
952
967
}
953
-
954
- func getUpstreamPDConfig (up * upstream.Upstream ) PDConfig {
955
- return PDConfig {
956
- PDAddrs : up .PdEndpoints ,
957
- KeyPath : up .SecurityConfig .KeyPath ,
958
- CAPath : up .SecurityConfig .CAPath ,
959
- CertPath : up .SecurityConfig .CertPath ,
960
- }
961
- }
0 commit comments