Skip to content

Commit

Permalink
meta: move entryPool from redis to dump.go (#4759)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored Apr 23, 2024
1 parent 4609254 commit 7ea4f2b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
34 changes: 34 additions & 0 deletions pkg/meta/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"strings"
"sync"
"unicode/utf8"

"github.com/goccy/go-json"
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 0 additions & 33 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ea4f2b

Please sign in to comment.