added more graceful error handling for corrupt containers

This commit is contained in:
Todd Gruben 2021-03-12 10:37:40 -06:00
parent 1b486ac812
commit 94d7b295ea
2 changed files with 27 additions and 12 deletions

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, rbf.ErrTxFailedToRemoveContainer
}
} else {
err = tx.PutContainer(index, field, view, shard, lastHi, rc)
panicOn(err)
if err != nil {
return 0, rbf.ErrTxFailedToPutContainer
}
}
}
// get the next container
rc, err = tx.Container(index, field, view, shard, hi)
panicOn(err)
if err != nil {
return 0, rbf.ErrTxFailedToRetrieveContainer
}
} // 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, rbf.ErrTxFailedToRemoveContainer
}
} else {
err = tx.PutContainer(index, field, view, shard, hi, rc)
panicOn(err)
if err != nil {
return 0, rbf.ErrTxFailedToPutContainer
}
}
} 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, rbf.ErrTxFailedToPutContainer
}
}
return
}

View file

@ -111,12 +111,15 @@ const (
)
var (
ErrTxClosed = errors.New("transaction closed")
ErrTxNotWritable = errors.New("transaction not writable")
ErrBitmapNameRequired = errors.New("bitmap name required")
ErrBitmapNotFound = errors.New("bitmap not found")
ErrBitmapExists = errors.New("bitmap already exists")
ErrTxTooLarge = errors.New("rbf tx too large")
ErrTxClosed = errors.New("transaction closed")
ErrTxNotWritable = errors.New("transaction not writable")
ErrBitmapNameRequired = errors.New("bitmap name required")
ErrBitmapNotFound = errors.New("bitmap not found")
ErrBitmapExists = errors.New("bitmap already exists")
ErrTxTooLarge = errors.New("rbf tx too large")
ErrTxFailedToRemoveContainer = errors.New("rbf tx failed to remove container")
ErrTxFailedToPutContainer = errors.New("rbf tx failed to put container")
ErrTxFailedToRetrieveContainer = errors.New("rbf tx failed to put container")
)
// Debug is just a temporary flag used for debugging.