Skip to content

Commit b9b2f10

Browse files
authored
fix(tidb): fix missing topology when adopting (#6509)
1 parent 93de38c commit b9b2f10

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

pkg/adoption/manager.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (m *manager) register(db *v1alpha1.TiDB) {
143143
}
144144
m.standby.add(hash, key)
145145

146-
m.logger.Info("register standby instance", "instance", key, "hash", hash)
146+
m.logger.Info("register standby instance", "instance", key, "hash", hash, "rv", db.GetResourceVersion())
147147

148148
return
149149
}
@@ -161,6 +161,8 @@ func (m *manager) register(db *v1alpha1.TiDB) {
161161

162162
item.hash = nHash
163163
item.instance = db.DeepCopy()
164+
165+
m.logger.Info("update standby instance", "instance", key, "hash", nHash, "rv", db.GetResourceVersion())
164166
// - applied and uid is not changed
165167
// - instance has been adopted and mode is changed to normal.
166168
// - just wait until the instance is synced.
@@ -199,10 +201,16 @@ func (m *manager) Adopt(dbg *v1alpha1.TiDBGroup, index int) (*v1alpha1.TiDB, Unl
199201
adopting := m.adopting.list(key)
200202
if index < len(adopting) {
201203
inKey := adopting[index]
204+
// should always exist
205+
item := m.keyToInstance[inKey]
202206

203-
m.logger.Info("return adopting standby instance", "group", key, "instance", inKey, "index", index)
207+
m.logger.Info("return adopting standby instance",
208+
"group", key,
209+
"instance", inKey,
210+
"index", index,
211+
"rv", item.instance.GetResourceVersion())
204212

205-
return m.keyToInstance[inKey].instance.DeepCopy(), DoNothing
213+
return item.instance.DeepCopy(), DoNothing
206214
}
207215

208216
hash := hashTiDBGroup(dbg)
@@ -217,7 +225,13 @@ func (m *manager) Adopt(dbg *v1alpha1.TiDBGroup, index int) (*v1alpha1.TiDB, Unl
217225
}
218226
m.lock(dbg, item)
219227

220-
m.logger.Info("adopting standby instance", "group", key, "instance", k, "hash", item.hash, "index", index)
228+
m.logger.Info("adopting standby instance",
229+
"group", key,
230+
"instance", k,
231+
"hash", item.hash,
232+
"index", index,
233+
"rv", item.instance.GetResourceVersion(),
234+
)
221235

222236
return item.instance.DeepCopy(), m.unlockFunc(item)
223237
}

pkg/controllers/tidbgroup/tasks/updater.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ func (f *factory) Adopt() (*runtime.TiDB, updater.UnlockFunc, bool) {
180180
Name: standby.Name,
181181
ResourceVersion: standby.ResourceVersion,
182182
},
183+
Spec: v1alpha1.TiDBSpec{
184+
Topology: standby.Spec.Topology,
185+
},
183186
}
184187

185188
tidb = f.updateTiDB(tidb)
@@ -189,18 +192,18 @@ func (f *factory) Adopt() (*runtime.TiDB, updater.UnlockFunc, bool) {
189192

190193
func (f *factory) updateTiDB(tidb *v1alpha1.TiDB) *v1alpha1.TiDB {
191194
spec := f.dbg.Spec.Template.Spec.DeepCopy()
195+
192196
tidb.Labels = coreutil.InstanceLabels[scope.TiDBGroup](f.dbg, f.rev)
193197
tidb.Annotations = coreutil.InstanceAnnotations[scope.TiDBGroup](f.dbg)
194198
tidb.Finalizers = []string{metav1alpha1.Finalizer}
195199
tidb.OwnerReferences = []metav1.OwnerReference{
196200
*metav1.NewControllerRef(f.dbg, v1alpha1.SchemeGroupVersion.WithKind("TiDBGroup")),
197201
}
198-
tidb.Spec = v1alpha1.TiDBSpec{
199-
Cluster: f.dbg.Spec.Cluster,
200-
Features: f.dbg.Spec.Features,
201-
Subdomain: HeadlessServiceName(f.dbg.Name), // same as headless service
202-
TiDBTemplateSpec: *spec,
203-
}
202+
203+
tidb.Spec.Cluster = f.dbg.Spec.Cluster
204+
tidb.Spec.Features = f.dbg.Spec.Features
205+
tidb.Spec.Subdomain = HeadlessServiceName(f.dbg.Name) // same as headless service
206+
tidb.Spec.TiDBTemplateSpec = *spec
204207

205208
if f.fg.Enabled(metav1alpha1.ClusterSubdomain) {
206209
tidb.Spec.Subdomain = coreutil.ClusterSubdomain(f.dbg.Spec.Cluster.Name)

0 commit comments

Comments
 (0)