FB-1548 - Added a fix for panic error that could happen when a view is opened by the ingest process but at the same time, was also deleted by TTL (#2147)

This commit is contained in:
hphamMolecula 2022-07-18 17:35:34 -05:00 • committed by GitHub
parent ccbc944eea
commit 41c59b77fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -1110,7 +1110,7 @@ func (f *Field) createViewIfNotExistsBase(cvm *CreateViewMessage) (*view, bool,
// If we already have this view, we can probably assume etcd already
// has it.
if view := f.viewMap[cvm.View]; view != nil {
if view := f.viewMap[cvm.View]; view != nil && !view.isClosing() {
return view, false, nil
}
@ -1142,6 +1142,8 @@ func (f *Field) newView(path, name string) *view {
// deleteView removes the view from the field.
func (f *Field) deleteView(name string) error {
f.mu.Lock()
defer f.mu.Unlock()
view := f.viewMap[name]
if view == nil {
return ErrInvalidView

View file

@ -444,6 +444,9 @@ func (b *Bitmap) DirectAdd(v uint64) bool {
// Contains returns true if v is in the bitmap.
func (b *Bitmap) Contains(v uint64) bool {
if b == nil {
return false
}
c := b.Containers.Get(highbits(v))
if c == nil {
return false

13
view.go
View file

@ -331,11 +331,24 @@ func (v *view) Name() string {
return v.name
}
func (v *view) isClosing() bool {
select {
case <-v.closing:
return true
default:
return false
}
}
// CreateFragmentIfNotExists returns a fragment in the view by shard.
func (v *view) CreateFragmentIfNotExists(shard uint64) (*fragment, error) {
v.mu.Lock()
defer v.mu.Unlock()
if v.isClosing() {
return nil, fmt.Errorf("cannot create fragment, view is closed")
}
// Find fragment in cache first.
if frag := v.fragments[shard]; frag != nil {
return frag, nil