Documentation
¶
Overview ¶
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Copyright (C) BABEC. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- Variables
- func CurrentTimestampNano() int64
- func Factory() *factory
- func GenTimestampKey() string
- func GenTimestampKeyByNano(nano int64) string
- func GenTxId() string
- func LruStrategy(bn *BirdsNestImpl) error
- func ToStrings(keys []Key) []string
- func ToTimestampKeysAndNormalKeys(key []string) (timestampKeys []Key, normalKeys []Key)
- type AbsoluteExpireTimeRule
- type BirdsNest
- type BirdsNestImpl
- func (b *BirdsNestImpl) Add(key Key) error
- func (b *BirdsNestImpl) Adds(keys []Key) error
- func (b *BirdsNestImpl) AddsAndSetHeight(keys []Key, height uint64) (result error)
- func (b *BirdsNestImpl) Contains(key Key, rules ...common.RuleType) (bool, error)
- func (b *BirdsNestImpl) Deserialize() error
- func (b *BirdsNestImpl) GetHeight() uint64
- func (b *BirdsNestImpl) Info() []uint64
- func (b *BirdsNestImpl) Serialize() error
- func (b *BirdsNestImpl) SetHeight(height uint64)
- func (b *BirdsNestImpl) Start()
- func (b *BirdsNestImpl) ValidateRule(key Key, rules ...common.RuleType) error
- type CuckooFilter
- type CuckooFilterImpl
- func (c *CuckooFilterImpl) Add(key Key) (bool, error)
- func (c *CuckooFilterImpl) Config() ([]byte, error)
- func (c *CuckooFilterImpl) Contains(key Key) (bool, error)
- func (c *CuckooFilterImpl) Encode() (FilterEncoder, error)
- func (c *CuckooFilterImpl) Extension() FilterExtension
- func (c *CuckooFilterImpl) Info() []uint64
- func (c *CuckooFilterImpl) IsFull() bool
- type DefaultFilterExtension
- type FilterEncoder
- type FilterExtension
- type Key
- type Logger
- type Rule
- type Serializer
- type SprintfError
- type Strategy
- type TestLogger
- type TimestampFilterExtension
- type TimestampKey
- type WalSnapshot
Constants ¶
const (
DefaultLoadFactor = 0.98
)
const (
Filepath = "birdsnest"
)
const TestDir = "./data/timestamp_birds_nest"
Variables ¶
var ( ErrKeyCannotBeEmpty = errors.New("key cannot be empty") ErrCannotModifyTheNestConfiguration = errors.New("when historical data exists, you cannot modify the nest " + "configuration") ErrBirdsNestSizeCannotBeZero = errors.New("the size cannot be 0") )
var ( SeparatorString = "-" // Separator chainmaker 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 (
ErrFilterExtensionNotSupport = NewError("filter extension not support type: %v")
)
var (
ErrKeyItsSoLongAgoError = NewError("key %v is out of the range %v-%v")
)
Functions ¶
func LruStrategy ¶
func LruStrategy(bn *BirdsNestImpl) error
LruStrategy Nest filter cycle elimination strategy
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 BirdsNest ¶
type BirdsNest 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 cuckoos nest information and status Info() []uint64 Start() }
BirdsNest Bird's Nest
type BirdsNestImpl ¶
type BirdsNestImpl struct {
// contains filtered or unexported fields
}
BirdsNestImpl impl
func NewBirdsNest ¶
func NewBirdsNest(config *common.BirdsNestConfig, exitC chan struct{}, strategy Strategy, logger Logger) ( *BirdsNestImpl, error)
NewBirdsNest Create a BirdsNest
func NewBirdsNestByNumber ¶
func NewBirdsNestByNumber(config *common.BirdsNestConfig, exitC chan struct{}, strategy Strategy, logger Logger, number int) (*BirdsNestImpl, error)
NewBirdsNestByNumber Create a numbered BirdsNest
func (*BirdsNestImpl) AddsAndSetHeight ¶
func (b *BirdsNestImpl) AddsAndSetHeight(keys []Key, height uint64) (result error)
AddsAndSetHeight Add multiple Key and set height
func (*BirdsNestImpl) Contains ¶
Contains sync
func (*BirdsNestImpl) Deserialize ¶
func (b *BirdsNestImpl) Deserialize() error
func (*BirdsNestImpl) GetHeight ¶
func (b *BirdsNestImpl) GetHeight() uint64
GetHeight get current height
func (*BirdsNestImpl) Info ¶
func (b *BirdsNestImpl) Info() []uint64
Info index 0 height index 1 cuckoo size index 2 current index index 3 total cuckoo size index 4 total space occupied by cuckoo
func (*BirdsNestImpl) Serialize ¶
func (b *BirdsNestImpl) Serialize() error
Serialize all cuckoos in the current BirdsNest
func (*BirdsNestImpl) SetHeight ¶
func (b *BirdsNestImpl) SetHeight(height uint64)
SetHeight set height
func (*BirdsNestImpl) Start ¶
func (b *BirdsNestImpl) Start()
Start TODO Goroutinue should be turned off using context.Context here
type CuckooFilter ¶
type CuckooFilter interface { IsFull() bool Add(key Key) (bool, error) Contains(key Key) (bool, error) Encode() (FilterEncoder, error) Extension() FilterExtension Info() []uint64 }
func NewCuckooFilter ¶
func NewCuckooFilter(config *common.CuckooConfig) CuckooFilter
NewCuckooFilter Params: common.CuckooConfig.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.CuckooConfig.TagsPerBucket: num of tags for each bucket, which is b in paper. tag is fingerprint, which is f
in paper.
common.CuckooConfig.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.CuckooConfig.BitsPerItem : num of bits for each item, which is length of tag(fingerprint) common.CuckooConfig.TableType : common.CuckooConfig.KeyType : 0 TableTypeSingle normal single table
1 TableTypePacked packed table, use semi-sort to save 1 bit per item 1 is recommended
Result: CuckooFilter
type CuckooFilterImpl ¶
type CuckooFilterImpl struct {
// contains filtered or unexported fields
}
CuckooFilterImpl Cuckoo Filter
func NewCuckooFilterByDecode ¶
func NewCuckooFilterByDecode(filter *common.CuckooFilter) (*CuckooFilterImpl, error)
func (*CuckooFilterImpl) Add ¶
func (c *CuckooFilterImpl) Add(key Key) (bool, error)
func (*CuckooFilterImpl) Config ¶
func (c *CuckooFilterImpl) Config() ([]byte, error)
func (*CuckooFilterImpl) Contains ¶
func (c *CuckooFilterImpl) Contains(key Key) (bool, error)
func (*CuckooFilterImpl) Encode ¶
func (c *CuckooFilterImpl) Encode() (FilterEncoder, error)
func (*CuckooFilterImpl) Extension ¶
func (c *CuckooFilterImpl) Extension() FilterExtension
func (*CuckooFilterImpl) Info ¶
func (c *CuckooFilterImpl) Info() []uint64
Info index 0 cuckoo size index 1 Space occupied by cuckoo
func (*CuckooFilterImpl) IsFull ¶
func (c *CuckooFilterImpl) IsFull() bool
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 Logger ¶
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 *BirdsNestImpl) 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
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/birdsnestN
func (*WalSnapshot) Write ¶
func (s *WalSnapshot) Write(data []byte) error
TODO Filter 单独持久化 优化 下一版优化 Write safe