Skip to content
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

session: add no register API for using TiDB as a library #17513

Merged
merged 20 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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"`
// NoRegister tells TiDB don't register itself to the dashboard.
NoRegister bool `toml:"no-register" json:"no-register"`
YuJuncen marked this conversation as resolved.
Show resolved Hide resolved
}

// UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed
Expand Down
5 changes: 5 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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.*
no-register = false

[log]
# Log level: debug, info, warn, error, fatal.
level = "info"
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ max-server-connections = 200
mem-quota-query = 10000
nested-loop-join-cache-capacity = 100
max-index-length = 3080
no-register = true
[performance]
txn-total-size-limit=2000
[tikv-client]
Expand Down Expand Up @@ -247,6 +248,7 @@ engines = ["tiflash"]
c.Assert(conf.Experimental.AllowsExpressionIndex, IsTrue)
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(conf.NoRegister, Equals, true)

_, err = f.WriteString(`
[log.file]
Expand Down
6 changes: 4 additions & 2 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,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 !config.GetGlobalConfig().NoRegister {
do.wg.Add(1)
go do.topologySyncerKeeper()
}

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (is *InfoSyncer) init(ctx context.Context) error {
if err != nil {
return err
}
if config.GetGlobalConfig().NoRegister {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd better to use config.GetGlobalConfig().NoRegister as a argument to GlobalInfoSyncerInit. It is best to reduce the strong correlation between internal objects and config.GetGlobalConfig().

return nil
}
return is.newTopologySessionAndStoreServerInfo(ctx, owner.NewSessionDefaultRetryCnt)
}

Expand Down
7 changes: 7 additions & 0 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sync/atomic"
"time"

"github.com/ngaut/pools"
"github.com/pingcap/errors"
"github.com/pingcap/parser"
"github.com/pingcap/parser/ast"
Expand All @@ -42,6 +43,12 @@ import (
"go.uber.org/zap"
)

type domainInitializer func(
YuJuncen marked this conversation as resolved.
Show resolved Hide resolved
dom *domain.Domain,
ddlLease time.Duration,
sysFactory func(*domain.Domain) (pools.Resource, error),
) error

type domainMap struct {
domains map[string]*domain.Domain
mu sync.Mutex
Expand Down