lightning: release memory pool when external engine close (#48537)
close pingcap/tidb#48538
This commit is contained in:
17
br/pkg/lightning/backend/external/engine.go
vendored
17
br/pkg/lightning/backend/external/engine.go
vendored
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user