index

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeRoot = "idx:root"
)

Variables

View Source
var (
	ErrIndexNotFound       = errors.New("index not found")
	ErrIndexExists         = errors.New("index already exists")
	ErrIndexStoreNotFound  = errors.New("index store not found")
	ErrLockerStateNotFound = errors.New("locker state not found")
	ErrLockerStateExists   = errors.New("locker state already exists")
)

Functions

func RegisterStoreType

func RegisterStoreType(storeType string, ctor StoreConstructor)

func RootIndexID

func RootIndexID(userID string, accessLevel model.AccessLevel) string

Types

type AssetRecordVisitor

type AssetRecordVisitor func(recordID string, r *AssetState) error

type AssetState

type AssetState struct {
	ImpressionID     string `json:"impression"`
	AssetID          string `json:"asset"`
	ContentType      string `json:"contentType"`
	RevisionNumber   int64  `json:"revisionNumber,omitempty"`
	WasRevisionOf    string `json:"wasRevisionOf,omitempty"`
	SpecializationOf string `json:"specializationOf,omitempty"`
}

func (*AssetState) Bytes

func (as *AssetState) Bytes() []byte

type Client

type Client interface {
	io.Closer

	// Bind links all underlying index states to a specific genesis block hash. If any of the stores
	// were already linked to a different hash, the call would fail.
	Bind(gbHash string) error

	// RootIndex returns a root index for the given account and requested access level.
	// If the index is not found, it will return ErrIndexNotFound.
	RootIndex(userID string, lvl model.AccessLevel) (RootIndex, error)

	// Index returns an index with the given id for the given account.
	// If the index is not found, it will return ErrIndexNotFound.
	Index(userID string, id string) (Index, error)
	// ListIndexes return a list of index definitions for all the indexes that are available
	// through this index client. We return a list of Properties to avoid construction of
	// all index instances that may be an expensive operation.
	ListIndexes(userID string) ([]*Properties, error)
	// DeleteIndex deletes the index from all the underlying index stores.
	DeleteIndex(userID, id string) error

	// IndexStore returns the index store with the given name.
	// If the store is not found, it will return ErrIndexStoreNotFound
	IndexStore(storeName string) (Store, error)
	// IndexStores return a list of index store definitions for all the stores that are available
	// through this index client. We return a list of StoreProperties to avoid construction of
	// all store instances that may be an expensive operation.
	IndexStores() []*StoreProperties
	// AddIndexStore instantiates and adds a new index store based on the provided configuration.
	AddIndexStore(cfg *StoreConfig, resolver cmdbase.ParameterResolver) error
}

Client provides an interface to a group of index stores, accessed using a priority list. It hides the implementation details of the store types available, and actual location of the index stores.

func NewLocalIndexClient

func NewLocalIndexClient(storeConfigs []*StoreConfig, resolver cmdbase.ParameterResolver, genesisBlockHash string) (Client, error)

type EncryptionMode

type EncryptionMode string
const (
	ModeNoEncryption      EncryptionMode = "none"
	ModeManagedEncryption EncryptionMode = "managed"
	ModeClientEncryption  EncryptionMode = "client"
)

type Index

type Index interface {
	io.Closer

	ID() string
	Properties() *Properties

	IsLocked() bool
	Unlock(key []byte) error
	Lock()

	IsWritable() bool
	Writer() (Writer, error)
}

Index is a database or any other storage system that provided an index of all or selected ledger records for easy and efficient access. Indexes can be generic or purpose-built.

type LockerState

type LockerState struct {
	ID         string `json:"id"`
	IndexID    string `json:"indexID"`
	AccountID  string `json:"accountID"`
	FirstBlock int64  `json:"firstBlock,omitempty"`
	TopBlock   int64  `json:"topBlock,omitempty"`
}

func (*LockerState) Bytes

func (ls *LockerState) Bytes() []byte

type Option

type Option func(opts *Options) error

func WithEncryption

func WithEncryption(key []byte) Option

func WithOptions

func WithOptions(opts Options) Option

type Options

type Options struct {
	ClientKey  []byte `json:"key,omitempty"`
	Parameters any    `json:"parameters,omitempty"`
}

func NewOptions

func NewOptions(opts ...Option) (Options, error)

NewOptions reads Options from Option array

type Properties

type Properties struct {
	IndexType   string            `json:"type"`
	Asset       string            `json:"asset,omitempty"`
	AccessLevel model.AccessLevel `json:"accessLevel"`
	Algorithm   string            `json:"algo"`
	Params      any               `json:"params"`
}

type RecordState

type RecordState struct {
	ID            string             `json:"id"`
	Operation     model.OpType       `json:"op"`
	Status        model.RecordStatus `json:"status"`
	LockerID      string             `json:"locker"`
	ParticipantID string             `json:"participant"`
	BlockNumber   int64              `json:"blockNumber"`
	Index         uint32             `json:"index"`
	ImpressionID  string             `json:"impression,omitempty"`
	ContentType   string             `json:"contentType,omitempty"`
}

func (*RecordState) Bytes

func (rs *RecordState) Bytes() []byte

type RecordVisitor

type RecordVisitor func(r *RecordState) error

type RootIndex

type RootIndex interface {
	Index

	GetRecord(recordID string) (*RecordState, error)
	TraverseRecords(lockerFilter, participantFilter string, vFunc RecordVisitor, maxRecords uint64) error
	TraverseVariants(lockerFilter, participantFilter string, vFunc VariantVisitor, includeHistory bool, maxVariants uint64) error
	TraverseAssetRecords(assetID string, vFunc AssetRecordVisitor, maxRecords uint64) error
	GetRecordsByImpressionID(impID string, lockerFilter map[string]bool) ([]string, error)
	GetVariant(variantID string, includeHistory bool) (*VariantRecordState, []*VariantRecordState, error)
}

RootIndex is a special type of index used by data wallets to provide fast access to ledger records and facilitate generic operations over available lockers and records.

type RootIndexParameters

type RootIndexParameters struct {
	ClientKey []byte `json:"key,omitempty"`
}

type Store

type Store interface {
	io.Closer

	ID() string
	Name() string
	Properties() *StoreProperties

	CreateIndex(userID string, indexType string, accessLevel model.AccessLevel, opts ...Option) (Index, error)
	RootIndex(userID string, lvl model.AccessLevel) (RootIndex, error)
	Index(userID string, id string) (Index, error)
	ListIndexes(userID string) ([]*Properties, error)
	DeleteIndex(userID, id string) error

	// Bind links the index store to a particular ledger instance by storing genesis block ID in the store.
	// If the store is already bound to a ledger, if will check the provided hash and return an error
	// if there is a mismatch. This is useful to catch conditions when the index store was used
	// in the context of a different ledger (i.e. in the development environment.
	Bind(gbHash string) error

	GenesisBlockHash() string
}

Store is a facility that can store indexes. Typically, a store is based on a specific database or storage technology that provides the desired runtime properties.

func CreateStore

func CreateStore(cfg *StoreConfig, resolver cmdbase.ParameterResolver) (Store, error)

type StoreConfig

type StoreConfig struct {
	ID             string         `koanf:"id" json:"id"`
	Name           string         `koanf:"name" json:"name"`
	Type           string         `koanf:"type" json:"type"`
	EncryptionMode EncryptionMode `koanf:"encryptionMode" json:"encryptionMode"`
	Params         map[string]any `koanf:"params" json:"params,omitempty"`
}

type StoreConstructor

type StoreConstructor func(cfg *StoreConfig, resolver cmdbase.ParameterResolver) (Store, error)

type StoreProperties

type StoreProperties struct {
	ID             string         `json:"id"`
	Name           string         `json:"name"`
	Type           string         `json:"type"`
	EncryptionMode EncryptionMode `json:"encryptionMode"`
}

func NewStorePropertiesFromConfig

func NewStorePropertiesFromConfig(cfg *StoreConfig) *StoreProperties

type VariantRecordState

type VariantRecordState struct {
	ID             string             `json:"id"`
	Operation      model.OpType       `json:"op"`
	Status         model.RecordStatus `json:"status"`
	LockerID       string             `json:"locker"`
	ParticipantID  string             `json:"participant"`
	BlockNumber    int64              `json:"block"`
	Index          uint32             `json:"index"`
	AssetID        string             `json:"asset"`
	ImpressionID   string             `json:"imp"`
	RevisionNumber int64              `json:"rev"`
	CreatedAt      *time.Time         `json:"at"`
	ContentType    string             `json:"ctype"`
}

func (*VariantRecordState) Bytes

func (rs *VariantRecordState) Bytes() []byte

type VariantVisitor

type VariantVisitor func(variantID string, master *VariantRecordState, history []*VariantRecordState) error

type Writer

type Writer interface {
	io.Closer

	ID() string

	LockerStates() ([]LockerState, error)
	AddLockerState(accountID, lockerID string, firstBlock int64) error
	AddLease(ds model.DataSet, effectiveBlockNumber int64) error
	AddLeaseRevocation(ds model.DataSet) error
	UpdateTopBlock(blockNumber int64) error
}

Writer is an interface for adding new records into an index.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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