-
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
store TiDB server info to PD and add http api handle #7082
Changes from 1 commit
3918624
2370bb0
b574aff
aca6b97
d5a1922
3c8f418
24eea21
f0007a4
159a7b4
f143709
256798e
8bd6c3d
80cdd6a
20e372f
839f298
bb2f009
ed0217e
d0c1925
a925b92
5fdba0b
73ea84f
440953f
9815df2
321cf31
027c983
c2ff1e5
8baa5be
be06280
8697127
38e30f1
c814267
9d091c9
ea275c1
33d26a0
750407c
ec488e9
b40cf74
c32d982
7403bb1
3801efe
b27b804
11dfd86
7fb9c1a
c4586ea
b7b35e3
d54c1ce
01eed94
6060b57
2a97788
2da0623
26c8b25
93c76ce
f8b7b98
9831a1f
34d12be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,6 +365,7 @@ func (do *Domain) loadSchemaInLoop(lease time.Duration) { | |
break | ||
} | ||
do.SchemaValidator.Restart() | ||
do.info.Restart(syncer.GetSessionLeaseID()) | ||
case <-do.exit: | ||
return | ||
} | ||
|
@@ -509,7 +510,7 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R | |
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
do.info = NewInfoSyncer(do.ddl.GetID(), do.etcdClient) | ||
do.info = NewInfoSyncer(do.ddl.GetID(), do.etcdClient, do.ddl.SchemaSyncer().GetSessionLeaseID()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. umm, could we create a new session in infoSyncer, like we do in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
err = do.info.StoreServerInfo(ctx) | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,8 @@ type InfoSyncer struct { | |
etcdCli *clientv3.Client | ||
info *ServerInfo | ||
serverInfoPath string | ||
// InfoSyncer will reuse the leaseID of ddl.SchemaSyncer. | ||
sessionLeaseID clientv3.LeaseID | ||
} | ||
|
||
// ServerInfo is server static information. | ||
|
@@ -63,28 +65,15 @@ type ServerVersionInfo struct { | |
} | ||
|
||
// NewInfoSyncer return new InfoSyncer. It is exported for testing. | ||
func NewInfoSyncer(id string, etcdCli *clientv3.Client) *InfoSyncer { | ||
func NewInfoSyncer(id string, etcdCli *clientv3.Client, leaseID clientv3.LeaseID) *InfoSyncer { | ||
return &InfoSyncer{ | ||
etcdCli: etcdCli, | ||
info: getServerInfo(id), | ||
serverInfoPath: fmt.Sprintf("%s/%s", ServerInformationPath, id), | ||
sessionLeaseID: leaseID, | ||
} | ||
} | ||
|
||
func getServerInfo(id string) *ServerInfo { | ||
cfg := config.GetGlobalConfig() | ||
info := &ServerInfo{ | ||
ID: id, | ||
IP: cfg.AdvertiseAddress, | ||
Port: cfg.Port, | ||
StatusPort: cfg.Status.StatusPort, | ||
Lease: cfg.Lease, | ||
} | ||
info.Version = mysql.ServerVersion | ||
info.GitHash = printer.TiDBGitHash | ||
return info | ||
} | ||
|
||
//GetServerInfo gets self server static information. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/ |
||
func (is *InfoSyncer) GetServerInfo() *ServerInfo { | ||
return is.info | ||
|
@@ -130,7 +119,7 @@ func (is *InfoSyncer) StoreServerInfo(ctx context.Context) error { | |
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
err = ddl.PutKVToEtcd(ctx, is.etcdCli, keyOpDefaultRetryCnt, is.serverInfoPath, hack.String(infoBuf)) | ||
err = ddl.PutKVToEtcd(ctx, is.etcdCli, keyOpDefaultRetryCnt, is.serverInfoPath, hack.String(infoBuf), clientv3.WithLease(is.sessionLeaseID)) | ||
return errors.Trace(err) | ||
} | ||
|
||
|
@@ -145,6 +134,12 @@ func (is *InfoSyncer) RemoveServerInfo() { | |
} | ||
} | ||
|
||
// Restart restart the info syncer with new session leaseID and store server info to etcd again. | ||
func (is *InfoSyncer) Restart(leaseID clientv3.LeaseID) { | ||
is.sessionLeaseID = leaseID | ||
is.StoreServerInfo(context.Background()) | ||
} | ||
|
||
// getInfo gets server information from Etcd according to the key and opts. | ||
func getInfo(ctx context.Context, etcdCli *clientv3.Client, key string, retryCnt int, timeout time.Duration, opts ...clientv3.OpOption) (map[string]*ServerInfo, error) { | ||
var err error | ||
|
@@ -178,3 +173,18 @@ func getInfo(ctx context.Context, etcdCli *clientv3.Client, key string, retryCnt | |
} | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
// getServerInfo gets self tidb server information. | ||
func getServerInfo(id string) *ServerInfo { | ||
cfg := config.GetGlobalConfig() | ||
info := &ServerInfo{ | ||
ID: id, | ||
IP: cfg.AdvertiseAddress, | ||
Port: cfg.Port, | ||
StatusPort: cfg.Status.StatusPort, | ||
Lease: cfg.Lease, | ||
} | ||
info.Version = mysql.ServerVersion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not move the two lines into the above block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
info.GitHash = printer.TiDBGitHash | ||
return info | ||
} |
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.
s/GetSessionLeaseID/GetLeaseID/