birdsnest

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: Apache-2.0 Imports: 19 Imported by: 5

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

View Source
const (
	DefaultLoadFactor = 0.98
)
View Source
const (
	Filepath = "birdsnest"
)
View Source
const TestDir = "./data/timestamp_birds_nest"

Variables

View Source
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")
)
View Source
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")
)
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 GenTimestampKey

func GenTimestampKey() string

func GenTimestampKeyByNano

func GenTimestampKeyByNano(nano int64) string

func GenTxId

func GenTxId() string

func LruStrategy

func LruStrategy(bn *BirdsNestImpl) 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 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) Add

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

Add a Key

func (*BirdsNestImpl) Adds

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

Adds Add multiple Key

func (*BirdsNestImpl) AddsAndSetHeight

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

AddsAndSetHeight Add multiple Key and set height

func (*BirdsNestImpl) Contains

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

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

func (*BirdsNestImpl) ValidateRule

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

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:

  1. TableTypeSingle normal single table
  2. 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 Key interface {
	// Parse the key
	Parse() ([][]byte, error)
	// Key bytes
	Key() []byte
	// Len The length of the key
	Len() int
	String() string
	GetNano() int64
}

func GetTimestampKey

func GetTimestampKey() Key

func GetTimestampKeyByNano

func GetTimestampKeyByNano(i int64) Key

func GetTimestampKeys

func GetTimestampKeys(n int) []Key

type Logger

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

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 *BirdsNestImpl) 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/birdsnestN

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