Documentation
¶
Index ¶
- Constants
- func GenerateFilename(name, kind string, timestamp int64) string
- func Read(filename string, p Processor) (err error)
- type BatchFn
- type Block
- type File
- type Kiroku
- type Ledger
- type Meta
- type Mirror
- func (m *Mirror) Channel() <-chan struct{}
- func (m *Mirror) Close() (err error)
- func (m *Mirror) Filename() (filename string, err error)
- func (m *Mirror) Meta() (meta Meta, err error)
- func (m *Mirror) Snapshot(fn func(*Snapshot) error) (err error)
- func (m *Mirror) Transaction(fn func(*Transaction) error) (err error)
- type NOOP
- func (n *NOOP) Export(ctx context.Context, filename string, r io.Reader) error
- func (n *NOOP) Get(ctx context.Context, filename string, fn func(io.Reader) error) error
- func (n *NOOP) GetNext(ctx context.Context, prefix, lastFilename string) (filename string, err error)
- func (n *NOOP) Import(ctx context.Context, filename string, w io.Writer) error
- type Options
- type Processor
- type Producer
- type Reader
- type Snapshot
- type Source
- type Transaction
- type TransactionFn
- type Type
- type Writer
Examples ¶
Constants ¶
const ( // ErrMirrorNilSource is returned when a mirror is initialized with a nil source ErrMirrorNilSource = errors.Error("mirrors cannot have a nil source") // ErrMirrorTransaction is returned when a mirror attempts a transaction ErrMirrorTransaction = errors.Error("mirrors cannot perform transactions") // ErrMirrorSnapshot is returned when a mirror attempts to snapshot ErrMirrorSnapshot = errors.Error("mirrors cannot perform snapshots") )
const ( // ErrEmptyDirectory is returned when a directory is empty ErrEmptyDirectory = errors.Error("invalid directory, cannot be empty") // ErrEmptyName is returned when a name is empty ErrEmptyName = errors.Error("invalid name, cannot be empty") )
const ( // DefaultEndOfResultsDelay is the default value for EndOfResultsDelay DefaultEndOfResultsDelay = time.Second * 10 // DefaultErrorDelay is the default value for ErrorDelay DefaultErrorDelay = time.Second * 30 // DefaultBatchDuration is the default value for BatchDuration DefaultBatchDuration = time.Second * 10 )
Variables ¶
This section is empty.
Functions ¶
func GenerateFilename ¶ added in v0.9.9
func Read ¶
Read will read a filename and provide a temporary reader
Example ¶
var err error
if err = Read("filename.moj", func(r *Reader) (err error) {
m := testReader.Meta()
fmt.Println("Meta!", m)
if err = r.ForEach(0, func(b *Block) (err error) {
fmt.Println("Block value:", string(b.Value))
return
}); err != nil {
log.Fatalf("Error iterating through blocks: %v", err)
}
return
}); err != nil {
log.Fatal(err)
return
}
Types ¶
type BatchFn ¶ added in v0.10.5
type BatchFn func(*Transaction)
type Block ¶
type Block struct {
// Type of block
Type Type
// Key of block
Key []byte
// Value of block
Value []byte
}
Block represents a block of data stored within history
func (*Block) MarshalEnkodo ¶
MarshalEnkodo is a enkodo encoding helper func
type Kiroku ¶
type Kiroku struct {
// contains filtered or unexported fields
}
Kiroku represents historical DB entries
func New ¶
New will initialize a new Kiroku instance Note: Processor and Options are optional
Example ¶
var err error
opts := MakeOptions("./test_data", "tester")
if testKiroku, err = New(opts, nil); err != nil {
log.Fatal(err)
return
}
Example (With_custom_Exporter) ¶
var (
src Source
err error
)
// Utilize any Source, see https://github.com/mojura/sync-s3 for an example
opts := MakeOptions("./test_data", "tester")
if testKiroku, err = New(opts, src); err != nil {
log.Fatal(err)
return
}
func NewWithContext ¶
NewWithContext will initialize a new Kiroku instance with a provided context.Context Note: Processor and Options are optional
func (*Kiroku) Meta ¶
Meta will return a copy of the current Meta
Example ¶
var (
m Meta
err error
)
if m, err = testKiroku.Meta(); err != nil {
log.Fatal(err)
}
fmt.Println("Meta", m)
func (*Kiroku) Snapshot ¶
Snapshot will engage a new history snapshot
Example ¶
var err error
if err = testKiroku.Snapshot(func(s *Snapshot) (err error) {
return s.Write([]byte("testKey"), []byte("hello world!"))
}); err != nil {
log.Fatal(err)
return
}
func (*Kiroku) Transaction ¶
func (k *Kiroku) Transaction(fn func(*Transaction) error) (err error)
Transaction will engage a new history transaction
Example ¶
var err error
if err = testKiroku.Transaction(func(t *Transaction) (err error) {
return t.AddBlock(TypeWriteAction, []byte("testKey"), []byte("hello world!"))
}); err != nil {
log.Fatal(err)
return
}
type Meta ¶
type Meta struct {
// BlockCount is the number of blocks contained within the Chunk
BlockCount int64 `json:"blockCount"`
// TotalBlockSize is the total block size (in bytes)
TotalBlockSize int64 `json:"totalBlockSize"`
// LastSnapshotAt is the timestamp of the last snapshot as Unix Nano
LastSnapshotAt int64 `json:"lastSnapshotAt"`
// CreatedAt is a UnixNano timestamp of when the last chunk was created
CreatedAt int64 `json:"createdAt"`
}
Meta represents the historical meta data
type Mirror ¶ added in v0.2.0
type Mirror struct {
// contains filtered or unexported fields
}
Mirror represents a read-only instance of historical DB entries Note: The mirror is updated through it's Importer
func NewMirror ¶ added in v0.2.0
NewMirror will initialize a new Mirror instance
Example ¶
var err error
opts := MakeOptions("./test_data", "tester")
if testMirror, err = NewMirror(opts, newErrorSource(io.EOF)); err != nil {
log.Fatal(err)
return
}
func NewMirrorWithContext ¶ added in v0.2.0
NewMirrorWithContext will initialize a new Mirror instance with a provided context.Context
func (*Mirror) Transaction ¶ added in v0.4.0
func (m *Mirror) Transaction(fn func(*Transaction) error) (err error)
type NOOP ¶ added in v0.9.6
type NOOP struct {
}
type Options ¶
type Options struct {
Dir string `toml:"dir" json:"dir"`
Name string `toml:"name" json:"name"`
Namespace string `toml:"namespace" json:"namespace"`
AvoidImportOnInit bool `toml:"avoid_import_on_init" json:"avoidImportOnInit"`
AvoidMergeOnInit bool `toml:"avoid_merge_on_init" json:"avoidMergeOnInit"`
AvoidMergeOnClose bool `toml:"avoid_merge_on_close" json:"avoidMergeOnClose"`
AvoidExportOnClose bool `toml:"avoid_export_on_close" json:"avoidExportOnClose"`
IsMirror bool `toml:"is_mirror" json:"isMirror"`
// Event handlers
OnUpdate func(*Reader)
// EndOfResultsDelay represents the amount of time to wait before pulling "Next" after
// receiving empty results (Default is 10 seconds).
EndOfResultsDelay time.Duration `toml:"end_of_results_delay" json:"endOfResultsDelay"`
// ErrorDelay represents the amount of time to wait before pulling "Next" after
// receiving an error
ErrorDelay time.Duration `toml:"error_delay" json:"errorDelay"`
// BatchDuration represents the amount of time to keep a transaction open for a
// Batch operation
BatchDuration time.Duration `toml:"batch_duration" json:"batchDuration"`
// RangeStart will determine the moment in time from which syncs will begin
RangeStart time.Time `toml:"range_start" json:"rangeStart"`
// RangeEnd will determine the moment in time from which syncs will end
// Note: This feature is slated to be implemented within the following
// release. As of now, this will act as a field placeholder
RangeEnd time.Time `toml:"range_end" json:"rangeEnd"`
}
Options represent Kiroku options
func MakeOptions ¶ added in v0.2.0
MakeOptions will create new Options
type Producer ¶ added in v0.10.5
type Producer struct {
// contains filtered or unexported fields
}
Producer represents historical DB entries
func NewProducer ¶ added in v0.10.5
New will initialize a new Producer instance Note: Processor and Options are optional
func NewProducerWithContext ¶ added in v0.10.5
NewWithContext will initialize a new Producer instance with a provided context.Context Note: Processor and Options are optional
func (*Producer) BatchBlock ¶ added in v0.10.5
Batch will engage a new history batch transaction
func (*Producer) Transaction ¶ added in v0.10.5
func (p *Producer) Transaction(fn TransactionFn) (err error)
Transaction will engage a new history transaction
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader will parse and read a history chunk
func NewReader ¶
NewReader will initialize a new chunk reader
Example ¶
var (
f *os.File
err error
)
if f, err = os.Open("filename.moj"); err != nil {
log.Fatalf("error opening: %v", err)
return
}
if testReader, err = NewReader(f); err != nil {
log.Fatalf("error initializing reader: %v", err)
return
}
func (*Reader) Copy ¶
Copy will copy the entire chunk (meta + blocks)
Example ¶
var (
f *os.File
err error
)
if f, err = os.Create("chunk.copy.moj"); err != nil {
log.Fatal(err)
return
}
defer f.Close()
if _, err = testReader.Copy(f); err != nil {
log.Fatalf("Error copying chunk: %v", err)
}
func (*Reader) CopyBlocks ¶
CopyBlocks will copy the blocks only (no meta)
Example ¶
var (
f *os.File
err error
)
if f, err = os.Create("chunk.blocksOnly.copy.moj"); err != nil {
log.Fatal(err)
return
}
defer f.Close()
if _, err = testReader.CopyBlocks(f); err != nil {
log.Fatalf("Error copying chunk: %v", err)
}
func (*Reader) ForEach ¶
ForEach will iterate through all the blocks within the reader
Example ¶
var err error
if err = testReader.ForEach(0, func(b *Block) (err error) {
fmt.Println("Block value:", string(b.Value))
return
}); err != nil {
log.Fatalf("Error iterating through blocks: %v", err)
}
func (*Reader) Meta ¶
Meta will return the meta information for the chunk
Example ¶
m := testReader.Meta()
fmt.Println("Meta!", m)
func (*Reader) ReadSeeker ¶ added in v0.1.2
func (r *Reader) ReadSeeker() io.ReadSeeker
ReadSeeker will return the Reader's underlying ReadSeeker
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot manages a Kiroku transaction
type Source ¶ added in v0.6.0
type Source interface {
Export(ctx context.Context, filename string, r io.Reader) error
Import(ctx context.Context, filename string, w io.Writer) error
Get(ctx context.Context, filename string, fn func(io.Reader) error) error
GetNext(ctx context.Context, prefix, lastFilename string) (filename string, err error)
}
Source is used for importing
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction manages a Kiroku transaction
func (*Transaction) AddBlock ¶
func (t *Transaction) AddBlock(typ Type, key, value []byte) (err error)
AddBlock will add a row
func (*Transaction) Meta ¶ added in v0.9.1
func (t *Transaction) Meta() (m Meta)
AddBlock will add a row
type TransactionFn ¶ added in v0.10.5
type TransactionFn func(*Transaction) error
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer will write a history chunk
func NewWriter ¶
NewWriter will initialize a new Writer instance
Example ¶
var err error
if testWriter, err = NewWriter("./test_data", "testie"); err != nil {
log.Fatal(err)
return
}
func NewWriterWithFile ¶
NewWriterWithFile will initialize a new Writer instance
func (*Writer) AddBlock ¶
AddBlock will add a row
Example ¶
var err error
if err = testWriter.AddBlock(TypeWriteAction, []byte("greeting"), []byte("Hello world!")); err != nil {
log.Fatalf("error adding row: %v", err)
return
}
func (*Writer) Filename ¶ added in v0.1.3
Filename will return the underlying filename of the Writer