From f9d6172fc6129e26be1d36c7db4644cd6c2e1bf0 Mon Sep 17 00:00:00 2001 From: CharlesCheung Date: Mon, 7 Mar 2022 14:23:10 +0800 Subject: [PATCH] capture(ticdc): fix the problem that openapi is blocked when pd is abnormal (#4778) --- cdc/capture/capture.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cdc/capture/capture.go b/cdc/capture/capture.go index 535d59e7185..6343bc043a9 100644 --- a/cdc/capture/capture.go +++ b/cdc/capture/capture.go @@ -118,9 +118,17 @@ func NewCapture4Test(o owner.Owner) *Capture { } func (c *Capture) reset(ctx context.Context) error { + conf := config.GetGlobalServerConfig() + sess, err := concurrency.NewSession(c.EtcdClient.Client.Unwrap(), + concurrency.WithTTL(conf.CaptureSessionTTL)) + if err != nil { + return errors.Annotate( + cerror.WrapError(cerror.ErrNewCaptureFailed, err), + "create capture session") + } + c.captureMu.Lock() defer c.captureMu.Unlock() - conf := config.GetGlobalServerConfig() c.info = &model.CaptureInfo{ ID: uuid.New().String(), AdvertiseAddr: conf.AdvertiseAddr, @@ -131,13 +139,6 @@ func (c *Capture) reset(ctx context.Context) error { // It can't be handled even after it fails, so we ignore it. _ = c.session.Close() } - sess, err := concurrency.NewSession(c.EtcdClient.Client.Unwrap(), - concurrency.WithTTL(conf.CaptureSessionTTL)) - if err != nil { - return errors.Annotate( - cerror.WrapError(cerror.ErrNewCaptureFailed, err), - "create capture session") - } c.session = sess c.election = concurrency.NewElection(sess, etcd.CaptureOwnerKey)