Documentation ¶
Overview ¶
Copyright 2021 Erigon contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2021 Erigon contributors ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func AssertCheckValues(ctx context.Context, tx kv.Tx, cache Cache) (int, error)
- func Less(a, b *Element) bool
- type Cache
- type CacheValidationResult
- type CacheView
- type Coherent
- func (c *Coherent) Get(k []byte, tx kv.Tx, id uint64) ([]byte, error)
- func (c *Coherent) GetCode(k []byte, tx kv.Tx, id uint64) ([]byte, error)
- func (c *Coherent) Len() int
- func (c *Coherent) OnNewBlock(stateChanges *remote.StateChangeBatch)
- func (c *Coherent) ValidateCurrentRoot(ctx context.Context, tx kv.Tx) (*CacheValidationResult, error)
- func (c *Coherent) View(ctx context.Context, tx kv.Tx) (CacheView, error)
- type CoherentConfig
- type CoherentRoot
- type CoherentView
- type DummyCache
- func (c *DummyCache) Evict() int
- func (c *DummyCache) Get(k []byte, tx kv.Tx, id uint64) ([]byte, error)
- func (c *DummyCache) GetCode(k []byte, tx kv.Tx, id uint64) ([]byte, error)
- func (c *DummyCache) Len() int
- func (c *DummyCache) OnNewBlock(sc *remote.StateChangeBatch)
- func (c *DummyCache) ValidateCurrentRoot(_ context.Context, _ kv.Tx) (*CacheValidationResult, error)
- func (c *DummyCache) View(_ context.Context, tx kv.Tx) (CacheView, error)
- type DummyView
- type Element
- type List
- func (l *List) Back() *Element
- func (l *List) Front() *Element
- func (l *List) Init() *List
- func (l *List) InsertAfter(e *Element, mark *Element) *Element
- func (l *List) InsertBefore(e *Element, mark *Element) *Element
- func (l *List) Len() int
- func (l *List) MoveAfter(e, mark *Element)
- func (l *List) MoveBefore(e, mark *Element)
- func (l *List) MoveToBack(e *Element)
- func (l *List) MoveToFront(e *Element)
- func (l *List) PushBack(e *Element) *Element
- func (l *List) PushFront(e *Element) *Element
- func (l *List) Remove(e *Element) ([]byte, []byte)
- func (l *List) Size() int
- type Stat
- type ThreadSafeEvictionList
- func (l *ThreadSafeEvictionList) Init()
- func (l *ThreadSafeEvictionList) Len() int
- func (l *ThreadSafeEvictionList) MoveToFront(e *Element)
- func (l *ThreadSafeEvictionList) Oldest() *Element
- func (l *ThreadSafeEvictionList) PushFront(e *Element)
- func (l *ThreadSafeEvictionList) Remove(e *Element)
- func (l *ThreadSafeEvictionList) Size() int
Constants ¶
const ( DEGREE = 32 MAX_WAITS = 100 )
Variables ¶
var DefaultCoherentConfig = CoherentConfig{ KeepViews: 5, NewBlockWait: 5 * time.Millisecond, CacheSize: 2 * datasize.GB, CodeCacheSize: 2 * datasize.GB, MetricsLabel: "default", WithStorage: true, WaitForNewBlock: true, }
Functions ¶
func AssertCheckValues ¶
Types ¶
type CacheValidationResult ¶
type Coherent ¶
type Coherent struct {
// contains filtered or unexported fields
}
Coherent High-level guaranties: - Keys/Values returned by cache are valid/immutable until end of db transaction - CacheView is always coherent with given db transaction -
Rules of set view.isCanonical value:
- method View can't parent.Clone() - because parent view is not coherent with current kv.Tx
- only OnNewBlock method may do parent.Clone() and apply StateChanges to create coherent view of kv.Tx
- parent.Clone() can't be caled if parent.isCanonical=false
- only OnNewBlock method can set view.isCanonical=true
Rules of filling cache.stateEvict:
- changes in Canonical View SHOULD reflect in stateEvict
- changes in Non-Canonical View SHOULD NOT reflect in stateEvict
func New ¶
func New(cfg CoherentConfig) *Coherent
func (*Coherent) OnNewBlock ¶
func (c *Coherent) OnNewBlock(stateChanges *remote.StateChangeBatch)
func (*Coherent) ValidateCurrentRoot ¶
type CoherentConfig ¶
type CoherentConfig struct { CacheSize datasize.ByteSize CodeCacheSize datasize.ByteSize WaitForNewBlock bool // should we wait 10ms for a new block message to arrive when calling View? WithStorage bool MetricsLabel string NewBlockWait time.Duration // how long wait KeepViews uint64 // keep in memory up to this amount of views, evict older }
type CoherentRoot ¶
type CoherentRoot struct {
// contains filtered or unexported fields
}
type CoherentView ¶
type CoherentView struct {
// contains filtered or unexported fields
}
CoherentView - dumb object, which proxy all requests to Coherent object. It's thread-safe, because immutable
type DummyCache ¶
type DummyCache struct{}
DummyCache - doesn't remember anything - can be used when service is not remote
func NewDummy ¶
func NewDummy() *DummyCache
func (*DummyCache) Evict ¶
func (c *DummyCache) Evict() int
func (*DummyCache) Len ¶
func (c *DummyCache) Len() int
func (*DummyCache) OnNewBlock ¶
func (c *DummyCache) OnNewBlock(sc *remote.StateChangeBatch)
func (*DummyCache) ValidateCurrentRoot ¶
func (c *DummyCache) ValidateCurrentRoot(_ context.Context, _ kv.Tx) (*CacheValidationResult, error)
type Element ¶
type Element struct {
// The value stored with this element.
K, V []byte
// contains filtered or unexported fields
}
Element is an element of a linked list.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a doubly linked list. The zero value for List is an empty list ready to use.
func (*List) InsertAfter ¶
InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*List) InsertBefore ¶
InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*List) MoveAfter ¶
MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List) MoveBefore ¶
MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List) MoveToBack ¶
MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List) MoveToFront ¶
MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List) PushBack ¶
PushBack inserts a new element e with value v at the back of list l and returns e.
func (*List) PushFront ¶
PushFront inserts a new element e with value v at the front of list l and returns e.
type Stat ¶
func DebugStats ¶
type ThreadSafeEvictionList ¶
type ThreadSafeEvictionList struct {
// contains filtered or unexported fields
}
func (*ThreadSafeEvictionList) Init ¶
func (l *ThreadSafeEvictionList) Init()
func (*ThreadSafeEvictionList) Len ¶
func (l *ThreadSafeEvictionList) Len() int
func (*ThreadSafeEvictionList) MoveToFront ¶
func (l *ThreadSafeEvictionList) MoveToFront(e *Element)
func (*ThreadSafeEvictionList) Oldest ¶
func (l *ThreadSafeEvictionList) Oldest() *Element
func (*ThreadSafeEvictionList) PushFront ¶
func (l *ThreadSafeEvictionList) PushFront(e *Element)
func (*ThreadSafeEvictionList) Remove ¶
func (l *ThreadSafeEvictionList) Remove(e *Element)
func (*ThreadSafeEvictionList) Size ¶
func (l *ThreadSafeEvictionList) Size() int