LoadParityData searches for parity volumes and loads them into memory.
()
| 494 | // LoadParityData searches for parity volumes and loads them into |
| 495 | // memory. |
| 496 | func (d *Decoder) LoadParityData() error { |
| 497 | ext := path.Ext(d.indexPath) |
| 498 | base := d.indexPath[:len(d.indexPath)-len(ext)] |
| 499 | matches, err := d.fileIO.FindWithPrefixAndSuffix(base+".", ext) |
| 500 | if err != nil { |
| 501 | return err |
| 502 | } |
| 503 | |
| 504 | var parityFiles []file |
| 505 | for i, match := range matches { |
| 506 | parityFile, err := func() (*file, error) { |
| 507 | volumeBytes, err := d.fileIO.ReadFile(match) |
| 508 | if err != nil { |
| 509 | return nil, err |
| 510 | } |
| 511 | |
| 512 | // Ignore all the other packet types other |
| 513 | // than recovery packets. |
| 514 | _, parityFile, err := readFile(recoveryDelegate{d.delegate}, &d.setID, volumeBytes) |
| 515 | if _, ok := err.(noPacketsFoundError); ok { |
| 516 | return nil, nil |
| 517 | } else if err != nil { |
| 518 | // TODO: Relax this check. |
| 519 | return nil, err |
| 520 | } |
| 521 | |
| 522 | if d.sliceByteCount != parityFile.mainPacket.sliceByteCount { |
| 523 | return nil, errors.New("slice byte count mismatch") |
| 524 | } |
| 525 | |
| 526 | if !reflect.DeepEqual(decoderInputFileInfoIDs(d.recoverySet), parityFile.mainPacket.recoverySet) { |
| 527 | return nil, errors.New("recovery set mismatch") |
| 528 | } |
| 529 | |
| 530 | if !reflect.DeepEqual(decoderInputFileInfoIDs(d.nonRecoverySet), parityFile.mainPacket.nonRecoverySet) { |
| 531 | return nil, errors.New("non-recovery set mismatch") |
| 532 | } |
| 533 | |
| 534 | return &parityFile, nil |
| 535 | }() |
| 536 | d.delegate.OnParityFileLoad(i+1, match, err) |
| 537 | if err != nil { |
| 538 | return err |
| 539 | } |
| 540 | if parityFile == nil { |
| 541 | continue |
| 542 | } |
| 543 | |
| 544 | parityFiles = append(parityFiles, *parityFile) |
| 545 | } |
| 546 | |
| 547 | var parityShards [][]byte |
| 548 | for _, file := range parityFiles { |
| 549 | for exponent, packet := range file.recoveryPackets { |
| 550 | if int(exponent) >= len(parityShards) { |
| 551 | parityShards = append(parityShards, make([][]byte, int(exponent+1)-len(parityShards))...) |
| 552 | } |
| 553 | parityShards[exponent] = packet.data |