Prevent old packets resolution. (#2134)

* Prevent old packets resolution.

With range map, we are just looking up ranges and not exactly
which packets were missing. This caused the case of old packets
being resolved after layer switch.

For example,
- Packet 10 is layer switch, range map gets reset
- Packet 11, 12, 13 are forwarded
- Packet 9 comes, it should ideally be dropped as pre-layer switch old
  packet. But, when looking up range map, it gets an offset and hence
  gets re-mapped to something before layer switch. This was probably
  okay as decoders would have had a key frame at the switch point and
  moved ahead, but incorrect technically.

Fix is to reset the start point in the range map to the switch point
and not 0. So, when packet 9 comes, range map will return "key too old"
error and that packet will be dropped as missing from cache.

* fix tests
This commit is contained in:
Raja Subramanian
2023-10-07 10:56:34 +05:30
committed by GitHub
parent f40a97fd3e
commit 2ff8fe3b78
5 changed files with 82 additions and 33 deletions
+5 -5
View File
@@ -59,12 +59,12 @@ func NewRangeMap[RT rangeType, VT valueType](size int) *RangeMap[RT, VT] {
halfRange: 1 << ((unsafe.Sizeof(t) * 8) - 1),
size: int(math.Max(float64(size), float64(minRanges))),
}
r.initRanges(0)
r.initRanges(0, 0)
return r
}
func (r *RangeMap[RT, VT]) ClearAndResetValue(val VT) {
r.initRanges(val)
func (r *RangeMap[RT, VT]) ClearAndResetValue(start RT, val VT) {
r.initRanges(start, val)
}
func (r *RangeMap[RT, VT]) DecValue(end RT, dec VT) {
@@ -87,10 +87,10 @@ func (r *RangeMap[RT, VT]) DecValue(end RT, dec VT) {
r.prune()
}
func (r *RangeMap[RT, VT]) initRanges(val VT) {
func (r *RangeMap[RT, VT]) initRanges(start RT, val VT) {
r.ranges = []rangeVal[RT, VT]{
{
start: 0,
start: start,
end: 0,
value: val,
},
+12 -7
View File
@@ -219,10 +219,10 @@ func TestRangeMapUint32(t *testing.T) {
require.Equal(t, uint32(17), value)
// reset
r.ClearAndResetValue(23)
r.ClearAndResetValue(24, 23)
expectedRanges = []rangeVal[uint32, uint32]{
{
start: 0,
start: 24,
end: 0,
value: 23,
},
@@ -233,12 +233,13 @@ func TestRangeMapUint32(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint32(23), value)
// decrement value and ensure that any key returns that value
// decrement value and ensure that any key after start in ClearAndResetValue above returns that value
// (as given end is higher than open range start, open range should be closed and a new range added)
r.DecValue(34, 12)
expectedRanges = []rangeVal[uint32, uint32]{
{
start: 0,
start: 24,
end: 34,
value: 23,
},
@@ -260,7 +261,7 @@ func TestRangeMapUint32(t *testing.T) {
expectedRanges = []rangeVal[uint32, uint32]{
{
start: 0,
start: 24,
end: 34,
value: 23,
},
@@ -277,8 +278,12 @@ func TestRangeMapUint32(t *testing.T) {
}
require.Equal(t, expectedRanges, r.ranges)
// first range access
// before first range access
value, err = r.GetValue(5)
require.ErrorIs(t, err, errKeyTooOld)
// first range access
value, err = r.GetValue(25)
require.NoError(t, err)
require.Equal(t, uint32(23), value)
@@ -314,7 +319,7 @@ func TestRangeMapUint32(t *testing.T) {
require.Equal(t, expectedRanges, r.ranges)
// aged out range access
value, err = r.GetValue(5)
value, err = r.GetValue(25)
require.ErrorIs(t, err, errKeyTooOld)
// access closed range before decrementing value