search: close unused reader and writer on re-indexing (#49458)

This commit is contained in:
Alexander Emelin 2022-05-24 09:42:21 +03:00 committed by GitHub
parent 5eb20739c2
commit 1e7e149ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -235,6 +235,12 @@ func (i *dashboardIndex) buildOrgIndex(ctx context.Context, orgID int64) (int, e
"orgSearchDashboardCount", len(dashboards))
i.mu.Lock()
if oldReader, ok := i.perOrgReader[orgID]; ok {
_ = oldReader.Close()
}
if oldWriter, ok := i.perOrgWriter[orgID]; ok {
_ = oldWriter.Close()
}
i.perOrgReader[orgID] = reader
i.perOrgWriter[orgID] = writer
i.mu.Unlock()
@ -347,6 +353,7 @@ func (i *dashboardIndex) applyDashboardEvent(ctx context.Context, orgID int64, d
// Skip event for org not yet fully indexed.
return nil
}
// TODO: should we release index lock while performing removeDashboard/updateDashboard?
reader, ok := i.perOrgReader[orgID]
if !ok {
// Skip event for org not yet fully indexed.
@ -364,6 +371,7 @@ func (i *dashboardIndex) applyDashboardEvent(ctx context.Context, orgID int64, d
if err != nil {
return err
}
_ = reader.Close()
i.perOrgReader[orgID] = newReader
return nil
}