diff --git a/internal/metarepos/report_collector.go b/internal/metarepos/report_collector.go index d54d83966..31740958b 100644 --- a/internal/metarepos/report_collector.go +++ b/internal/metarepos/report_collector.go @@ -636,6 +636,7 @@ func (rce *reportCollectExecutor) getReport(ctx context.Context) error { } report := rce.processReport(response) + defer report.Release() if report.Len() > 0 { if err := rce.helper.ProposeReport(rce.storageNodeID, report.UncommitReports); err != nil { rce.reportCtx.setExpire() @@ -646,10 +647,8 @@ func (rce *reportCollectExecutor) getReport(ctx context.Context) error { } func (rce *reportCollectExecutor) processReport(response *snpb.GetReportResponse) *mrpb.StorageNodeUncommitReport { - report := &mrpb.StorageNodeUncommitReport{ - StorageNodeID: response.StorageNodeID, - UncommitReports: response.UncommitReports, - } + report := mrpb.NewStoragenodeUncommitReport(response.StorageNodeID) + report.UncommitReports = response.UncommitReports if report.Len() == 0 { return report @@ -664,9 +663,9 @@ func (rce *reportCollectExecutor) processReport(response *snpb.GetReportResponse return report } - diff := &mrpb.StorageNodeUncommitReport{ - StorageNodeID: report.StorageNodeID, - } + diff := mrpb.NewStoragenodeUncommitReport(report.StorageNodeID) + diff.UncommitReports = make([]snpb.LogStreamUncommitReport, 0, len(report.UncommitReports)) + defer report.Release() i := 0 j := 0 @@ -919,7 +918,8 @@ func (rc *reportContext) saveReport(report *mrpb.StorageNodeUncommitReport) { rc.mu.Lock() defer rc.mu.Unlock() - rc.report = report + rc.report = mrpb.NewStoragenodeUncommitReport(report.StorageNodeID) + rc.report.UncommitReports = report.UncommitReports } func (rc *reportContext) getReport() *mrpb.StorageNodeUncommitReport { diff --git a/proto/mrpb/raft_metadata_repository.go b/proto/mrpb/raft_metadata_repository.go index 507c5e90c..c0ab8d02c 100644 --- a/proto/mrpb/raft_metadata_repository.go +++ b/proto/mrpb/raft_metadata_repository.go @@ -2,6 +2,7 @@ package mrpb import ( "sort" + "sync" "github.com/kakao/varlog/pkg/types" "github.com/kakao/varlog/proto/snpb" @@ -75,6 +76,24 @@ func (l *LogStreamUncommitReports) Deleted() bool { return l.Status == varlogpb.LogStreamStatusDeleted } +var storageNodeUncommitReportPool = sync.Pool{ + New: func() any { + return new(StorageNodeUncommitReport) + }, +} + +func NewStoragenodeUncommitReport(snid types.StorageNodeID) *StorageNodeUncommitReport { + r := storageNodeUncommitReportPool.Get().(*StorageNodeUncommitReport) + r.StorageNodeID = snid + return r +} + +func (l *StorageNodeUncommitReport) Release() { + l.StorageNodeID = types.StorageNodeID(0) + l.UncommitReports = nil + storageNodeUncommitReportPool.Put(l) +} + func (l *StorageNodeUncommitReport) Len() int { return len(l.UncommitReports) }