Skip to content

Commit 3d26949

Browse files
committed
Adding step in GKE Data Cache watcher to check and remove VG duplicates.
1 parent c653070 commit 3d26949

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

pkg/gce-pd-csi-driver/cache.go

+69-1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ func checkVgExists(volumeGroupName string) bool {
391391
return false
392392
}
393393
// Check if the required volume group already exists
394+
klog.V(4).Infof("samhalim checkvgexist info: %v ", string(info))
395+
klog.V(4).Infof("samhalim does it contains? %v ", strings.Contains(string(info), volumeGroupName))
394396
return strings.Contains(string(info), volumeGroupName)
395397
}
396398

@@ -489,7 +491,15 @@ func reduceVolumeGroup(volumeGroupName string, force bool) {
489491
}
490492
info, err := common.RunCommand("" /* pipedCmd */, nil /* pipedCmdArg */, "vgreduce", args...)
491493
if err != nil {
492-
klog.Errorf("Errored while cleaning up volume group %v: %s", err, info)
494+
klog.V(2).Infof("samhalim this is info: %v", string(info))
495+
klog.V(2).Infof("samhalim this is err: %v", err.Error())
496+
klog.V(2).Infof("samhalim info true?: %v", strings.Contains(string(info), "duplicate VG names with vgrename uuid"))
497+
klog.V(2).Infof("samhalim err true?: %v", strings.Contains(err.Error(), "duplicate VG names with vgrename uuid"))
498+
if strings.Contains(string(info), "duplicate VG names with vgrename uuid") || strings.Contains(err.Error(), "duplicate VG names with vgrename uuid") {
499+
removeAndFixDuplicate(volumeGroupName)
500+
} else {
501+
klog.Errorf("Errored while cleaning up volume group %v: %s", err, info)
502+
}
493503
}
494504
}
495505

@@ -542,6 +552,62 @@ func IsRaided() (bool, error) {
542552
return false, nil
543553
}
544554

555+
func removeAndFixDuplicate(vgName string) {
556+
// Get the new VG duplicate. This is the VG name that has 0 lv_count
557+
args := []string{
558+
"-v",
559+
"--noheadings",
560+
"-o",
561+
"vg_uuid",
562+
"--select",
563+
"vg_name=" + vgName,
564+
"--select",
565+
"lv_count=0",
566+
}
567+
uuidToRemove, err := common.RunCommand("" /* pipedCmd */, nil /* pipedCmdArg */, "vgs", args...)
568+
if err != nil {
569+
klog.Errorf("errored while running vgs to remove duplicate %v: %s", err, uuidToRemove)
570+
}
571+
klog.V(2).Infof("samhalim this is uuidToRemove %s", string(uuidToRemove))
572+
573+
vgRename := vgName + "-new"
574+
// rename UUID to something else so we can vgremove.
575+
args = []string{
576+
string(uuidToRemove),
577+
vgRename,
578+
}
579+
info, err := common.RunCommand("" /* pipedCmd */, nil /* pipedCmdArg */, "vgrename", args...)
580+
if err != nil {
581+
klog.Errorf("errored while running vgrename to remove duplicate %v: %s", err, info)
582+
}
583+
info, err = common.RunCommand("" /* pipedCmd */, nil /* pipedCmdArg */, "vgremove", []string{vgRename}...)
584+
if err != nil {
585+
klog.Errorf("errored while running vgremove to remove duplicate %v: %s", err, info)
586+
}
587+
588+
// Extend new Raided LSSD to the old VG
589+
raidedLocalSsdPath, err := fetchRAIDedLocalSsdPath()
590+
if err != nil {
591+
klog.Errorf("failed to get raided lssd path to remove duplicate")
592+
}
593+
info, err = common.RunCommand("" /* pipedCmd */, nil /* pipedCmdArg */, "vgextend", []string{vgName, raidedLocalSsdPath}...)
594+
if err != nil {
595+
klog.Errorf("errored while running vgextend to remove duplicate %v: %s", err, info)
596+
}
597+
598+
// remove any leftover old metadata using vgck
599+
vgckUpdateMetadata(vgName)
600+
// put log here that remove and fix duplicate is successful
601+
}
602+
603+
func vgckUpdateMetadata(vgName string) {
604+
// remove any leftover old metadata using vgck
605+
info, err := common.RunCommand("" /* pipedCmd */, nil /* pipedCmdArg */, "vgck", []string{"--updatemetadata", vgName}...)
606+
if err != nil {
607+
klog.Errorf("errored while running vgck for cleanup to remove duplicate %v: %s", err, info)
608+
}
609+
}
610+
545611
func isCachingSetup(mainLvName string) (error, bool) {
546612
// Verify caching is setup for PD
547613
args := []string{
@@ -583,6 +649,7 @@ func InitializeDataCacheNode(nodeId string) error {
583649
volumeGroupName := getVolumeGroupName(nodeId)
584650

585651
vgExists := checkVgExists(volumeGroupName)
652+
klog.V(4).Infof("samhalim vgexist %v", vgExists)
586653
// Check if the required volume group already exists
587654
if vgExists {
588655
// Clean up Volume Group before adding the PD
@@ -636,6 +703,7 @@ func watchDiskDetaches(watcher *fsnotify.Watcher, nodeName string, errorCh chan
636703
// In case of an event i.e. creation or deletion of any new PV, we update the VG metadata.
637704
// This might include some non-LVM changes, no harm in updating metadata multiple times.
638705
reduceVolumeGroup(getVolumeGroupName(nodeName), true)
706+
vgckUpdateMetadata(getVolumeGroupName(nodeName))
639707
klog.V(2).Infof("disk attach/detach event %#v\n", event)
640708
}
641709
}

0 commit comments

Comments
 (0)