Documentation
¶
Index ¶
- Constants
- func Read(filename string, p Processor) (err error)
- type Block
- type Exporter
- type Importer
- type Kiroku
- type Meta
- type Mirror
- type MirrorOptions
- type Options
- type Processor
- type Reader
- func (r *Reader) Copy(destination io.Writer) (n int64, err error)
- func (r *Reader) CopyBlocks(destination io.Writer) (n int64, err error)
- func (r *Reader) ForEach(seek int64, fn func(*Block) error) (lastPosition int64, err error)
- func (r *Reader) Meta() Meta
- func (r *Reader) ReadSeeker() io.ReadSeeker
- type Snapshot
- type Transaction
- type Type
- type Writer
- func (w *Writer) AddBlock(t Type, key, value []byte) (err error)
- func (w *Writer) Close() (err error)
- func (w *Writer) Filename() string
- func (w *Writer) GetIndex() (index uint64, err error)
- func (w *Writer) Merge(r *Reader) (err error)
- func (w *Writer) Meta() Meta
- func (w *Writer) NextIndex() (index uint64, err error)
- func (w *Writer) SetIndex(index uint64) (err error)
Examples ¶
Constants ¶
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 )
Variables ¶
This section is empty.
Functions ¶
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 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 Importer ¶ added in v0.2.0
type Importer interface {
GetNext(ctx context.Context, prefix, lastFilename string) (filename string, err error)
Import(ctx context.Context, filename string, w io.Writer) (err error)
}
Importer is used for importing
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 (
e Exporter
err error
)
// Utilize any Exporter, see https://github.com/mojura/sync-s3 for an example
opts := MakeOptions("./test_data", "tester")
if testKiroku, err = New(opts, e); 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) {
if err = t.SetIndex(1337); err != nil {
return
}
return t.AddBlock(TypeWriteAction, []byte("testKey"), []byte("hello world!"))
}); err != nil {
log.Fatal(err)
return
}
type Meta ¶
type Meta struct {
// CurrentIndex would be the current index count
CurrentIndex uint64 `json:"currentIndex"`
// 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
func NewMirror(opts MirrorOptions, i Importer) (mp *Mirror, err error)
NewMirror will initialize a new Mirror instance
Example ¶
var err error
opts := MakeMirrorOptions("./test_data", "tester", nil)
if testMirror, err = NewMirror(opts, newErrorImporter(io.EOF)); err != nil {
log.Fatal(err)
return
}
func NewMirrorWithContext ¶ added in v0.2.0
func NewMirrorWithContext(ctx context.Context, opts MirrorOptions, i Importer) (mp *Mirror, err error)
NewMirrorWithContext will initialize a new Mirror instance with a provided context.Context
type MirrorOptions ¶ added in v0.2.0
type MirrorOptions struct {
Options
// EndOfResultsDelay represents the amount of time to wait before pulling "Next" after receiving empty results
// Note: Default is 10 seconds
EndOfResultsDelay time.Duration
}
MirrorOptions represent Mirror options
func MakeMirrorOptions ¶ added in v0.2.0
func MakeMirrorOptions(dir, name string, onImport Processor) (o MirrorOptions)
MakeMirrorOptions will create new Mirror Options
func (*MirrorOptions) Validate ¶ added in v0.2.0
func (m *MirrorOptions) Validate() (err error)
Validate ensures that the MirrorOptions have all the required fields set
type Options ¶
type Options struct {
Dir string
Name string
AvoidMergeOnInit bool
AvoidMergeOnClose bool
AvoidExportOnClose bool
}
Options represent Kiroku options
func MakeOptions ¶ added in v0.2.0
MakeOptions will create new Options
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader will parse and read a history chunk
func NewReader ¶
func NewReader(rs io.ReadSeeker) (rp *Reader, err error)
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 (
lastPosition int64
err error
)
if lastPosition, 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)
}
fmt.Println("Last read block at", lastPosition)
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 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) GetIndex ¶
func (t *Transaction) GetIndex() (index uint64, err error)
GetIndex will get the current index value
func (*Transaction) NextIndex ¶
func (t *Transaction) NextIndex() (index uint64, err error)
NextIndex will get the current index value then increment the internal value
func (*Transaction) SetIndex ¶
func (t *Transaction) SetIndex(index uint64) (err error)
SetIndex will set the index value Note: This can be used to manually set an index to a desired value
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
func (*Writer) GetIndex ¶
GetIndex will get the current index value
Example ¶
var (
index uint64
err error
)
if index, err = testWriter.GetIndex(); err != nil {
log.Fatal(err)
return
}
fmt.Println("Current index:", index)