Skip to content

Commit

Permalink
check phase too
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc committed Jun 29, 2023
1 parent d32ff44 commit e6e15e9
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions pkg/manager/volumes/pvc_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e6e15e9

Please sign in to comment.