How does data redundancy under RAID 5 work?

198 views

I do understand RAID 1. You have two drives that are mirrored. So when one drive fails, you have the full set of data on the other drive.

But with RAID 5 you are able to lose a complete drive out of a set of 3 for example. You have full data redundancy without sacrificing half of your capacity. How does this work?

In: 5

7 Answers

Anonymous 0 Comments

[removed]

Anonymous 0 Comments

I’ll explain for storing 2 bits; the principle is the same in larger scale, just repeated a few billion times.

If you have 3 drives to store your 2 bits then you store 1 bit on the first drive and 1 on the second. This is how RAID 0 works, by the way. From there you want to store something on the 3rd drive that has information about both bits. If you were to just store another copy of the 1st bit, for example, then losing the 2nd drive would lose data.

The solution here is to store some notion of “the two bits are the same” or “the two bits are different.” Typically the convention is that if the bits are the same you store a 0 and if they’re different you store a 1.

In this setup if you lose the 3rd drive there’s no problem–all the original data was stored on the first two. If you lose the 1st or 2nd drive then you look at the 2nd or 1st to get one bit, then you look at the 3rd drive to figure out if the missing drive held the same bit or a different one.

Anonymous 0 Comments

So this is because the parity information is striped across all the disks. Each disk holds unique parity information for each other disk. If disk 0 has parity for A, and the other disks have the A data split between them, if disk 0 is lost then there is no loss of data. If, for example, disk 1 is lost, the remaining data and parity can recover the lost data. Now repeat that process staggering the parity information across each drive and you have RAID 5

Anonymous 0 Comments

RAID 5 is kind of a combination of striping (RAID 0) with what’s called parity.

If you think of the 3 drives as a table with columns and rows, you stripe the data across 2 of the 3 columns in a row, and then calculate the parity in the 3rd column. If you then delete one of the first two cells, you could recalculate it using the parity. It’s not a copy of the data, it’s instructions on how to figure out what data is missing based on another piece of data.

You can actually demonstrate this in Excel. Make 2 columns of random 1s and 0s. In the 3rd column put in the equation “=XOR(A1,B1)” and fill down. In the 4th column do another equation of “=XOR(B1,C1)” and fill down. The data will match the first column. You have 2 pieces of real data and one column that lets you create anything that is missing.

Anonymous 0 Comments

The first 2 drives store half the data each.
The third drive stores the *difference* between the data on the first drive and the data on the second drive.

This sounds complicated on the surface, how could you describe the “difference” between an operating system file and a video for example?

But remember, at the bit level, data is just 1s and 0s. If you have a 1 on the first drive, you only need one tiny piece of information to determine what was on the second drive: was it the same (that means the second drive contained a 1) or was it different (that means the second drive contained a 0)?

Anonymous 0 Comments

RAID 5 takes advantage of technology called Parity Calculations for redundancy.

Parity uses the Function XoR (exclusive Or). XoR takes in 2 binary digits (0 or 1) and if both are the same it returns 0, if they are different it returns 1

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0

Now imagine having an array of 3 hard drives, 2 storing data and 1 storing the parity info. Take a string of bits from each drive and perform XoR

0 + 1 = 1

Now assume you lost a disk

0 + x = 1

Since you know the parity result, you can calculate that the missing but Must be 1, because if it was 0 the parity calculation would fail. In this way you can use only a single disks worth of space to store parity info for an entire array of disks vs having a mirrored copy.

RAID 5 doesn’t use a single disk for parity, but rather spreads the parity info across the entire array in order to improve overall performance. But even spread over the array the parity info is only 1 disks worth of space regardless of the size of the array.

In practice though RAID 5 is going the way of the dodo. The problem is that drives are now so large that if you replace a drive it can take more than 24 hours to rebuild the array. During that time your array is vulnerable because it is being stressed and the chances of blowing another drive is high. If you lose a 2nd drive, you lose all your data.

RAID 6 works like RAID 5, but has 2 separate parity calculations (losing 2 disks worth of space) allowing you to lose 2 drives without losing data.

But RAID 10 still provides far better overall performance.

Anonymous 0 Comments

Not sure I can do like 5, but like a teenager maybe.

In RAID 5, data is written to a collection of disks. It writes the data to all the disks except one. For that last disk, a parity bit is calculated for each bit written to the others. That parity bit is either a 1 or a 0, but it tells the system if the actual data, the total of 1’s and 0’s is odd or even. So if one disk is lost, the system can recalculate if it is missing a 1 or a 0. In reality, disks don’t write individual bits, they write in blocks. The parity block will contain all the parity bits for the chunks on the other disks.

In RAID 5, the first block goes on disk 0, then disk 1, then disk 2, etc, The parity block goes on the last disk. Now this is done across all disks in the set. If you have 10 disks, then 9 will hold data while the last one will have the parity bit. The system rotates the starting point so that which disk holds the parity bits for a particular block. That way, all the disks hold the same amount of actual data and parity information. If you lose one disk, the system calculates the missing data from the parity bit for each read/write. This will slow the system down a bit, but you will lose no data. Replacing the disk re-scans all the data and parity bits to repopulate the missing data. That’s why rebuilding a RAID array takes so long.

So like you’re 5: If you have 5 trays. You place an apple on tray 1, an apple on tray 2, no apple on tray 3, and an apple on tray 4. So you have three apples, right? Now there’s a rule, if you have an even number of apples, you don’t put one on tray 5. If you have an odd number of apples, you put one on tray 5 so that your total number of apples is always even. So now you put one on tray 5. That’s the parity tray. Now, if you take away tray 2, can you use that rule to figure out if tray 2 had an apple or not? Sure you can! Since you have three apples left on the 4 trays, the tray that’s now missing must have an apple because you know that there needs to be an even number of apples!