Moving an LVM mirror log

Suppose you created an LVM mirror but your mirror log is on the wrong SAN device. SAN migration won't help you since these LUNs exist on different SAN machines altogehter. But how do you move the mirror log?

Let's create an LVM mirror:

  Last login: Sat Nov 23 17:36:23 2013
  [[email protected] ~]# ls /dev/sd*
  /dev/sda  /dev/sdb
  [[email protected] ~]# pvcreate /dev/sda
    Writing physical volume data to disk "/dev/sda"
    Physical volume "/dev/sda" successfully created
  [[email protected] ~]# pvcreate /dev/sdb
    Writing physical volume data to disk "/dev/sdb"
    Physical volume "/dev/sdb" successfully created
  [[email protected] ~]# vgcreate vgmir /dev/sda /dev/sdb
    Volume group "vgmir" successfully created
  [[email protected] ~]# lvcreate -l 45%FREE vgmir -n lvmir
    Logical volume "lvmir" created
  [[email protected] ~]# lvconvert -m 1 /dev/vgmir/lvmir 
    vgmir/lvmir: Converted: 0.2%
    vgmir/lvmir: Converted: 2.2%
  ...
    vgmir/lvmir: Converted: 99.5%
    vgmir/lvmir: Converted: 100.0%

Now lvs -a -o +devices will show you the detailed mirror configuration:

  LV               VG       Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert Devices
  lvmir            vgmir    mwi-a-m- 3.59g                         lvmir_mlog 100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
  [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                                   /dev/sda(0)
  [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                                   /dev/sdb(0)
  [lvmir_mlog]     vgmir    lwi-aom- 4.00m                                                   /dev/sdb(920)

In my case /dev/sdb and /dev/sdc were on different SAN machines and one machine was loaded quite heavily. Meaning we got a 160 IOPS maximum out of the entire mirror. Now all credit goes to our SAN admins for getting the utilization of the older SAN machine to the point where the LUN could easily deliver 4000 IOPS.

However there's one thing to consider: the mirror log. The mirror log generally incurs extra IOPS, so you want to create it on the faster/less loaded SAN machine. Two approaches immediately come to mind: a) convert the mirror from on disk log to in-memory then recreating it on the faster SAN machine; b) dropping the slower mirror leg entirely and recreating the mirror with the faster SAN as the mirror device.

Let's drop the mirror:

  [[email protected] ~]# lvconvert -m 0 vgmir/lvmir /dev/sdb
    Logical volume lvmir converted.

And recreate the mirror with the mirror log on ``/dev/sda``::

  [[email protected] ~]# lvs -a -o +devices,seg_pe_ranges
    LV      VG       Attr     LSize Pool Origin Data%  Move Log Copy%  Convert Devices        PE Ranges         
    lvmir   vgmir    -wi-a--- 3.59g                                            /dev/sda(0)    /dev/sda:0-919    
  [[email protected] ~]# lvconvert -m 1 vgmir/lvmir /dev/sdb:0-919 /dev/sda
    vgmir/lvmir: Converted: 0.2%
    vgmir/lvmir: Converted: 2.7%
    vgmir/lvmir: Converted: 99.8%
    vgmir/lvmir: Converted: 100.0%
  [[email protected] ~]# lvs -a -o +devices
    LV               VG       Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert Devices                            
    lv_root          VolGroup -wi-ao-- 3.45g                                                   /dev/vda2(0)                       
    lv_swap          VolGroup -wi-ao-- 3.88g                                                   /dev/vda2(882)                     
    lvmir            vgmir    mwi-a-m- 3.59g                         lvmir_mlog 100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
    [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                                   /dev/sda(0)                        
    [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                                   /dev/sdb(0)                        
    [lvmir_mlog]     vgmir    lwi-aom- 4.00m                                                   /dev/sda(920)                      

The trick here is, since we don't have an option to specify the mirror leg explicitely we specify a PE range on /dev/sdb and the full /dev/sda and LVM figures out where to place the segments.

Let's convert that to a core mirror:

  [[email protected] ~]# lvconvert --mirrorlog core vgmir/lvmir
    Logical volume lvmir converted.
  [[email protected] ~]# lvs -a -o +devices
    LV               VG       Attr     LSize Pool Origin Data%  Move Log Copy%  Convert Devices                            
    lv_root          VolGroup -wi-ao-- 3.45g                                            /dev/vda2(0)                       
    lv_swap          VolGroup -wi-ao-- 3.88g                                            /dev/vda2(882)                     
    lvmir            vgmir    mwi-a-m- 3.59g                             100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
    [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                            /dev/sda(0)                        
    [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                            /dev/sdb(0)                        

Then convert it back to a on-disk mirror::

  [[email protected] ~]# lvconvert --mirrorlog disk vgmir/lvmir /dev/sdb
    Logical volume lvmir converted.
  [[email protected] ~]# lvs -a -o +devices
    LV               VG       Attr     LSize Pool Origin Data%  Move Log        Copy%  Convert Devices                            
    lv_root          VolGroup -wi-ao-- 3.45g                                                   /dev/vda2(0)                       
    lv_swap          VolGroup -wi-ao-- 3.88g                                                   /dev/vda2(882)                     
    lvmir            vgmir    mwi-a-m- 3.59g                         lvmir_mlog 100.00         lvmir_mimage_0(0),lvmir_mimage_1(0)
    [lvmir_mimage_0] vgmir    iwi-aom- 3.59g                                                   /dev/sda(0)                        
    [lvmir_mimage_1] vgmir    iwi-aom- 3.59g                                                   /dev/sdb(0)                        
    [lvmir_mlog]     vgmir    lwi-aom- 4.00m                                                   /dev/sdb(920)                      

Converting the mirror-log to a core-log is clearly much faster and the only drawback seems to be that in case of a reboot the whole mirror will be resynced which is just as good as resyncing the mirror in the first place.

comments powered by Disqus