Skip to content

Commit

Permalink
fix autotune fec mis-align when parameters are different
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Oct 12, 2023
1 parent b6abd38 commit ceebe17
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions fec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type fecDecoder struct {
codec reedsolomon.Encoder

// auto tune fec parameter
autoTune autoTune
autoTune autoTune
shouldTune bool
}

func newFECDecoder(dataShards, parityShards int) *fecDecoder {
Expand Down Expand Up @@ -78,18 +79,17 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) {
}

// check if FEC parameters is out of sync
var shouldTune bool
if int(in.seqid())%dec.shardSize < dec.dataShards {
if in.flag() != typeData { // expect typeData
shouldTune = true
dec.shouldTune = true
}
} else {
if in.flag() != typeParity {
shouldTune = true
dec.shouldTune = true
}
}

if shouldTune {
if dec.shouldTune {
autoDS := dec.autoTune.FindPeriod(true)
autoPS := dec.autoTune.FindPeriod(false)

Expand All @@ -108,11 +108,17 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) {
dec.codec = codec
dec.decodeCache = make([][]byte, dec.shardSize)
dec.flagCache = make([]bool, dec.shardSize)
dec.shouldTune = false
//log.Println("autotune to :", dec.dataShards, dec.parityShards)
}
}
}

// parameters in tuning
if dec.shouldTune {
return nil
}

// insertion
n := len(dec.rx) - 1
insertIdx := 0
Expand Down

0 comments on commit ceebe17

Please sign in to comment.