lightning: release memory pool when external engine close (#48537)

close pingcap/tidb#48538
This commit is contained in:
lance6716
2023-11-17 16:53:18 +08:00
committed by GitHub
parent a4f85c3568
commit 4f2a69eca7
2 changed files with 26 additions and 1 deletions

View File

@ -379,7 +379,22 @@ func (e *Engine) SplitRanges(
}
// Close implements common.Engine.
func (e *Engine) Close() error { return nil }
func (e *Engine) Close() error {
if e.bufPool != nil {
e.bufPool.Destroy()
e.bufPool = nil
}
return nil
}
// Reset resets the memory buffer pool.
func (e *Engine) Reset() error {
if e.bufPool != nil {
e.bufPool.Destroy()
e.bufPool = membuf.NewPool()
}
return nil
}
// MemoryIngestData is the in-memory implementation of IngestData.
type MemoryIngestData struct {

View File

@ -1734,6 +1734,11 @@ func (local *Backend) ResetEngine(ctx context.Context, engineUUID uuid.UUID) err
// the only way to reset the engine + reclaim the space is to delete and reopen it 🤷
localEngine := local.lockEngine(engineUUID, importMutexStateClose)
if localEngine == nil {
if engineI, ok := local.externalEngine[engineUUID]; ok {
extEngine := engineI.(*external.Engine)
return extEngine.Reset()
}
log.FromContext(ctx).Warn("could not find engine in cleanupEngine", zap.Stringer("uuid", engineUUID))
return nil
}
@ -1767,6 +1772,11 @@ func (local *Backend) CleanupEngine(ctx context.Context, engineUUID uuid.UUID) e
localEngine := local.lockEngine(engineUUID, importMutexStateClose)
// release this engine after import success
if localEngine == nil {
if extEngine, ok := local.externalEngine[engineUUID]; ok {
retErr := extEngine.Close()
delete(local.externalEngine, engineUUID)
return retErr
}
log.FromContext(ctx).Warn("could not find engine in cleanupEngine", zap.Stringer("uuid", engineUUID))
return nil
}