@@ -391,6 +391,8 @@ func checkVgExists(volumeGroupName string) bool {
391
391
return false
392
392
}
393
393
// 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 ))
394
396
return strings .Contains (string (info ), volumeGroupName )
395
397
}
396
398
@@ -489,7 +491,15 @@ func reduceVolumeGroup(volumeGroupName string, force bool) {
489
491
}
490
492
info , err := common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgreduce" , args ... )
491
493
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
+ }
493
503
}
494
504
}
495
505
@@ -542,6 +552,62 @@ func IsRaided() (bool, error) {
542
552
return false , nil
543
553
}
544
554
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
+
545
611
func isCachingSetup (mainLvName string ) (error , bool ) {
546
612
// Verify caching is setup for PD
547
613
args := []string {
@@ -583,6 +649,7 @@ func InitializeDataCacheNode(nodeId string) error {
583
649
volumeGroupName := getVolumeGroupName (nodeId )
584
650
585
651
vgExists := checkVgExists (volumeGroupName )
652
+ klog .V (4 ).Infof ("samhalim vgexist %v" , vgExists )
586
653
// Check if the required volume group already exists
587
654
if vgExists {
588
655
// Clean up Volume Group before adding the PD
@@ -636,6 +703,7 @@ func watchDiskDetaches(watcher *fsnotify.Watcher, nodeName string, errorCh chan
636
703
// In case of an event i.e. creation or deletion of any new PV, we update the VG metadata.
637
704
// This might include some non-LVM changes, no harm in updating metadata multiple times.
638
705
reduceVolumeGroup (getVolumeGroupName (nodeName ), true )
706
+ vgckUpdateMetadata (getVolumeGroupName (nodeName ))
639
707
klog .V (2 ).Infof ("disk attach/detach event %#v\n " , event )
640
708
}
641
709
}
0 commit comments