milkyway

package
v0.0.0-...-e70b4cf Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLoadFactor = 0.98
)
View Source
const (
	Filepath = "milkyway"
)

Variables

View Source
var (
	SeparatorString = "-"
	// Separator perseus ca
	Separator = byte(202)

	ErrKeyLengthCannotBeZero = errors.New("the key length cannot be 0")
	ErrNotTimestampKey       = errors.New("not timestamp txid")
	ErrTimestampKeyIsInvalid = errors.New("TxId nanosecond is invalid")
)
View Source
var (
	ErrKeyCannotBeEmpty                 = errors.New("key cannot be empty")
	ErrCannotModifyTheNestConfiguration = errors.New("when historical data exists, you cannot modify the nest " +
		"configuration")
	ErrMilkyWaySizeCannotBeZero = errors.New("the size cannot be 0")
)
View Source
var (
	ErrFilterExtensionNotSupport = NewError("filter extension not support type: %v")
)
View Source
var (
	ErrKeyItsSoLongAgoError = NewError("key %v is out of the range %v-%v")
)
View Source
var (

	// ErrKeyTimeIsNotInTheFilterRange Not error; Key time is not in the filter range
	ErrKeyTimeIsNotInTheFilterRange = errors.New("key time is not in the filter range")
)

Functions

func CurrentTimestampNano

func CurrentTimestampNano() int64

func Factory

func Factory() *factory

Factory return the global tx filter factory. nolint: revive

func LruStrategy

func LruStrategy(bn *MilkyWayImpl) error

LruStrategy Nest filter cycle elimination strategy

func ToStrings

func ToStrings(keys []Key) []string

ToStrings TimestampKey to string

func ToTimestampKeysAndNormalKeys

func ToTimestampKeysAndNormalKeys(key []string) (timestampKeys []Key, normalKeys []Key)

ToTimestampKeysAndNormalKeys string to TimestampKey return timestampKeys and normalKeys

Types

type AbsoluteExpireTimeRule

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

func NewAETRule

func NewAETRule(absoluteExpireTime int64) AbsoluteExpireTimeRule

func (AbsoluteExpireTimeRule) Validate

func (r AbsoluteExpireTimeRule) Validate(key Key) error

type DefaultFilterExtension

type DefaultFilterExtension struct {
}

func NewDefaultFilterExtension

func NewDefaultFilterExtension() *DefaultFilterExtension

func (DefaultFilterExtension) Serialize

func (d DefaultFilterExtension) Serialize() []byte

func (DefaultFilterExtension) Store

func (d DefaultFilterExtension) Store(Key) error

func (DefaultFilterExtension) Validate

func (d DefaultFilterExtension) Validate(Key, bool) error

type FilterEncoder

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

type FilterExtension

type FilterExtension interface {
	// Validate validate key
	Validate(key Key, full bool) error
	Store(key Key) error
	Serialize() []byte
}

FilterExtension filter extension

func DeserializeDefault

func DeserializeDefault() FilterExtension

func ExtensionDeserialize

func ExtensionDeserialize(bytes []byte) (FilterExtension, error)

func NewTimestampFilterExtension

func NewTimestampFilterExtension() FilterExtension

type Key

type Key interface {
	// Parse the key
	Parse() ([][]byte, error)
	// Key bytes
	Key() []byte
	// Len The length of the key
	Len() int
	String() string
	GetNano() int64
}

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Infof(format string, args ...interface{})
}

type MilkyWay

type MilkyWay interface {
	GetHeight() uint64
	SetHeight(height uint64)
	// Add the key
	Add(key Key) error
	// Adds adding Multiple Keys
	Adds(keys []Key) (result error)
	// AddsAndSetHeight Adds and SetHeight
	AddsAndSetHeight(keys []Key, height uint64) (result error)
	// Contains the key
	Contains(key Key, rules ...common.RuleType) (bool, error)
	ValidateRule(key Key, rules ...common.RuleType) error
	// Info Current pegasus nest information and status
	Info() []uint64

	Start()
}

MilkyWay

type MilkyWayImpl

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

MilkyWayImpl impl

func NewMilkyWay

func NewMilkyWay(config *common.MilkyWayConfig, exitC chan struct{}, strategy Strategy, logger Logger) (
	*MilkyWayImpl, error)

NewMilkyWay Create a MilkyWay

func NewMilkyWayByNumber

func NewMilkyWayByNumber(config *common.MilkyWayConfig, exitC chan struct{}, strategy Strategy, logger Logger,
	number int) (*MilkyWayImpl, error)

NewMilkyWayByNumber Create a numbered MilkyWay

func (*MilkyWayImpl) Add

func (b *MilkyWayImpl) Add(key Key) error

Add a Key

func (*MilkyWayImpl) Adds

func (b *MilkyWayImpl) Adds(keys []Key) error

Adds Add multiple Key

func (*MilkyWayImpl) AddsAndSetHeight

func (b *MilkyWayImpl) AddsAndSetHeight(keys []Key, height uint64) (result error)

AddsAndSetHeight Add multiple Key and set height

func (*MilkyWayImpl) Contains

func (b *MilkyWayImpl) Contains(key Key, rules ...common.RuleType) (bool, error)

Contains sync

func (*MilkyWayImpl) Deserialize

func (b *MilkyWayImpl) Deserialize() error

func (*MilkyWayImpl) GetHeight

func (b *MilkyWayImpl) GetHeight() uint64

GetHeight get current height

func (*MilkyWayImpl) Info

func (b *MilkyWayImpl) Info() []uint64

Info index 0 height index 1 pegasus size index 2 current index index 3 total pegasus size index 4 total space occupied by pegasus

func (*MilkyWayImpl) Serialize

func (b *MilkyWayImpl) Serialize() error

Serialize all cuckoos in the current MilkyWay

func (*MilkyWayImpl) SetHeight

func (b *MilkyWayImpl) SetHeight(height uint64)

SetHeight set height

func (*MilkyWayImpl) Start

func (b *MilkyWayImpl) Start()

Start TODO Goroutinue should be turned off using context.Context here

func (*MilkyWayImpl) ValidateRule

func (b *MilkyWayImpl) ValidateRule(key Key, rules ...common.RuleType) error

type PegasusFilter

type PegasusFilter interface {
	IsFull() bool
	Add(key Key) (bool, error)
	Contains(key Key) (bool, error)
	Encode() (FilterEncoder, error)
	Extension() FilterExtension
	Info() []uint64
}

func NewPegasusFilter

func NewPegasusFilter(config *common.PegasusConfig) PegasusFilter

NewPegasusFilter Params: common.PegasusConfig.TableType : has two constant parameters to choose from:

  1. TableTypeSingle normal single table
  2. TableTypePacked packed table, use semi-sort to save 1 bit per item

common.PegasusConfig.TagsPerBucket: num of tags for each bucket, which is b in paper. tag is fingerprint, which is f

in paper.

common.PegasusConfig.MaxNumKeys : num of keys that filter will store. this value should close to and lower

nextPow2(maxNumKeys/tagsPerBucket) * maxLoadFactor. cause table.NumBuckets is
always a power of two

common.PegasusConfig.BitsPerItem : num of bits for each item, which is length of tag(fingerprint) common.PegasusConfig.TableType : common.PegasusConfig.KeyType : 0 TableTypeSingle normal single table

1 TableTypePacked packed table, use semi-sort to save 1 bit per item
1 is recommended

Result: PegasusFilter

type PegasusFilterImpl

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

PegasusFilterImpl Pegasus Filter

func NewPegasusFilterByDecode

func NewPegasusFilterByDecode(filter *common.PegasusFilter) (*PegasusFilterImpl, error)

func (*PegasusFilterImpl) Add

func (c *PegasusFilterImpl) Add(key Key) (bool, error)

func (*PegasusFilterImpl) Config

func (c *PegasusFilterImpl) Config() ([]byte, error)

func (*PegasusFilterImpl) Contains

func (c *PegasusFilterImpl) Contains(key Key) (bool, error)

func (*PegasusFilterImpl) Encode

func (c *PegasusFilterImpl) Encode() (FilterEncoder, error)

func (*PegasusFilterImpl) Extension

func (c *PegasusFilterImpl) Extension() FilterExtension

func (*PegasusFilterImpl) Info

func (c *PegasusFilterImpl) Info() []uint64

Info index 0 pegasus size index 1 Space occupied by pegasus

func (*PegasusFilterImpl) IsFull

func (c *PegasusFilterImpl) IsFull() bool

type Rule

type Rule interface {
	Validate(Key) error
}

type Serializer

type Serializer interface {
	Serialize() error
	Deserialize() error
}

type SprintfError

type SprintfError string

func NewError

func NewError(s string) SprintfError

func (SprintfError) Error

func (s SprintfError) Error(a ...interface{}) error

type Strategy

type Strategy func(bn *MilkyWayImpl) error

type TestLogger

type TestLogger struct {
	T *testing.T
}

func (TestLogger) Debugf

func (t TestLogger) Debugf(format string, args ...interface{})

func (TestLogger) Errorf

func (t TestLogger) Errorf(format string, args ...interface{})

func (TestLogger) Infof

func (t TestLogger) Infof(format string, args ...interface{})

type TimestampFilterExtension

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

func DeserializeTimestamp

func DeserializeTimestamp(bytes []byte) (*TimestampFilterExtension, error)

func (*TimestampFilterExtension) Serialize

func (t *TimestampFilterExtension) Serialize() []byte

func (*TimestampFilterExtension) Store

func (t *TimestampFilterExtension) Store(key Key) error

func (*TimestampFilterExtension) Validate

func (t *TimestampFilterExtension) Validate(key Key, full bool) error

type TimestampKey

type TimestampKey []byte

TimestampKey Converting TxId directly using TimestampKey is not allowed, see ToTimestampKey

func ToTimestampKey

func ToTimestampKey(txId string) (TimestampKey, error)

func (TimestampKey) GetNano

func (k TimestampKey) GetNano() int64

func (TimestampKey) Key

func (k TimestampKey) Key() []byte

func (TimestampKey) Len

func (k TimestampKey) Len() int

func (TimestampKey) Parse

func (k TimestampKey) Parse() ([][]byte, error)

func (TimestampKey) String

func (k TimestampKey) String() string

type WalSnapshot

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

func NewWalSnapshot

func NewWalSnapshot(path, name string, number int) (*WalSnapshot, error)

eg: data/tx_filter/chainN/milkywayN

func (*WalSnapshot) Read

func (s *WalSnapshot) Read() ([]byte, error)

Read safe

func (*WalSnapshot) Write

func (s *WalSnapshot) Write(data []byte) error

TODO Filter 单独持久化 优化 下一版优化 Write safe

Jump to

Keyboard shortcuts

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