kvcache

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 17 Imported by: 13

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.

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

View Source
const (
	DEGREE    = 32
	MAX_WAITS = 100
)

Variables

View Source
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

func AssertCheckValues(ctx context.Context, tx kv.Tx, cache Cache) (int, error)

func Less

func Less(a, b *Element) bool

Types

type Cache

type Cache interface {
	// View - returns CacheView consistent with givent kv.Tx
	View(ctx context.Context, tx kv.Tx) (CacheView, error)
	OnNewBlock(sc *remote.StateChangeBatch)
	Len() int
	ValidateCurrentRoot(ctx context.Context, tx kv.Tx) (*CacheValidationResult, error)
}

type CacheValidationResult

type CacheValidationResult struct {
	RequestCancelled   bool
	Enabled            bool
	LatestStateBehind  bool
	CacheCleared       bool
	LatestStateID      uint64
	StateKeysOutOfSync [][]byte
	CodeKeysOutOfSync  [][]byte
}

type CacheView

type CacheView interface {
	Get(k []byte) ([]byte, error)
	GetCode(k []byte) ([]byte, error)
}

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) Get

func (c *Coherent) Get(k []byte, tx kv.Tx, id uint64) ([]byte, error)

func (*Coherent) GetCode

func (c *Coherent) GetCode(k []byte, tx kv.Tx, id uint64) ([]byte, error)

func (*Coherent) Len

func (c *Coherent) Len() int

func (*Coherent) OnNewBlock

func (c *Coherent) OnNewBlock(stateChanges *remote.StateChangeBatch)

func (*Coherent) ValidateCurrentRoot

func (c *Coherent) ValidateCurrentRoot(ctx context.Context, tx kv.Tx) (*CacheValidationResult, error)

func (*Coherent) View

func (c *Coherent) View(ctx context.Context, tx kv.Tx) (CacheView, error)

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

func (*CoherentView) Get

func (c *CoherentView) Get(k []byte) ([]byte, error)

func (*CoherentView) GetCode

func (c *CoherentView) GetCode(k []byte) ([]byte, error)

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) Get

func (c *DummyCache) Get(k []byte, tx kv.Tx, id uint64) ([]byte, error)

func (*DummyCache) GetCode

func (c *DummyCache) GetCode(k []byte, tx kv.Tx, id uint64) ([]byte, error)

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)

func (*DummyCache) View

func (c *DummyCache) View(_ context.Context, tx kv.Tx) (CacheView, error)

type DummyView

type DummyView struct {
	// contains filtered or unexported fields
}

func (*DummyView) Get

func (c *DummyView) Get(k []byte) ([]byte, error)

func (*DummyView) GetCode

func (c *DummyView) GetCode(k []byte) ([]byte, 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.

func (*Element) Next

func (e *Element) Next() *Element

Next returns the next list element or nil.

func (*Element) Prev

func (e *Element) Prev() *Element

Prev returns the previous list element or nil.

func (*Element) Size

func (e *Element) Size() int

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 NewList

func NewList() *List

New returns an initialized list.

func (*List) Back

func (l *List) Back() *Element

Back returns the last element of list l or nil if the list is empty.

func (*List) Front

func (l *List) Front() *Element

Front returns the first element of list l or nil if the list is empty.

func (*List) Init

func (l *List) Init() *List

Init initializes or clears list l.

func (*List) InsertAfter

func (l *List) InsertAfter(e *Element, mark *Element) *Element

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

func (l *List) InsertBefore(e *Element, mark *Element) *Element

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) Len

func (l *List) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*List) MoveAfter

func (l *List) MoveAfter(e, mark *Element)

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

func (l *List) MoveBefore(e, mark *Element)

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

func (l *List) MoveToBack(e *Element)

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

func (l *List) MoveToFront(e *Element)

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

func (l *List) PushBack(e *Element) *Element

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*List) PushFront

func (l *List) PushFront(e *Element) *Element

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List) Remove

func (l *List) Remove(e *Element) ([]byte, []byte)

Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.

func (*List) Size

func (l *List) Size() int

Size returns the size of the elements in the list by bytes

type Stat

type Stat struct {
	BlockNum  uint64
	BlockHash [32]byte
	Lenght    int
}

func DebugStats

func DebugStats(cache Cache) []Stat

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL