From 7ea4f2bac62a3f1c6dbecdcd6cc08a84992c1f54 Mon Sep 17 00:00:00 2001 From: Sandy Xu Date: Tue, 23 Apr 2024 19:56:26 +0800 Subject: [PATCH] meta: move entryPool from redis to dump.go (#4759) --- pkg/meta/dump.go | 34 ++++++++++++++++++++++++++++++++++ pkg/meta/redis.go | 33 --------------------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/pkg/meta/dump.go b/pkg/meta/dump.go index 1d8ad4e7e01f..8e3b7f0b8e70 100644 --- a/pkg/meta/dump.go +++ b/pkg/meta/dump.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "strings" + "sync" "unicode/utf8" "github.com/goccy/go-json" @@ -125,6 +126,39 @@ type DumpedEntry struct { DefaultACL *DumpedACL `json:"posix_acl_default,omitempty"` } +type wrapEntryPool struct { + sync.Pool +} + +func (p *wrapEntryPool) Get() *DumpedEntry { + return p.Pool.Get().(*DumpedEntry) +} + +func (p *wrapEntryPool) Put(de *DumpedEntry) { + if de == nil { + return + } + + de.Name = "" + de.Xattrs = nil + de.Chunks = nil + de.Symlink = "" + de.AccessACL = nil + de.DefaultACL = nil + de.Entries = nil + p.Pool.Put(de) +} + +var entryPool = wrapEntryPool{ + Pool: sync.Pool{ + New: func() interface{} { + return &DumpedEntry{ + Attr: &DumpedAttr{}, + } + }, + }, +} + var CHARS = []byte("0123456789ABCDEF") func escape(original string) string { diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index 99e22c9282c6..982ed6986a69 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -3500,39 +3500,6 @@ func (m *redisMeta) checkServerConfig() { logger.Infof("Ping redis latency: %s", time.Since(start)) } -type wrapEntryPool struct { - sync.Pool -} - -func (p *wrapEntryPool) Get() *DumpedEntry { - return p.Pool.Get().(*DumpedEntry) -} - -func (p *wrapEntryPool) Put(de *DumpedEntry) { - if de == nil { - return - } - - de.Name = "" - de.Xattrs = nil - de.Chunks = nil - de.Symlink = "" - de.AccessACL = nil - de.DefaultACL = nil - de.Entries = nil - p.Pool.Put(de) -} - -var entryPool = wrapEntryPool{ - Pool: sync.Pool{ - New: func() interface{} { - return &DumpedEntry{ - Attr: &DumpedAttr{}, - } - }, - }, -} - func (m *redisMeta) dumpEntries(es ...*DumpedEntry) error { ctx := Background var keys []string