sqlite

package
v0.0.0-...-4b51c2d Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XorFindFarthestQuery = `SELECT
		xor(key, (?1)) as distance
		FROM kvstore
		ORDER BY distance DESC`
)

Variables

This section is empty.

Functions

func NewDB

func NewDB(dataDir string, network string) (*sql.DB, error)

func NewStorage

func NewStorage(config storage.PortalStorageConfig, db *sql.DB) (storage.ContentStorage, error)

Types

type ContentStorage

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

func (*ContentStorage) Close

func (p *ContentStorage) Close() error

func (*ContentStorage) ContentCount

func (p *ContentStorage) ContentCount() (uint64, error)

ContentCount return the total content count

func (*ContentStorage) ContentSize

func (p *ContentStorage) ContentSize() (uint64, error)

func (*ContentStorage) EstimateNewRadius

func (p *ContentStorage) EstimateNewRadius(currentRadius *uint256.Int) (*uint256.Int, error)

EstimateNewRadius calculates an estimated new radius based on the current radius, used size, and storage capacity. The method takes the currentRadius as input and returns the estimated new radius and an error (if any). It calculates the size ratio of usedSize to storageCapacityInBytes and adjusts the currentRadius accordingly. If the size ratio is greater than 0, it performs the adjustment; otherwise, it returns the currentRadius unchanged. The method returns an error if there is any issue in determining the used size.

func (*ContentStorage) ForcePrune

func (p *ContentStorage) ForcePrune(radius *uint256.Int) error

ForcePrune delete the content which distance is further than the given radius

func (*ContentStorage) Get

func (p *ContentStorage) Get(contentKey []byte, contentId []byte) ([]byte, error)

Get the content according to the contentId

func (*ContentStorage) GetLargestDistance

func (p *ContentStorage) GetLargestDistance() (*uint256.Int, error)

GetLargestDistance find the largest distance

func (*ContentStorage) Put

func (p *ContentStorage) Put(contentKey []byte, contentId []byte, content []byte) error

func (*ContentStorage) Radius

func (p *ContentStorage) Radius() *uint256.Int

func (*ContentStorage) ReclaimSpace

func (p *ContentStorage) ReclaimSpace() error

ReclaimSpace reclaims space in the ContentStorage's SQLite database by performing a VACUUM operation. It returns an error if the VACUUM operation encounters any issues.

func (*ContentStorage) Size

func (p *ContentStorage) Size() (uint64, error)

Size get database size, content size and similar

func (*ContentStorage) SizeByKey

func (p *ContentStorage) SizeByKey(contentId []byte) (uint64, error)

func (*ContentStorage) SizeByKeys

func (p *ContentStorage) SizeByKeys(ids [][]byte) (uint64, error)

func (*ContentStorage) SizeOutRadius

func (p *ContentStorage) SizeOutRadius(radius *uint256.Int) (uint64, error)

func (*ContentStorage) UnusedSize

func (p *ContentStorage) UnusedSize() (uint64, error)

func (*ContentStorage) UsedSize

func (p *ContentStorage) UsedSize() (uint64, error)

UsedSize = Size - UnusedSize

type PutResult

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

func (*PutResult) Err

func (p *PutResult) Err() error

func (*PutResult) Pruned

func (p *PutResult) Pruned() bool

func (*PutResult) PrunedCount

func (p *PutResult) PrunedCount() int

Jump to

Keyboard shortcuts

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