MCPcopy Create free account
hub / github.com/akalin/gopar / LoadParityData

Method LoadParityData

par2/decoder.go:496–559  ·  view source on GitHub ↗

LoadParityData searches for parity volumes and loads them into memory.

()

Source from the content-addressed store, hash-verified

494// LoadParityData searches for parity volumes and loads them into
495// memory.
496func (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

Callers 11

repairFunction · 0.45
testCreateFunction · 0.45
verifyFunction · 0.45
testWriteParityFunction · 0.45
testShardCountsFunction · 0.45
testDecoderVerifyFunction · 0.45
TestSetIDMismatchFunction · 0.45
testDecoderRepairFunction · 0.45
TestRepairAddedBytesFunction · 0.45
TestRepairRemovedBytesFunction · 0.45
TestRepairSwappedFilesFunction · 0.45

Calls 5

readFileFunction · 0.85
decoderInputFileInfoIDsFunction · 0.85
ReadFileMethod · 0.65
OnParityFileLoadMethod · 0.65

Tested by 9

testCreateFunction · 0.36
testWriteParityFunction · 0.36
testShardCountsFunction · 0.36
testDecoderVerifyFunction · 0.36
TestSetIDMismatchFunction · 0.36
testDecoderRepairFunction · 0.36
TestRepairAddedBytesFunction · 0.36
TestRepairRemovedBytesFunction · 0.36
TestRepairSwappedFilesFunction · 0.36