pingcap / pingcap/tidb-operator
TiKV StatefulSet is never created on first bootstrap when TidbCluster includes TiFlash
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 540
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 18
Description
Bug Report
What version of Kubernetes are you using?
Reproduced in PingCAP test-infra (ksyun-rhel). Not specific to one Kubernetes version.
What version of TiDB Operator are you using?
The current v1 controller on master still has this path:
pkg/controller/tidbcluster/tidb_cluster_control.gosyncs TiFlash before TiKVpkg/manager/member/tiflash_member_manager.gotreatsGetStoresfailure as fatal and returns
What storage classes exist in the Kubernetes cluster and what are used for PD/TiKV pods?
Not relevant. TiKV StatefulSet is not created, so this is not a PVC/storage-class scheduling problem.
What's the status of the TiDB cluster pods?
PD is running. TiFlash StatefulSet may already exist. TiKV StatefulSet / pods are not created. The cluster never bootstraps.
What did you do?
Same shape as #4807, but this is a first-time create, not EBS restore:
- Create a
TidbClusterwith PD + TiKV + TiFlash in the same spec (spec.recoveryModeis not set). - Optional but easier to hit:
spec.pd.mode: mswith PD microservices (tso / scheduling). - Wait for the cluster to become Ready.
Concrete failing run: TCMS plan execution 8206262 (ng-import-into-br-migrate-tidbx, one TidbCluster with PD + 3 TiKV + 1 TiFlash write).
What did you expect to see?
Operator creates the TiKV StatefulSet, PD bootstraps, TidbCluster becomes Ready.
What did you see instead?
PD comes up, TiKV is never created, cluster stays not Ready until timeout.
Operator calls PD GET /pd/api/v1/stores from TiFlash sync and gets:
[PD:cluster:ErrNotBootstrapped]
TiKV cluster not bootstrapped, please start TiKV first
This is the same operator log as #4807:
Fail to GetStores for TidbCluster ...:
Error response 500 URL http://<pd>/pd/api/v1/stores,
body response: "[PD:cluster:ErrNotBootstrapped]TiKV cluster not bootstrapped, please start TiKV first"
After that, reconcile returns and tikvMemberManager.Sync never runs, so TiKV pods cannot appear.
This is not a resource-pool issue. In 8206262, sibling items (minio, tikv-worker, sdkserver, tools, ...) became Ready; only the TidbCluster items stayed not Ready until creationWaitTimeout.
Why this is an operator code bug
PD returning ErrNotBootstrapped before any TiKV exists is expected. The bug is that TiFlash sync aborts the whole reconcile on that error, so TiKV is never created, so PD can never bootstrap.
-
Reconcile order (
tidb_cluster_control.go):tiflashMemberManager.Syncruns first; any errorreturns beforetikvMemberManager.Sync. -
After the TiFlash StatefulSet exists,
syncTidbClusterStatusdoes:
storesInfo, err := pdCli.GetStores()
if err != nil {
tc.Status.TiFlash.Synced = false
klog.Warningf("Fail to GetStores for TidbCluster %s/%s: %s", ...)
return err // blocks TiKV creation
}
- TiKV already handles the same error and still creates the StatefulSet:
storesInfo, err := pdCli.GetStores()
if err != nil {
if pdapi.IsTiKVNotBootstrappedError(err) {
klog.Infof("TiKV of Cluster %s/%s not bootstrapped yet", ...)
tc.Status.TiKV.BootStrapped = false
return nil // continue and create STS
}
return err
}
Resulting deadlock:
- PD becomes available.
- TiFlash STS can be created (GetStores is skipped while the STS does not exist yet).
- If TiKV STS is not created in that same loop (for example PD API is up but PDMS clients are not ready, so TiKV Sync requeues), the next loop sees an existing TiFlash STS,
GetStoresreturnsErrNotBootstrapped, TiFlash returns error, TiKV Sync never runs again.
This is timing-dependent. If TiKV STS is created in the same reconcile as the first TiFlash STS, the cluster can come up. If the next reconcile hits GetStores first, TiKV is stuck forever.
Relation to #4807 / #4808
#4807 was the same Fail to GetStores / ErrNotBootstrapped blocking TiKV creation, during EBS snapshot restore.
#4808 only skipped TiFlash sync while spec.recoveryMode is true (syncRecoveryForTiFlash). It did not change:
- reconcile order (still TiFlash then TiKV)
- TiFlash
GetStoresstillreturn erronErrNotBootstrapped
So the first-bootstrap path is still broken.
Suggested fix
Either:
- Sync TiKV before TiFlash, or
- In TiFlash
syncTidbClusterStatus, treatpdapi.IsTiKVNotBootstrappedError(err)the same way TiKV does (return nil) so latertikvMemberManager.Synccan create the StatefulSet.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pkg/controller/tidbcluster/tidb_cluster_control.go and compare the TiFlash and TiKV sync paths in pkg/manager/member/tiflash_member_manager.go. Trace how pdCli.GetStores handles pdapi.IsTiKVNotBootstrappedError during first bootstrap. Done means a TidbCluster with PD, TiKV, and TiFlash creates the TiKV StatefulSet and can become Ready instead of stopping reconciliation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100