repo

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 27 Imported by: 1

Documentation

Overview

Package repo contains utility modules to open offset logs and create different kinds of indexes.

Index

Constants

View Source
const PrefixIndex = "indexes"
View Source
const PrefixMultiLog = "sublogs"

Variables

This section is empty.

Functions

func AllKeyPairs

func AllKeyPairs(r Interface) (map[string]ssb.KeyPair, error)

func DefaultKeyPair

func DefaultKeyPair(r Interface, algo refs.RefAlgo) (ssb.KeyPair, error)

func LoadKeyPair

func LoadKeyPair(r Interface, name string) (ssb.KeyPair, error)

func NewFilteredLog added in v0.2.1

func NewFilteredLog(b margaret.Log, fn FilterFunc) margaret.Log

NewFilteredLog wraps the passed log into a new one, using the FilterFunc to decide if a message is in the log.

func NewKeyPair

func NewKeyPair(r Interface, name string, algo refs.RefAlgo) (ssb.KeyPair, error)

func NewKeyPairFromSeed

func NewKeyPairFromSeed(r Interface, name string, algo refs.RefAlgo, seed io.Reader) (ssb.KeyPair, error)

func OpenBadgerDB added in v0.2.1

func OpenBadgerDB(path string) (*badger.DB, error)

func OpenBlobStore

func OpenBlobStore(r Interface) (ssb.BlobStore, error)

func OpenFileSystemMultiLog

func OpenFileSystemMultiLog(r Interface, name string, f multilog.Func) (*roaring.MultiLog, librarian.SinkIndex, error)

func OpenIndex

func OpenIndex(db *badger.DB, name string, f func(librarian.SeqSetterIndex) librarian.SinkIndex) (librarian.Index, librarian.SinkIndex, error)

func OpenLog

func OpenLog(r Interface, path ...string) (multimsg.AlterableLog, error)

func OpenStandaloneMultiLog added in v0.2.1

func OpenStandaloneMultiLog(r Interface, name string, f multilog.Func) (multilog.MultiLog, librarian.SinkIndex, error)

Types

type FilterFunc added in v0.2.1

type FilterFunc func(refs.Message) bool

FilterFunc works on messages of a FilteredLog. If the func returns true, the log is in the filtered log.

type FilteredLog added in v0.2.1

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

FilteredLog omits entries in the backing log as decided by the configured FilterFunc. It does so by claiming the entries are deleted (via returning margaret.ErrNulled instead)

func (FilteredLog) Append added in v0.2.1

func (fl FilteredLog) Append(val interface{}) (int64, error)

func (FilteredLog) Changes added in v0.2.1

func (fl FilteredLog) Changes() luigi.Observable

func (FilteredLog) Get added in v0.2.1

func (fl FilteredLog) Get(s int64) (interface{}, error)

Get retrieves the message object by traversing the authors sublog to the root log

func (FilteredLog) Query added in v0.2.1

func (fl FilteredLog) Query(qry ...margaret.QuerySpec) (luigi.Source, error)

func (FilteredLog) Seq added in v0.2.1

func (fl FilteredLog) Seq() int64

type Interface

type Interface interface {
	GetPath(...string) string
}

func New

func New(basePath string) Interface

New creates a new repository value, it opens the keypair and database from basePath if it is already existing

type LibrarianIndexCreater

type LibrarianIndexCreater func(*badger.DB) (librarian.SeqSetterIndex, librarian.SinkIndex)

type MakeMultiLog

type MakeMultiLog func(db *badger.DB) (multilog.MultiLog, librarian.SinkIndex, error)

type MakeSimpleIndex

type MakeSimpleIndex func(db *badger.DB) (librarian.Index, librarian.SinkIndex, error)

type MultiLogMaker

type MultiLogMaker interface {
	MakeMultiLog(db *badger.DB) (multilog.MultiLog, librarian.SinkIndex, error)
}

type ResolverFilter

type ResolverFilter func(int64) bool

ResolverFilter get's passed the value from the domain that is searched. Should return true if the value should be included and sorted

type SequenceResolver

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

SequenceResolver holds three gigantic arrays for each of the understood ResolveDomains.

It should be hooked into a receive log, and filled with Append.

TODO: a better approach might be to fetch these lazyly from disk if they become too large. At 1mio messages we roughly look at 8mb per domain.

func NewSequenceResolver

func NewSequenceResolver(r Interface) (*SequenceResolver, error)

NewSequenceResolver opens the stored resolver at r.GetPath("seqmaps") and Loads existing values.

func NewSequenceResolverFromLog

func NewSequenceResolverFromLog(l margaret.Log) (*SequenceResolver, error)

NewSequenceResolverFromLog creates a fresh resolver reading the full margaret log. Expects to read refs.Message from the log. Useful for testing.

func (*SequenceResolver) Append

func (sr *SequenceResolver) Append(seq int64, feed int64, claimed, received time.Time) error

Append adds all three domains to the resolver.

func (SequenceResolver) Close

func (sr SequenceResolver) Close() error

Close serialzes the resolver to disk.

func (*SequenceResolver) Load

func (sr *SequenceResolver) Load() (int64, error)

Load reads the files from repo and deserializes them.

func (SequenceResolver) Seq

func (sr SequenceResolver) Seq() int64

Seq returns the number of entries held by the resolver.

func (*SequenceResolver) Serialize

func (sr *SequenceResolver) Serialize() error

Serialize does the reverse from Load. It saves the three domains to disk.

func (SequenceResolver) SortAndFilter

func (sr SequenceResolver) SortAndFilter(seqs []int64, by SortDomain, ok ResolverFilter, desc bool) (SortedSeqSlice, error)

SortAndFilter goes through seqs in the passed domain using the filter function to include wanted elements. desc: true means descending, desc: false means ascending.

func (SequenceResolver) SortAndFilterAll

func (sr SequenceResolver) SortAndFilterAll(by SortDomain, ok ResolverFilter, desc bool) (SortedSeqSlice, error)

func (SequenceResolver) SortAndFilterBitmap

func (sr SequenceResolver) SortAndFilterBitmap(seqs *bmap.Bitmap, by SortDomain, ok ResolverFilter, desc bool) (SortedSeqSlice, error)

func (SequenceResolver) String

func (sr SequenceResolver) String() string

type SimpleIndexMaker

type SimpleIndexMaker interface {
	MakeSimpleIndex(db *badger.DB) (librarian.Index, librarian.SinkIndex, error)
}

type SortDomain

type SortDomain uint

SortDomain an enum for the understood domains

const (
	SortByClaimed SortDomain
	SortByReceived
	SortByFeedSeq
)

The known domains are: Claimed timestamp, Received Timestamp and Sequence number of the messageon the feed (this is important for partial replication, where feeds are not fetched in full and correct order)

type SortedAscending

type SortedAscending struct{ SortedSeqSlice }

SortedAscending wraps around SortedSeqSlice to give it a Less that sorts values from small to large.

func (SortedAscending) Less

func (ts SortedAscending) Less(i int, j int) bool

Less sorts values up

type SortedDescending

type SortedDescending struct{ SortedSeqSlice }

SortedDescending wraps around SortedSeqSlice to give it a Less that sorts values from large to small.

func (SortedDescending) Less

func (ts SortedDescending) Less(i int, j int) bool

Less sorts values down

type SortedSeqSlice

type SortedSeqSlice []SortedSequence

SortedSeqSlice a slice of SortedSequences that can be sorted

func (SortedSeqSlice) AsLuigiSource

func (ts SortedSeqSlice) AsLuigiSource() luigi.Source

AsLuigiSource returns a luigi.Source to iterate over the sorted array. Helpful for retrofitting into existing margaret code.

func (SortedSeqSlice) Len

func (ts SortedSeqSlice) Len() int

func (SortedSeqSlice) Swap

func (ts SortedSeqSlice) Swap(i int, j int)

Swap swaps the elements with indexes i and j.

type SortedSequence

type SortedSequence struct {
	By  int64 // fill with the value of the domain
	Seq int64 // the sequence of the entry we are looking for
}

SortedSequence holds the sequence value of the message and the domain value it should be sorted by.

Jump to

Keyboard shortcuts

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