Skip to content

Commit

Permalink
session: add no register API for using TiDB as a library (#17513) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen authored Jul 15, 2020
1 parent e2c95ee commit c05ceac
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ type Config struct {
Experimental Experimental `toml:"experimental" json:"experimental"`
// EnableCollectExecutionInfo enables the TiDB to collect execution info.
EnableCollectExecutionInfo bool `toml:"enable-collect-execution-info" json:"enable-collect-execution-info"`
// SkipRegisterToDashboard tells TiDB don't register itself to the dashboard.
SkipRegisterToDashboard bool `toml:"skip-register-to-dashboard" json:"skip-register-to-dashboard"`
// EnableTelemetry enables the usage data report to PingCAP.
EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"`
}
Expand Down
5 changes: 5 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ max-server-connections = 0
# Whether new collations are enabled, as indicated by its name, this configuration entry take effect ONLY when a TiDB cluster bootstraps for the first time.
new_collations_enabled_on_first_bootstrap = false

# Don't register information of this TiDB to etcd, so this instance of TiDB won't appear in the services like dashboard.
# This option is useful when you want to embed TiDB into your service(i.e. use TiDB as a library).
# *If you want to start a TiDB service, NEVER enable this.*
skip-register-to-dashboard = false

# When enabled, usage data (for example, instance versions) will be reported to PingCAP periodically for user experience analytics.
# If this config is set to `false` on all TiDB servers, telemetry will be always disabled regardless of the value of the global variable `tidb_enable_telemetry`.
# See PingCAP privacy policy for details: https://pingcap.com/en/privacy-policy/
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ repair-mode = true
max-server-connections = 200
mem-quota-query = 10000
max-index-length = 3080
skip-register-to-dashboard = true
[performance]
txn-total-size-limit=2000
[tikv-client]
Expand Down Expand Up @@ -247,6 +248,7 @@ engines = ["tiflash"]
c.Assert(conf.Experimental.AllowAutoRandom, IsTrue)
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(conf.SkipRegisterToDashboard, Equals, true)

_, err = f.WriteString(`
[log.file]
Expand Down
9 changes: 6 additions & 3 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,12 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R
}
})

skipRegisterToDashboard := config.GetGlobalConfig().SkipRegisterToDashboard
err = do.ddl.SchemaSyncer().Init(ctx)
if err != nil {
return err
}
do.info, err = infosync.GlobalInfoSyncerInit(ctx, do.ddl.GetID(), do.etcdClient)
do.info, err = infosync.GlobalInfoSyncerInit(ctx, do.ddl.GetID(), do.etcdClient, skipRegisterToDashboard)
if err != nil {
return err
}
Expand All @@ -739,8 +740,10 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R
do.wg.Add(1)
go do.infoSyncerKeeper()

do.wg.Add(1)
go do.topologySyncerKeeper()
if !skipRegisterToDashboard {
do.wg.Add(1)
go do.topologySyncerKeeper()
}

return nil
}
Expand Down
9 changes: 6 additions & 3 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ func setGlobalInfoSyncer(is *InfoSyncer) {
}

// GlobalInfoSyncerInit return a new InfoSyncer. It is exported for testing.
func GlobalInfoSyncerInit(ctx context.Context, id string, etcdCli *clientv3.Client) (*InfoSyncer, error) {
func GlobalInfoSyncerInit(ctx context.Context, id string, etcdCli *clientv3.Client, skipRegisterToDashBoard bool) (*InfoSyncer, error) {
is := &InfoSyncer{
etcdCli: etcdCli,
info: getServerInfo(id),
serverInfoPath: fmt.Sprintf("%s/%s", ServerInformationPath, id),
minStartTSPath: fmt.Sprintf("%s/%s", ServerMinStartTSPath, id),
}
err := is.init(ctx)
err := is.init(ctx, skipRegisterToDashBoard)
if err != nil {
return nil, err
}
Expand All @@ -144,11 +144,14 @@ func GlobalInfoSyncerInit(ctx context.Context, id string, etcdCli *clientv3.Clie
}

// Init creates a new etcd session and stores server info to etcd.
func (is *InfoSyncer) init(ctx context.Context) error {
func (is *InfoSyncer) init(ctx context.Context, skipRegisterToDashboard bool) error {
err := is.newSessionAndStoreServerInfo(ctx, owner.NewSessionDefaultRetryCnt)
if err != nil {
return err
}
if skipRegisterToDashboard {
return nil
}
return is.newTopologySessionAndStoreServerInfo(ctx, owner.NewSessionDefaultRetryCnt)
}

Expand Down
2 changes: 1 addition & 1 deletion domain/infosync/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestTopology(t *testing.T) {
failpoint.Enable("github.com/pingcap/tidb/domain/infosync/mockServerInfo", "return(true)")
defer failpoint.Disable("github.com/pingcap/tidb/domain/infosync/mockServerInfo")

info, err := GlobalInfoSyncerInit(ctx, currentID, cli)
info, err := GlobalInfoSyncerInit(ctx, currentID, cli, false)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit c05ceac

Please sign in to comment.