-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: support renew lease for read operation on cached table #29840
Changes from 18 commits
7dd848e
332c11a
ea991a2
7734a44
2485db3
3024cf4
73c4050
3a35566
1531867
cacd897
f4abff4
c9bad74
2934379
adb83cb
2009265
9108e9e
a6f8369
fedf01c
2000cc1
0e575c5
48b41f1
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 |
---|---|---|
|
@@ -93,8 +93,8 @@ type Domain struct { | |
serverID uint64 | ||
serverIDSession *concurrency.Session | ||
isLostConnectionToPD sync2.AtomicInt32 // !0: true, 0: false. | ||
|
||
onClose func() | ||
renewLeaseCh chan func() // It is used to call the renewLease function of the cache table. | ||
onClose func() | ||
} | ||
|
||
// loadInfoSchema loads infoschema at startTS. | ||
|
@@ -159,7 +159,7 @@ func (do *Domain) loadInfoSchema(startTS uint64) (infoschema.InfoSchema, bool, i | |
return nil, false, currentSchemaVersion, nil, err | ||
} | ||
|
||
newISBuilder, err := infoschema.NewBuilder(do.Store()).InitWithDBInfos(schemas, bundles, policies, neededSchemaVersion) | ||
newISBuilder, err := infoschema.NewBuilder(do.Store(), do.renewLeaseCh).InitWithDBInfos(schemas, bundles, policies, neededSchemaVersion) | ||
if err != nil { | ||
return nil, false, currentSchemaVersion, nil, err | ||
} | ||
|
@@ -271,7 +271,7 @@ func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64 | |
} | ||
diffs = append(diffs, diff) | ||
} | ||
builder := infoschema.NewBuilder(do.Store()).InitWithOldInfoSchema(do.infoCache.GetLatest()) | ||
builder := infoschema.NewBuilder(do.Store(), do.renewLeaseCh).InitWithOldInfoSchema(do.infoCache.GetLatest()) | ||
phyTblIDs := make([]int64, 0, len(diffs)) | ||
actions := make([]uint64, 0, len(diffs)) | ||
for _, diff := range diffs { | ||
|
@@ -287,6 +287,7 @@ func (do *Domain) tryLoadSchemaDiffs(m *meta.Meta, usedVersion, newVersion int64 | |
actions = append(actions, uint64(1<<diff.Type)) | ||
} | ||
} | ||
|
||
is := builder.Build() | ||
relatedChange := transaction.RelatedSchemaChange{} | ||
relatedChange.PhyTblIDS = phyTblIDs | ||
|
@@ -406,7 +407,6 @@ func (do *Domain) Reload() error { | |
|
||
// lease renew, so it must be executed despite it is cache or not | ||
do.SchemaValidator.Update(ver.Ver, oldSchemaVersion, is.SchemaMetaVersion(), changes) | ||
|
||
lease := do.DDL().GetLease() | ||
sub := time.Since(startTime) | ||
// Reload interval is lease / 2, if load schema time elapses more than this interval, | ||
|
@@ -700,6 +700,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio | |
indexUsageSyncLease: idxUsageSyncLease, | ||
planReplayer: &planReplayer{planReplayerGCLease: planReplayerGCLease}, | ||
onClose: onClose, | ||
renewLeaseCh: make(chan func(), 10), | ||
} | ||
|
||
do.SchemaValidator = NewSchemaValidator(ddlLease, do) | ||
|
@@ -824,11 +825,11 @@ func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.R | |
// Local store needs to get the change information for every DDL state in each session. | ||
go do.loadSchemaInLoop(ctx, ddlLease) | ||
} | ||
do.wg.Add(3) | ||
do.wg.Add(4) | ||
go do.topNSlowQueryLoop() | ||
go do.infoSyncerKeeper() | ||
go do.renewLease() | ||
go do.globalConfigSyncerKeeper() | ||
|
||
if !skipRegisterToDashboard { | ||
do.wg.Add(1) | ||
go do.topologySyncerKeeper() | ||
|
@@ -1729,6 +1730,22 @@ func (do *Domain) MockInfoCacheAndLoadInfoSchema(is infoschema.InfoSchema) { | |
do.infoCache.Insert(is, 0) | ||
} | ||
|
||
func (do *Domain) renewLease() { | ||
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 a global gorountine |
||
defer func() { | ||
do.wg.Done() | ||
logutil.BgLogger().Info("renew lease goroutine exited.") | ||
}() | ||
for { | ||
select { | ||
case <-do.exit: | ||
close(do.renewLeaseCh) | ||
return | ||
case op := <-do.renewLeaseCh: | ||
JayLZhou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
op() | ||
} | ||
} | ||
} | ||
|
||
func init() { | ||
initByLDFlagsForGlobalKill() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ type Builder struct { | |
// TODO: store is only used by autoid allocators | ||
// detach allocators from storage, use passed transaction in the feature | ||
store kv.Storage | ||
// TODO: renewLeaseCh is only used to pass data between table and domain | ||
renewLeaseCh chan func() | ||
} | ||
|
||
// ApplyDiff applies SchemaDiff to the new InfoSchema. | ||
|
@@ -438,7 +440,7 @@ func (b *Builder) applyCreateTable(m *meta.Meta, dbInfo *model.DBInfo, tableID i | |
} | ||
} | ||
} | ||
tbl, err := tables.TableFromMeta(allocs, tblInfo) | ||
tbl, err := b.tableFromMeta(allocs, tblInfo) | ||
JayLZhou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
@@ -601,7 +603,7 @@ func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, bundles []*placement. | |
} | ||
|
||
for _, di := range dbInfos { | ||
err := b.createSchemaTablesForDB(di, tables.TableFromMeta) | ||
err := b.createSchemaTablesForDB(di, b.tableFromMeta) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
@@ -622,6 +624,20 @@ func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, bundles []*placement. | |
return b, nil | ||
} | ||
|
||
func (b *Builder) tableFromMeta(alloc autoid.Allocators, tblInfo *model.TableInfo) (table.Table, error) { | ||
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. Newline before this function; |
||
ret, err := tables.TableFromMeta(alloc, tblInfo) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
if t, ok := ret.(table.CachedTable); ok { | ||
err = t.Init(b.renewLeaseCh) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
} | ||
return ret, nil | ||
} | ||
|
||
type tableFromMetaFunc func(alloc autoid.Allocators, tblInfo *model.TableInfo) (table.Table, error) | ||
|
||
func (b *Builder) createSchemaTablesForDB(di *model.DBInfo, tableFromMeta tableFromMetaFunc) error { | ||
|
@@ -658,7 +674,7 @@ func RegisterVirtualTable(dbInfo *model.DBInfo, tableFromMeta tableFromMetaFunc) | |
} | ||
|
||
// NewBuilder creates a new Builder with a Handle. | ||
func NewBuilder(store kv.Storage) *Builder { | ||
func NewBuilder(store kv.Storage, renewCh chan func()) *Builder { | ||
return &Builder{ | ||
store: store, | ||
is: &infoSchema{ | ||
|
@@ -667,6 +683,7 @@ func NewBuilder(store kv.Storage) *Builder { | |
ruleBundleMap: map[string]*placement.Bundle{}, | ||
sortedTablesBuckets: make([]sortedTables, bucketCount), | ||
}, | ||
renewLeaseCh: renewCh, | ||
} | ||
} | ||
|
||
|
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.
now you have used the
var wg util.WaitGroupWrapper
and you can simplify the code like here.tidb/br/pkg/lightning/restore/checksum_test.go
Line 100 in b266d7d
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.
you can only change the
renewLease
for using theRun
ofWaitGroupWrapper
.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.
the other leave it as it is because
WaitGroupWrapper
is compatible withWaitGroup
.