Merge pull request #1527 from tgruben/core-334-fix

[CORE-334]  more graceful error handling for corrupt containers
This commit is contained in:
tgruben 2021-03-12 15:16:12 -06:00 committed by GitHub
commit 29b8501aff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

24
rbf.go
View file

@ -284,15 +284,21 @@ func (tx *RBFTx) addOrRemove(index, field, view string, shard uint64, batched, r
// not first time through, write what we got.
if remove && (rc == nil || rc.N() == 0) {
err = tx.RemoveContainer(index, field, view, shard, lastHi)
panicOn(err)
if err != nil {
return 0, errors.Wrap(err, "failed to remove container")
}
} else {
err = tx.PutContainer(index, field, view, shard, lastHi, rc)
panicOn(err)
if err != nil {
return 0, errors.Wrap(err, "failed to put container")
}
}
}
// get the next container
rc, err = tx.Container(index, field, view, shard, hi)
panicOn(err)
if err != nil {
return 0, errors.Wrap(err, "failed to retrieve container")
}
} // else same container, keep adding bits to rct.
chng := false
// rc can be nil before, and nil after, in both Remove/Add below.
@ -311,17 +317,23 @@ func (tx *RBFTx) addOrRemove(index, field, view string, shard uint64, batched, r
if remove {
if rc == nil || rc.N() == 0 {
err = tx.RemoveContainer(index, field, view, shard, hi)
panicOn(err)
if err != nil {
return 0, errors.Wrap(err, "failed to remove container")
}
} else {
err = tx.PutContainer(index, field, view, shard, hi, rc)
panicOn(err)
if err != nil {
return 0, errors.Wrap(err, "failed to put container")
}
}
} else {
if rc == nil || rc.N() == 0 {
panic("there should be no way to have an empty bitmap AFTER an Add() operation")
}
err = tx.PutContainer(index, field, view, shard, hi, rc)
panicOn(err)
if err != nil {
return 0, errors.Wrap(err, "failed to put container")
}
}
return
}