From 81c8880aba813ea8a9602665aeda5b61e2e64a47 Mon Sep 17 00:00:00 2001 From: husharp Date: Thu, 25 Jul 2024 11:10:12 +0800 Subject: [PATCH] update log Signed-off-by: husharp --- examples/basic/pd-micro-service-cluster.yaml | 17 ++++++++------ pkg/manager/member/pd_ms_upgrader.go | 24 +++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/examples/basic/pd-micro-service-cluster.yaml b/examples/basic/pd-micro-service-cluster.yaml index 355831f56ea..67b55c6447e 100644 --- a/examples/basic/pd-micro-service-cluster.yaml +++ b/examples/basic/pd-micro-service-cluster.yaml @@ -15,9 +15,12 @@ spec: discovery: {} helper: image: alpine:3.16.0 + startScriptV2FeatureFlags: + - PDMSWithName pd: - baseImage: pingcap/pd - version: v8.1.0 + # TODO: replaced v8.3.0 after v8.3.0 released + baseImage: hub.pingcap.net/devbuild/pd + version: v8.3.0-5391 maxFailoverCount: 0 replicas: 1 # if storageClassName is not set, the default Storage Class of the Kubernetes cluster will be used @@ -28,13 +31,13 @@ spec: mode: "ms" pdms: - name: "tso" - baseImage: pingcap/pd - version: v8.1.0 + baseImage: hub.pingcap.net/devbuild/pd + version: v8.3.0-5391 replicas: 2 - name: "scheduling" - baseImage: pingcap/pd - version: v8.1.0 - replicas: 1 + baseImage: hub.pingcap.net/devbuild/pd + version: v8.3.0-5391 + replicas: 2 tikv: baseImage: pingcap/tikv version: v8.1.0 diff --git a/pkg/manager/member/pd_ms_upgrader.go b/pkg/manager/member/pd_ms_upgrader.go index e845e143672..544781ce4ad 100644 --- a/pkg/manager/member/pd_ms_upgrader.go +++ b/pkg/manager/member/pd_ms_upgrader.go @@ -50,7 +50,7 @@ func (u *pdMSUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.St } curService := controller.PDMSTrimName(newSet.Name) - klog.Infof("gracefulUpgrade pdMS trim name, componentName: %s", curService) + klog.Infof("TidbCluster: [%s/%s]' gracefulUpgrade pdMS trim name, componentName: %s", ns, tcName, curService) if tc.Status.PDMS[curService] == nil { tc.Status.PDMS[curService] = &v1alpha1.PDMSStatus{Name: curService} return fmt.Errorf("tidbcluster: [%s/%s]'s pdMS component is nil, can not to be upgraded, component: %s", ns, tcName, curService) @@ -62,7 +62,7 @@ func (u *pdMSUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.St if oldTrimName != curService { return fmt.Errorf("tidbcluster: [%s/%s]'s pdMS oldTrimName is %s, not equal to componentName: %s", ns, tcName, oldTrimName, curService) } - klog.Infof("gracefulUpgrade pdMS trim name, oldTrimName: %s", oldTrimName) + klog.Infof("TidbCluster: [%s/%s]' gracefulUpgrade pdMS trim name, oldTrimName: %s", ns, tcName, oldTrimName) if tc.PDMSScaling(oldTrimName) { klog.Infof("TidbCluster: [%s/%s]'s pdMS status is %v, can not upgrade pdMS", ns, tcName, tc.Status.PDMS[curService].Phase) @@ -85,7 +85,7 @@ func (u *pdMSUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.St // If we encounter this situation, we will let the native statefulset controller do the upgrade completely, which may be unsafe for upgrading pdMS. // Therefore, in the production environment, we should try to avoid modifying the pd statefulset update strategy directly. newSet.Spec.UpdateStrategy = oldSet.Spec.UpdateStrategy - klog.Warningf("tidbcluster: [%s/%s] pdMS statefulset %s UpdateStrategy has been modified manually, componentName: %s", ns, tcName, oldSet.GetName(), curService) + klog.Warningf("Tidbcluster: [%s/%s] pdMS statefulset %s UpdateStrategy has been modified manually, componentName: %s", ns, tcName, oldSet.GetName(), curService) return nil } @@ -142,26 +142,26 @@ func (u *pdMSUpgrader) upgradePDMSPod(tc *v1alpha1.TidbCluster, ordinal int32, n return err } - klog.Infof("[TODO] pdms upgrader: check primary: %s, upgradePDMSName: %s, upgradePodName: %s", primary, upgradePDMSName, upgradePodName) + klog.Infof("TidbCluster: [%s/%s]' pdms upgrader: check primary: %s, upgradePDMSName: %s, upgradePodName: %s", ns, tcName, + primary, upgradePDMSName, upgradePodName) // If current pdms is primary, transfer primary to other pdms pod if strings.Contains(primary, upgradePodName) || strings.Contains(primary, upgradePDMSName) { targetName := "" - if tc.PDStsActualReplicas() > 1 { + if tc.PDMSStsActualReplicas(curService) > 1 { targetName = choosePDMSToTransferFromMembers(tc, newSet, ordinal) } if targetName != "" { - klog.Infof("[TODO] pdms upgrader: transfer pdms primary to: %s", targetName) + klog.Infof("TidbCluster: [%s/%s]' pdms upgrader: transfer pdms primary to: %s", ns, tcName, targetName) err := controller.GetPDClient(u.deps.PDControl, tc).TransferPrimary(curService, targetName) if err != nil { - klog.Errorf("pdms upgrader: failed to transfer pdms primary to: %s, %v", targetName, err) + klog.Errorf("TidbCluster: [%s/%s]' pdms upgrader: failed to transfer pdms primary to: %s, %v", ns, tcName, targetName, err) return err } - klog.Infof("pdms upgrader: transfer pdms primary to: %s successfully", targetName) - return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd member: [%s] is transferring leader to pd member: [%s]", ns, tcName, upgradePDMSName, targetName) + klog.Infof("TidbCluster: [%s/%s]' pdms upgrader: transfer pdms primary to: %s successfully", ns, tcName, targetName) } else { - klog.Warningf("pdms upgrader: skip to transfer pdms primary, because can not find a suitable pd") + klog.Warningf("TidbCluster: [%s/%s]' pdms upgrader: skip to transfer pdms primary, because can not find a suitable pd", ns, tcName) } } } @@ -176,7 +176,9 @@ func (u *pdMSUpgrader) upgradePDMSPod(tc *v1alpha1.TidbCluster, ordinal int32, n // 1. Find the max suitable ordinal in (x, n], because they have been upgraded // 2. If no suitable ordinal, find the min suitable ordinal in [0, x) to reduce the count of transfer func choosePDMSToTransferFromMembers(tc *v1alpha1.TidbCluster, newSet *apps.StatefulSet, ordinal int32) string { + ns := tc.GetNamespace() tcName := tc.GetName() + klog.Infof("Tidbcluster: [%s/%s]' pdms upgrader: start to choose pdms to transfer primary from members", ns, tcName) ordinals := helper.GetPodOrdinals(*newSet.Spec.Replicas, newSet) // set ordinal to max ordinal if ordinal isn't exist @@ -201,7 +203,7 @@ func choosePDMSToTransferFromMembers(tc *v1alpha1.TidbCluster, newSet *apps.Stat targetName = PDMSPodName(tcName, list[0], controller.PDMSTrimName(newSet.Name)) } - klog.Infof("pd ms upgrader: choose pd ms to transfer leader from members, targetName: %s", targetName) + klog.Infof("Tidbcluster: [%s/%s]' pdms upgrader: choose pdms to transfer primary from members, targetName: %s", ns, tcName, targetName) return targetName }