Documentation ¶
Index ¶
- Constants
- Variables
- func CurrentTimestampNano() int64
- func Factory() *factory
- func LruStrategy(bn *MilkyWayImpl) error
- func ToStrings(keys []Key) []string
- func ToTimestampKeysAndNormalKeys(key []string) (timestampKeys []Key, normalKeys []Key)
- type AbsoluteExpireTimeRule
- type DefaultFilterExtension
- type FilterEncoder
- type FilterExtension
- type Key
- type Logger
- type MilkyWay
- type MilkyWayImpl
- func (b *MilkyWayImpl) Add(key Key) error
- func (b *MilkyWayImpl) Adds(keys []Key) error
- func (b *MilkyWayImpl) AddsAndSetHeight(keys []Key, height uint64) (result error)
- func (b *MilkyWayImpl) Contains(key Key, rules ...common.RuleType) (bool, error)
- func (b *MilkyWayImpl) Deserialize() error
- func (b *MilkyWayImpl) GetHeight() uint64
- func (b *MilkyWayImpl) Info() []uint64
- func (b *MilkyWayImpl) Serialize() error
- func (b *MilkyWayImpl) SetHeight(height uint64)
- func (b *MilkyWayImpl) Start()
- func (b *MilkyWayImpl) ValidateRule(key Key, rules ...common.RuleType) error
- type PegasusFilter
- type PegasusFilterImpl
- func (c *PegasusFilterImpl) Add(key Key) (bool, error)
- func (c *PegasusFilterImpl) Config() ([]byte, error)
- func (c *PegasusFilterImpl) Contains(key Key) (bool, error)
- func (c *PegasusFilterImpl) Encode() (FilterEncoder, error)
- func (c *PegasusFilterImpl) Extension() FilterExtension
- func (c *PegasusFilterImpl) Info() []uint64
- func (c *PegasusFilterImpl) IsFull() bool
- type Rule
- type Serializer
- type SprintfError
- type Strategy
- type TestLogger
- type TimestampFilterExtension
- type TimestampKey
- type WalSnapshot
Constants ¶
const (
DefaultLoadFactor = 0.98
)
const (
Filepath = "milkyway"
)
Variables ¶
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") )
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") )
var (
ErrFilterExtensionNotSupport = NewError("filter extension not support type: %v")
)
var (
ErrKeyItsSoLongAgoError = NewError("key %v is out of the range %v-%v")
)
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 LruStrategy ¶
func LruStrategy(bn *MilkyWayImpl) error
LruStrategy Nest filter cycle elimination strategy
func ToTimestampKeysAndNormalKeys ¶
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
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 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) AddsAndSetHeight ¶
func (b *MilkyWayImpl) AddsAndSetHeight(keys []Key, height uint64) (result error)
AddsAndSetHeight Add multiple Key and set height
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:
- TableTypeSingle normal single table
- 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) Config ¶
func (c *PegasusFilterImpl) Config() ([]byte, 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 Serializer ¶
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 ¶
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
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) Write ¶
func (s *WalSnapshot) Write(data []byte) error
TODO Filter 单独持久化 优化 下一版优化 Write safe