@@ -83,7 +83,6 @@ type Domain struct {
8383 //
8484 // BeginRo() using _visible in zero-copy way
8585 dirtyFiles * btree2.BTreeG [* FilesItem ]
86- cache * domainCache // protected by visibleFiles lock
8786
8887 // _visible - underscore in name means: don't use this field directly, use BeginFilesRo()
8988 // underlying array is immutable - means it's ready for zero-copy use
@@ -92,11 +91,7 @@ type Domain struct {
9291 checker * DependencyIntegrityChecker
9392}
9493
95- type domainCache struct {
96- c * DomainGetFromFileCache
97- }
98-
99- func newDomainCache (name kv.Domain ) * domainCache {
94+ func newDomainCache (name kv.Domain ) * DomainGetFromFileCache {
10095 limit := domainGetFromFileCacheLimit
10196 if name == kv .CodeDomain {
10297 limit = limit / 10 // CodeDomain has compressed values - means cache will store values (instead of pointers to mmap)
@@ -105,44 +100,13 @@ func newDomainCache(name kv.Domain) *domainCache {
105100 domainGetFromFileCacheEnabled = false
106101 return nil
107102 }
108- return & domainCache {c : NewDomainGetFromFileCache (domainGetFromFileCacheLimit )}
109- }
110-
111- func (d * domainCache ) Add (key uint64 , value domainGetFromFileCacheItem ) {
112- d .c .Add (key , value )
113- }
114-
115- func (d * domainCache ) Get (key uint64 ) (value domainGetFromFileCacheItem , ok bool ) {
116- return d .c .Get (key )
103+ return NewDomainGetFromFileCache (domainGetFromFileCacheLimit )
117104}
118105
119- // func newDomainVisible(name kv.Domain, files []visibleFile) *domainVisible {
120- // d := &domainVisible{
121- // name: name,
122- // files: files,
123- // }
124- // limit := domainGetFromFileCacheLimit
125- // if name == kv.CodeDomain {
126- // limit = limit / 10 // CodeDomain has compressed values - means cache will store values (instead of pointers to mmap)
127- // }
128- // if limit == 0 {
129- // domainGetFromFileCacheEnabled = false
130- // }
131- // d.caches = &sync.Pool{New: func() any { return NewDomainGetFromFileCache(limit) }}
132- // return d
133- // }
134-
135- // func (v *domainVisible) newGetFromFileCache() *DomainGetFromFileCache {
136- // if !domainGetFromFileCacheEnabled {
137- // return nil
138- // }
139- // return v.caches.Get().(*DomainGetFromFileCache)
140- // }
141-
142106type domainVisible struct {
143107 files []visibleFile
144108 name kv.Domain
145- //caches *sync.Pool
109+ cache * DomainGetFromFileCache
146110}
147111
148112func NewDomain (cfg statecfg.DomainCfg , stepSize uint64 , dirs datadir.Dirs , logger log.Logger ) (* Domain , error ) {
@@ -389,7 +353,7 @@ func (d *Domain) reCalcVisibleFiles(toTxNum uint64) {
389353 }
390354 }
391355 d ._visible = newDomainVisible (d .Name , calcVisibleFiles (d .dirtyFiles , d .Accessors , checker , false , toTxNum ))
392- d .cache = newDomainCache (d .Name ) // old value should be GC'ed
356+ d ._visible . cache = newDomainCache (d .Name ) // old value should be GC'ed
393357 d .History .reCalcVisibleFiles (toTxNum )
394358}
395359
@@ -659,6 +623,10 @@ func (d *Domain) BeginFilesRo() *DomainRoTx {
659623 }
660624 }
661625
626+ if d ._visible .cache == nil {
627+ d ._visible .cache = newDomainCache (d .Name )
628+ }
629+
662630 return & DomainRoTx {
663631 name : d .Name ,
664632 stepSize : d .stepSize ,
@@ -667,7 +635,7 @@ func (d *Domain) BeginFilesRo() *DomainRoTx {
667635 visible : d ._visible ,
668636 files : d ._visible .files ,
669637 salt : d .salt .Load (),
670- getFromFileCache : d .cache . c ,
638+ getFromFileCache : d ._visible . cache ,
671639 }
672640}
673641
0 commit comments