istorage

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: MIT Imports: 7 Imported by: 2

README

istorage

  • Simple key-value persistency interface
  • Idea borrowed from Project Kaiser storage

Channel: pointer or value

Seems chan RecordParts is more effective than chan *RecordParts

https://groups.google.com/forum/#!topic/golang-nuts/eM_a09l8yU0 You may be surprised how large a struct can get before passing it has a noticeable performance impact compared to passing a pointer to that struct (not to mention accessing data behind a pointer involves an indirection, and especially when the data is shared across processors, there can be additional cost.

BenchmarkChanInterface-4          	 3000000	       428 ns/op	      64 B/op	       1 allocs/op
BenchmarkChanValue-4              	 5000000	       297 ns/op	       0 B/op	       0 allocs/op
BenchmarkChanValueFromPointer-4   	 5000000	       301 ns/op	       0 B/op	       0 allocs/op
BenchmarkChanPointer-4            	 5000000	       395 ns/op	      64 B/op	       1 allocs/op

Slice or Map

Slice is faster for small sizes https://www.darkcoding.net/software/go-slice-search-vs-map-lookup/

Documentation

Index

Constants

View Source
const (
	// Aka BO
	DomainConf = iota
	// Aka POS
	DomainOps
)

Domain values

View Source
const DefaultPart = 0

DefaultPart denotes default part of the record

Variables

View Source
var ErrFilteringByOnlyPartsIsProhibited = errors.New("Filtering by only parts is prohibited")

ErrFilteringByOnlyPartsIsProhibited s.e.

View Source
var Get func(ctx context.Context, workspaceID int64, recordType int32, IDs []int64, partTypes []int32) (res <-chan Record, perr *error)

Get returns channel for records with given workspaceID and recordType - res buffer length must be zero - res must be sorted by ID, PartType - If IDs is not empty result is filtered by IDs - If IDs is not empty and partTypes is not empty result is filtered by IDs and partTypes - Get must analyze ctx.Err AFTER each write to channel - *perr will be valid when chan is closed - `Get` is intended for fast reading, Cassandra implementation must use CL=1 - ErrFilteringByOnlyPartsIsProhibited must be returned if len(partTypes) > 0 && len(IDs) == 0

View Source
var GetEvents func(ctx context.Context, LogID int64, offset1From, offset1To int64) (res <-chan Event, perr *error)

GetEvents between offset1From and offset1To (offset1To INCLUDED into result) Must analyze ctx.Err AFTER each write to channel

View Source
var Put func(ctx context.Context, workspaceID int64, batch []Record) error

Put puts records in transaction

View Source
var PutEvents func(ctx context.Context, LogID int64, batch []Event) (err error)

PutEvents batch of events Transaction is not needed (so only some records can be written) Offset1 MUST monotonically increase If it is not GetEvents may stop on first missed number

Functions

func DeclareForTest added in v0.10.0

func DeclareForTest()

DeclareForTest s.e.

func DeclareForTest2 added in v0.12.0

func DeclareForTest2()

DeclareForTest2 s.e.

func GenerateWSID added in v0.15.0

func GenerateWSID() int64

GenerateWSID s.e.

func TestImpl added in v0.6.0

func TestImpl(actx context.Context, t *testing.T)

TestImpl s.e. Storage must be empty before testing

func TestImpl2 added in v0.12.0

func TestImpl2(actx context.Context, t *testing.T)

TestImpl2 s.e. Storage must be empty before testing

func ToRecords added in v0.6.0

func ToRecords(records <-chan Record) <-chan Records

ToRecords groups values of `records` channel by ID and produces channel of Records

Types

type Event added in v0.12.0

type Event struct {
	Offset1         int64
	Offset2         int64
	WSID            int64
	Domain          int32
	Type            int32
	OriginDeviceID  int64
	OriginTimestamp int64
	OriginOffset    int64
	MyTimestamp     int64
	Data            []byte
	MetaData        []byte
}

Event s.e.

func ToEventSlice added in v0.12.0

func ToEventSlice(records <-chan Event, perr *error) ([]Event, error)

ToEventSlice converts chan Event to []Event

type Record

type Record struct {
	RecordType int32
	ID         int64

	DocType int32
	DocID   int64

	ParentType int32
	ParentID   int64

	PartType int32
	PartID   int64

	// Offset of the event which affected the value
	Offset int64
	// 0-deleted, 1-active, 2-closed
	State int32
	// Data
	Value []byte
}

Record used by Put

func ToSlice added in v0.6.0

func ToSlice(records <-chan Record, perr *error) ([]Record, error)

ToSlice converts chan Record to []Record

type Records added in v0.6.0

type Records []Record

Records returned by ToRecords

func (Records) GetPart added in v0.6.0

func (rr Records) GetPart(partType int32) *Record

GetPart returns first part by type or nil if part not found

func (Records) GetParts added in v0.6.0

func (rr Records) GetParts(partType int32) []Record

GetParts returns all parts by type or nil if part not found

Jump to

Keyboard shortcuts

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