Skip to content

Commit 7fe1319

Browse files
authored
TiManager: fix refresh did not work (#6152)
1 parent 467e862 commit 7fe1319

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

pkg/timanager/apis/pd/v1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type StoreState string
8686
const (
8787
StoreStateUp StoreState = "Up"
8888
StoreStateOffline StoreState = "Offline"
89-
StoreStateTombstore StoreState = "Tombstone"
89+
StoreStateTombstone StoreState = "Tombstone"
9090
)
9191

9292
type NodeState string

pkg/timanager/informer.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,18 @@ func (f *factory[UnderlayClient]) InformerFor(obj runtime.Object) cache.SharedIn
151151
return informer
152152
}
153153

154-
poller, ok := f.pollers[informerType]
154+
p, ok := f.pollers[informerType]
155155
if !ok {
156-
newPollerFunc, ok := f.newPollerFuncMap[informerType]
157-
if !ok {
156+
newPollerFunc, ok2 := f.newPollerFuncMap[informerType]
157+
if !ok2 {
158158
// TODO: fix it
159159
panic("unrecognized type")
160160
}
161-
poller = newPollerFunc(f.name, f.logger, f.c)
161+
p = newPollerFunc(f.name, f.logger, f.c)
162+
f.pollers[informerType] = p
162163
}
163164

164-
lw := NewListerWatcher[UnderlayClient](f.logger, poller)
165+
lw := NewListerWatcher[UnderlayClient](f.logger, p)
165166

166167
informer = cache.NewSharedIndexInformer(
167168
lw,
@@ -179,11 +180,12 @@ func (f *factory[UnderlayClient]) Refresh(obj runtime.Object) {
179180
defer f.lock.Unlock()
180181

181182
informerType := reflect.TypeOf(obj)
182-
poller, ok := f.pollers[informerType]
183+
p, ok := f.pollers[informerType]
183184
if !ok {
185+
f.logger.Info("no poller for type", "type", informerType)
184186
return
185187
}
186-
poller.Refresh()
188+
p.Refresh()
187189
}
188190

189191
type ListerWatcher[UnderlayClient any] interface {

pkg/timanager/pd/pd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func SplitPrimaryKey(key string) (ns, cluster string) {
109109
// If any keys are changed, client will be renewed
110110
// The first key is primary key to get client from manager
111111
func CacheKeys(pdg *v1alpha1.PDGroup) ([]string, error) {
112-
keys := []string{}
112+
var keys []string
113113

114114
keys = append(keys,
115115
PrimaryKey(pdg.Namespace, pdg.Spec.Cluster.Name), // cluster name as primary key

pkg/timanager/poller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Poller interface {
3737
// IF Run is called multiple times, the previous one will be stopped
3838
// immediately and start a new one to push event to new channel
3939
Run(ctx context.Context, ch chan<- watch.Event)
40-
// Poll once immediately
40+
// Refresh once immediately
4141
Refresh()
4242
}
4343

@@ -59,11 +59,12 @@ func NewPoller[T any, PT Object[T], L client.ObjectList](
5959
interval time.Duration,
6060
) Poller {
6161
return &poller[T, PT, L]{
62-
name: name,
63-
interval: interval,
64-
lister: lister,
65-
equality: eq,
66-
logger: logger,
62+
name: name,
63+
interval: interval,
64+
lister: lister,
65+
equality: eq,
66+
logger: logger,
67+
refreshCh: make(chan struct{}, bufSize),
6768
}
6869
}
6970

0 commit comments

Comments
 (0)