diff --git a/pkg/manager/volumes/pvc_modifier.go b/pkg/manager/volumes/pvc_modifier.go index 2cec024955..4db9cfdea2 100644 --- a/pkg/manager/volumes/pvc_modifier.go +++ b/pkg/manager/volumes/pvc_modifier.go @@ -286,7 +286,7 @@ func (p *pvcModifier) tryToModifyPVC(ctx *componentVolumeContext) error { if !isEvicted { // do not evict leader when resizing PVC (increasing size) // as if the storage size is not enough, the leader eviction will be blocked (never finished) - if !volumesSizeNeedModify(actual) { + if !skipEvictLeaderForSizeModify(actual) { if ensureTiKVLeaderEvictionCondition(ctx.tc, metav1.ConditionTrue) { // return to sync tc return fmt.Errorf("try to evict leader for tidbcluster %s/%s", ctx.tc.Namespace, ctx.tc.Name) @@ -321,21 +321,36 @@ func (p *pvcModifier) tryToModifyPVC(ctx *componentVolumeContext) error { return nil } -func volumesSizeNeedModify(actual []ActualVolume) bool { +// skip evict leader if the storage size should be modified or is in modifying phase +func skipEvictLeaderForSizeModify(actual []ActualVolume) bool { for _, vol := range actual { if vol.PVC == nil || vol.Desired == nil { continue } - // check with status, return need to modify if the size is modifying - oldSize, ok := vol.PVC.Annotations[annoKeyPVCStatusStorageSize] - if !ok { - // get from status capacity if not modified by the PVC Modifier before - quantity := vol.GetStorageSize() - oldSize = quantity.String() + + annoStatusSize, ok := vol.PVC.Annotations[annoKeyPVCStatusStorageSize] + if ok { + // modified by the PVC Modifier before (with status size annotation) + if annoStatusSize == vol.Desired.Size.String() { + continue // already up to date, no need to modify size + } + return true // need to modify size } - if oldSize != vol.Desired.Size.String() { - return true + + // not modified by the PVC modifier before (without status size annotation) + quantity := vol.GetStorageSize() + statusSize := quantity.String() + klog.Infof("volume %s/%s: phase %s, old size %s, new size %s", vol.PVC.Namespace, vol.PVC.Name, vol.Phase, statusSize, vol.Desired.Size.String()) + if statusSize == vol.Desired.Size.String() { + // special case: skip evict leader (again) as the PVC is in modfiying phase (and the status size annotation is not set yet) + if vol.Phase == VolumePhaseModifying { + return true + } + // already modified, in fact, the status size annotation should already be set + continue } + // need to modify size + return true } return false }