Skip to content

Commit

Permalink
Fixing issue with bit allocation byteoffset calculation
Browse files Browse the repository at this point in the history
The byteoffset calculation was skewed to double include
the offset value calculated. The double calculation
happens if the starting ordinal is part of the head
sequence block. This error in calculation could result
in duplicate but getting allocated eventually propogating
to ipam and vni id allocations

Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
  • Loading branch information
abhi committed Jun 5, 2017
1 parent 8b46b24 commit 62472f3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bitseq/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ func (h *Handle) set(ordinal, start, end uint64, any bool, release bool) (uint64
} else {
nh.unselected--
}

// Attempt to write private copy to store
if err := nh.writeToStore(); err != nil {
if _, ok := err.(types.RetryError); !ok {
Expand Down Expand Up @@ -492,22 +491,27 @@ func (h *Handle) UnmarshalJSON(data []byte) error {

// getFirstAvailable looks for the first unset bit in passed mask starting from start
func getFirstAvailable(head *sequence, start uint64) (uint64, uint64, error) {

// Find sequence which contains the start bit
byteStart, bitStart := ordinalToPos(start)
current, _, _, inBlockBytePos := findSequence(head, byteStart)

// Derive the this sequence offsets
byteOffset := byteStart - inBlockBytePos
bitOffset := inBlockBytePos*8 + bitStart

var firstOffset uint64
if current == head {
firstOffset = byteOffset
}
for current != nil {
if current.block != blockMAX {
bytePos, bitPos, err := current.getAvailableBit(bitOffset)
return byteOffset + bytePos, bitPos, err
}
// Moving to next block: Reset bit offset.
bitOffset = 0
byteOffset += current.count * blockBytes
byteOffset += (current.count * blockBytes) - firstOffset
firstOffset = 0
current = current.next
}
return invalidPos, invalidPos, ErrNoBitAvailable
Expand All @@ -524,6 +528,7 @@ func getAvailableFromCurrent(head *sequence, start, curr, end uint64) (uint64, u
if end < ret {
goto begin
}

return bytePos, bitPos, nil
}

Expand Down

0 comments on commit 62472f3

Please sign in to comment.