journal

package
v0.0.0-...-f9b9731 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const JOURNAL_NAME_REGEX = ".+"

Variables

View Source
var NameRegExp *regexp.Regexp

Functions

func JHashFromName

func JHashFromName(jname string) uint64

JidFromName returns a journal id (jid) by its name

Types

type ChnksController

type ChnksController interface {
	// JournalName returns the jounal name it controls
	JournalName() string

	// GetChunkForWrite returns chunk for write operaion, the call could
	// be cancelled via ctx. The excludeCid could contain the chunk.Id which should
	// not be returned. Providing excludeCid the client indicates that it already
	// tries to write to the chunk and the operation was not successful, so it should not
	// be repeated.
	// ctx == nil is acceptable
	GetChunkForWrite(ctx context.Context, excludeCid chunk.Id) (chunk.Chunk, error)

	// Chunks returns a sorted list of chunks. ctx can cancel the call. ctx
	// could be nil.
	Chunks(ctx context.Context) (chunk.Chunks, error)

	// WaitForNewData waits till new data appears in the journal, or the
	// ctx is closed. Will return an error if any. or indicates the new
	// data is added to the journal
	WaitForNewData(ctx context.Context, pos Pos) error

	// DeleteChunk marks the journal's chunk with Id <= lastCid as deleted. The cdf will be called as soon as a chunk
	// will be marked as deleted. The DeleteChunk doesn't delete the chunk data physically, but it gets the chunk out from
	// the service loop. The callback function could either delete the data or archive it.
	// The function returns number of chunks makred as deleted or an error, if any
	DeleteChunks(ctx context.Context, lastCid chunk.Id, cdf OnChunkDeleteF) (int, error)

	// LocalFolder returns the folder on the FS where all the chunks are stored
	LocalFolder() string
}

ChnksController allows to create and access to the journal's chunks, it is used by the journal.journal implementation.

type Controller

type Controller interface {
	// Visit iterate over all known journals and it calls the cv for every journal found. Iteration is
	// stopped when all journals are visited or cv returns false
	Visit(ctx context.Context, cv ControllerVisitorF)

	// GetOrCreate creates new, or gives an access to existing journal
	GetOrCreate(ctx context.Context, jname string) (Journal, error)

	// Delete removes the internal record, but doesn't touch the journal data.
	// an error could be returned if there are alive chunks registered. The journal could be
	// re-created following up calls by GetOrCreate
	Delete(ctx context.Context, jname string) error
}

Controller provides an access to known journals

Clients should use the interface for accessing to journals and their states

type ControllerVisitorF

type ControllerVisitorF func(j Journal) bool

ControllerVisitor is a func which will be called by Visit() function (see Controller). It must return false if the process should be stopped

type Iterator

type Iterator interface {
	io.Closer
	records.Iterator

	Pos() Pos

	// SetPos allows to change the JIterator position
	SetPos(pos Pos)
}

Iterator interface provides a journal JIterator

type JIterator

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

func NewJIterator

func NewJIterator(j Journal) *JIterator

func (*JIterator) Close

func (it *JIterator) Close() error

func (*JIterator) CurrentPos

func (it *JIterator) CurrentPos() records.IteratorPos

func (*JIterator) Get

func (it *JIterator) Get(ctx context.Context) (records.Record, error)

func (*JIterator) Next

func (it *JIterator) Next(ctx context.Context)

func (*JIterator) Pos

func (it *JIterator) Pos() Pos

func (*JIterator) Release

func (it *JIterator) Release()

func (*JIterator) SetBackward

func (it *JIterator) SetBackward(bkwrd bool)

func (*JIterator) SetPos

func (it *JIterator) SetPos(pos Pos)

func (*JIterator) String

func (it *JIterator) String() string

type Journal

type Journal interface {

	// Name returns the journal name
	Name() string

	// Write - writes records received from the JIterator to the journal.
	// It returns number of records written, next record write position and an error if any
	Write(ctx context.Context, rit records.Iterator) (int, Pos, error)

	// Size returns the summarized chunks' size
	Size() uint64

	// Count returns number of records in the journal
	Count() uint64

	// Sync could be called after a write to sync the written data with the
	// storage to be sure the read will be able to read the new added
	// data
	Sync()

	// ChnksController returns ChnksController for the journal
	Chunks() ChnksController
}

Journal interface describes a journal

func New

func New(cc ChnksController) Journal

New creates a new journal

type OnChunkDeleteF

type OnChunkDeleteF func(cid chunk.Id, filename string, err error)

OnChunkDeleteF is callback function provided to ChnksController.DeleteChunk. It will be invoked as soon as the chunk is marked as deleted.

type Pos

type Pos struct {
	CId chunk.Id
	Idx uint32
}

Pos defines a position within a journal. Can be ordered.

func ParsePos

func ParsePos(pstr string) (Pos, error)

func (Pos) Less

func (jp Pos) Less(jp2 Pos) bool

func (Pos) String

func (jp Pos) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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