-
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
domain: fast new a etcd session when the session is stale in the schemaVersionSyncer #7774
Changes from all commits
58fcff5
deaf6f7
ed072c6
0d13ac6
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"github.com/grpc-ecosystem/go-grpc-prometheus" | ||
"github.com/ngaut/pools" | ||
"github.com/pingcap/tidb/ast" | ||
"github.com/pingcap/tidb/config" | ||
"github.com/pingcap/tidb/ddl" | ||
"github.com/pingcap/tidb/infoschema" | ||
"github.com/pingcap/tidb/kv" | ||
|
@@ -42,6 +43,7 @@ import ( | |
log "github.com/sirupsen/logrus" | ||
"golang.org/x/net/context" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/keepalive" | ||
) | ||
|
||
// Domain represents a storage space. Different domains can use the same database name. | ||
|
@@ -405,16 +407,16 @@ func (do *Domain) loadSchemaInLoop(lease time.Duration) { | |
case <-syncer.Done(): | ||
// The schema syncer stops, we need stop the schema validator to synchronize the schema version. | ||
log.Info("[ddl] reload schema in loop, schema syncer need restart") | ||
do.SchemaValidator.Stop() | ||
err := do.mustRestartSyncer() | ||
if err != nil { | ||
log.Errorf("[ddl] reload schema in loop, schema syncer restart err %v", errors.ErrorStack(err)) | ||
break | ||
} | ||
do.SchemaValidator.Restart() | ||
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. Need to add metrics here? 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. we already have metrics.NewSessionHistogram and metrics.DeploySyncerHistogram, I think there is no need to add here. 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. Got it. |
||
log.Info("[ddl] schema syncer restarted.") | ||
case <-do.info.Done(): | ||
log.Info("[ddl] reload schema in loop, server info syncer need restart") | ||
do.info.Restart(context.Background()) | ||
log.Info("[ddl] server info syncer restarted.") | ||
case <-do.exit: | ||
return | ||
} | ||
|
@@ -527,12 +529,19 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio | |
func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.Resource, error)) error { | ||
if ebd, ok := do.store.(EtcdBackend); ok { | ||
if addrs := ebd.EtcdAddrs(); addrs != nil { | ||
cfg := config.GetGlobalConfig() | ||
cli, err := clientv3.New(clientv3.Config{ | ||
Endpoints: addrs, | ||
DialTimeout: 5 * time.Second, | ||
DialOptions: []grpc.DialOption{ | ||
grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor), | ||
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor), | ||
grpc.WithBackoffMaxDelay(time.Second * 3), | ||
grpc.WithKeepaliveParams(keepalive.ClientParameters{ | ||
Time: time.Duration(cfg.TiKVClient.GrpcKeepAliveTime) * time.Second, | ||
Timeout: time.Duration(cfg.TiKVClient.GrpcKeepAliveTimeout) * time.Second, | ||
PermitWithoutStream: true, | ||
}), | ||
}, | ||
TLS: ebd.TLSConfig(), | ||
}) | ||
|
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.
Why change this?
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.
session is accessed in multi-thread.
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.
Can you talk about it in detail?
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.
loadSnapshotInfoSchemaIfNeeded will use the session, and loadSchemaLoop will too.
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.
Gotcha.