Improving mirror fault handling.
<background>
"Events" are mechanism that device-mapper kernel targets use to signal user-space. An event can be raised for any number of reasons,
including: a mirror becomes in-sync, an I/O error has occurred to a device in a mirror, a snapshot has become full - anything that may warrant user-space interest.
User-space can wait on a DM device (using 'dmsetup wait <device> [<event_nr>]') for an event to take place; and once an event is received, take action. It is always prudent to check the status output of the DM device once an event is received to ensure you are taking the appropriate action. Since devices can raise an event for a variety of reasons, do not presuppose a particular reason for an event.
There exists a daemon ('dmeventd') specifically designed to listen for events. Devices are registered with the daemon along with the name of a Dynamic Shared Object (aka DSO, aka runtime library) via a library interface - libdevmapper-event. The daemon "wait"s on the device for an event and uses the DSO to process it. For example, when LVM creates a mirror, it registers the mirror device with the daemon, specifying "libdevmapper-event-lvm2mirror.so" as the DSO to use for processing events. (If users don't like the way the default DSO handles events, they can even specify their own.)
</background>
Currently, the mirror DSO - libdevmapper-event-lvm2mirror.so - is limited in what it does. (Find the code in LVM2/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c) It will tell you when a mirror becomes "in-sync" and it will remove a device that suffers an I/O error - regardless of how or why. It is the last part that needs improving...
We now have the ability to detect the type of error that was encountered by the mirror. After an event, we can get the status of the mirror, which will look something like this:
"0 41943040 mirror 2 254:3 254:4 40960/40960 1 AA 3 clustered_disk 254:2 A" The 'A's signify that the disks are "alive". Looking at 'linux-2.6/drivers/md/dm-raid1.c' we find the other possible states:
* A => Alive - No failures * D => Dead - A write failure occurred leaving mirror out-of-sync * S => Sync - A sychronization failure occurred, mirror out-of-sync * R => Read - A read failure occurred, mirror data unaffected
We can do so much more with this information than the immediate removal of an offending device. 'S' could cause us to simply suspend/resume the device to restart the resynchronization process - giving us another shot at it. 'R' could mean that we have a unrecoverable read error - a block relocation might be initiated via a write. In the case of a 'D', we could wait some user configured amount of time (or %'age out of sync) before removing the offending device, as it could be a transient failure.
A good DSO would also allow us to do proactive scans of RAID devices - spotting problems before they bite us. (Like the existence of an unrecoverable read error rendering a RAID5 useless - even before a drive has failed.) There are lots of possibilities here....
If I were to guess at the phases of development I would say they are:
1) Simplest working solution - DONE
2) Improve parsing of mirror status output in the DSO
- Location => LVM2/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
- Be able to determine failure types (need more states then just 'ME_FAILURE')
- At the very least, we improve the log messages at this phase and it sets us up to improve the handling of each error type - potentially ignoring some error types for now (like read failures).
3) Implement different methods to handle the different error types
4) Transient fault handling
- Since we can't just assume "wait 5 seconds and then see if the failure still exists", we are going to have to make this configurable. Discussion should proceed on this in parallel with #2 and #3, since this phase will take a long time for everyone to agree. We have to determine where the user specifies the configuration - lvm.conf? CLI? We also have to determine /what/ their configuration will be based on - time? percentage of mirror out-of-sync?
5) Proactive scan
- Even in the case where software does everything right, your RAID volume can become inconsistent. Long seeks, adjacent track erasure, problems with RAM or copying, unrecoverable read errors... it'd be nice if we could spot these before they become a problem. We could use the DSO to perform proactive scanning - perhaps just a little bit of the storage at a time. Every so many days, you could be reassured that everything is in order.
brassow
Quoted 23 lines · Jonathan Brassow [[email protected]] wrote:
* A => Alive - No failures * D => Dead - A write failure occurred leaving mirror out-of-sync * S => Sync - A sychronization failure occurred, mirror out-of-sync * R => Read - A read failure occurred, mirror data unaffectedWe can do so much more with this information than the immediate removal of an offending device. 'S' could cause us to simply suspend/resume the device to restart the resynchronization process - giving us another shot at it. 'R' could mean that we have a unrecoverable read error - a block relocation might be initiated via a write. In the case of a 'D', we could wait some user configured amount of time (or %'age out of sync) before removing the offending device, as it could be a transient failure.
2) Improve parsing of mirror status output in the DSO
- Location =>LVM2/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
- Be able to determine failure types (need more states then just 'ME_FAILURE')
- At the very least, we improve the log messages at this phase and it sets us up to improve the handling of each error type - potentially ignoring some error types for now (like read failures).3) Implement different methods to handle the different error types
Quoted 8 lines
4) Transient fault handling
- Since we can't just assume "wait 5 seconds and then see if the failure still exists", we are going to have to make this configurable. Discussion should proceed on this in parallel with #2 and #3, since this phase will take a long time for everyone to agree. We have to determine where the user specifies the configuration - lvm.conf? CLI? We also have to determine /what/ their configuration will be based on - time? percentage of mirror out-of-sync?
Thank you Jonathan for the nice write up. Transient failure are generally recoverable after a period of time. The 'time' may vary from device to device though. lvm.conf based configuration is a good place to start. Do we really need LV or PV based configuration for this 'timeout'?
The recovery itself doesn't depend on the %of out-of-sync regions, but that is a good place to start looking for re-allocating the regions if configured for re-allocation.
Here are my thoughts:
handle_mirror_transient_failure()
{
do {
if (device-came-back-to-life()) {
start-resynchronization();
break;
}
if (reallocation-timeout exceeded or
re-allocation-too-much out-of-sync) {
re-allocate();
break;
}
if (some-other-timeout exceeded) {
log a message and break;
}
sleep(for-few-seconds);
timeout =- few-seconds;
} while (1)
}Thanks, Malahal.
Quoted 33 lines · On Jan 12, 2009, at 9:26 PM, [email protected] wrote:
Quoted 9 lines
4) Transient fault handling
- Since we can't just assume "wait 5 seconds and then see if the failure
still exists", we are going to have to make this configurable. Discussion should proceed on this in parallel with #2 and #3, since this phase will take a long time for everyone to agree. We have to determine where the user specifies the configuration - lvm.conf? CLI? We also have to determine /what/ their configuration will be based on - time? percentage of mirror out-of-sync?Thank you Jonathan for the nice write up. Transient failure are generally recoverable after a period of time. The 'time' may vary from device to device though. lvm.conf based configuration is a good place to start. Do we really need LV or PV based configuration for this 'timeout'?
The recovery itself doesn't depend on the %of out-of-sync regions, but that is a good place to start looking for re-allocating the regions if configured for re-allocation.
Here are my thoughts:
handle_mirror_transient_failure() { do { if (device-came-back-to-life()) { start-resynchronization(); break; } if (reallocation-timeout exceeded or re-allocation-too-much out-of-sync) { re-allocate(); break;
Quoted 8 lines
}
if (some-other-timeout exceeded) {
log a message and break;
}
sleep(for-few-seconds);
timeout =- few-seconds;
} while (1)
}If we put the configuration in lvm.conf, then it would globally apply to all volume groups and all logical volumes. I might be willing to accept that for a while, but others may want a plan for something better going forward. We don't want to pollute the conf file with new fields that will be useless shortly into the future. If you look in LVM2/doc/example.conf and search for _fault_policy, you can see that there are already some configuration options there. We might stick the new ones there as well. (Although this somewhat confuses me, because they apply only to our default DSO, and you can change the DSO you want to use in a completely different section of the config file... So now you have settings that are worthless because a custom DSO is being used.)
What I meant in regards to "/what/ their configuration will be based on", is that the user may not care about the time they wait for a device to come back, but how far the mirror has gone out of sync while the device has been gone... If one of the legs fails and the mirror is 75% out of sync before the device comes back, the user may just want the device removed and stop waiting. If the user specifies "5 minutes" wait time, but there have been no writes to the mirror in that time, then we could probably wait longer. You see what I mean? A user may wish to use a combination of the two methods... "Wait 20 minutes for the device to come back, but only if the mirror stays > 95% in-sync".
As for the pseudo-code... I wouldn't use a 'while(1)' there... leave the thread free to continue. We could use dmeventd's timer events to trigger the next check for the device coming back (I hope). Your code seems to suggest that you understand my point in the preceding paragraph, but I am a bit confused by the use of '[re-]allocation'. In this piece of code, we are only concerned about whether or not to take action. The action is user defined (see the example.conf mentioned above), so the space may or may not be reallocated.
brassow