Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
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 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
if testKiroku, err = New("./test_data", "tester", nil, nil); err != nil {
log.Fatal(err)
return
}
Example (With_custom_Processor) ¶
var err error
pfn := func(r *Reader) (err error) {
fmt.Println("Hello chunk!", r.Meta())
return
}
if testKiroku, err = New("./test_data", "tester", pfn, nil); err != nil {
log.Fatal(err)
return
}
func NewWithContext ¶
func NewWithContext(ctx context.Context, dir, name string, p Processor, o *Options) (kp *Kiroku, err error)
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
// BlockCount is the number of blocks contained within the Chunk
BlockCount int64
// TotalBlockSize is the total block size (in bytes)
TotalBlockSize int64
// LastSnapshotAt is the timestamp of the last snapshot as Unix Nano
LastSnapshotAt int64
// CreatedAt is a UnixNano timestamp of when the last chunk was created
CreatedAt int64
}
Meta represents the historical meta data
type Options ¶
type Options struct {
AvoidMergeOnInit bool
AvoidProcessOnInit bool
AvoidMergeOnClose bool
AvoidProcessOnClose bool
}
Options represent Kiroku 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)
}
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) 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)