sanity-check: check whether containers are flagged as mapped before mapping

In the old unmarshal code, the decision to mark a thing as mapped (always
yes) happens separately from setting the mapping. What if this could ever
somehow possibly go wrong? Let's sanity-check that to be extra careful.
This commit is contained in:
Seebs 2020-02-07 12:55:49 -06:00 committed by Matt Jaffee
parent 7841a660a8
commit ba7db3028b
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -88,7 +88,12 @@ func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) error {
// Map byte slice directly to the container data.
citer.Next()
_, c := citer.Value()
k, c := citer.Value()
if !c.Mapped() {
fmt.Printf("inexplicable: container %d (%d/%d) doesn't think it's mapped. fixing that.\n",
k, i, keyN)
c.setMapped(true)
}
switch c.typ() {
case containerArray:
c.setArray((*[0xFFFFFFF]uint16)(unsafe.Pointer(&data[offset]))[:c.N():c.N()])
@ -108,7 +113,12 @@ func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) error {
citer, _ := b.Containers.Iterator(0)
for i := 0; i < int(keyN); i++ {
citer.Next()
_, c := citer.Value()
k, c := citer.Value()
if !c.Mapped() {
fmt.Printf("inexplicable: container %d (%d/%d) doesn't think it's mapped. fixing that.\n",
k, i, keyN)
c.setMapped(true)
}
switch c.typ() {
case containerRun:
runCount := binary.LittleEndian.Uint16(data[pos : pos+runCountHeaderSize])
@ -176,12 +186,17 @@ func (b *Bitmap) unmarshalPilosaRoaring(data []byte) error {
// Map byte slice directly to the container data.
citer.Next()
_, c := citer.Value()
k, c := citer.Value()
// this shouldn't happen, since we don't normally store nils.
if c == nil {
continue
}
if !c.Mapped() {
fmt.Printf("inexplicable: container %d (%d/%d) doesn't think it's mapped. fixing that.\n",
k, i, keyN)
c.setMapped(true)
}
switch c.typ() {
case containerRun:
runCount := binary.LittleEndian.Uint16(data[offset : offset+runCountHeaderSize])