streamlog

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package streamlog is the Neptune Streams commit log: an ordered, expiring record of committed graph changes.

Index

Constants

View Source
const (
	OpAdd    = "ADD"
	OpRemove = "REMOVE"
)

Op values of a change record.

View Source
const (
	AtSequenceNumber    = "AT_SEQUENCE_NUMBER"
	AfterSequenceNumber = "AFTER_SEQUENCE_NUMBER"
	TrimHorizon         = "TRIM_HORIZON"
	Latest              = "LATEST"
)

Iterator types accepted by Read.

View Source
const DefaultRetention = 7 * 24 * time.Hour

DefaultRetention is the documented default of neptune_streams_expiry_days (7 days).

Variables

View Source
var (
	// ErrNotFound means the requested sequence number is past the newest record.
	ErrNotFound = errors.New("stream records not found")
	// ErrExpired means the requested sequence number was already trimmed.
	ErrExpired = errors.New("stream records expired")
	// ErrInvalid means the iterator or sequence number is malformed.
	ErrInvalid = errors.New("invalid stream request")
)

Functions

This section is empty.

Types

type Change

type Change struct {
	Op   string
	Data Data
}

Change is one operation of a transaction, before it is numbered.

type Data

type Data struct {
	Value *Value `json:"value,omitempty"`
	ID    string `json:"id,omitempty"`
	Type  string `json:"type,omitempty"`
	Key   string `json:"key,omitempty"`
	From  string `json:"from,omitempty"`
	To    string `json:"to,omitempty"`
	Stmt  string `json:"stmt,omitempty"`
}

Data is the serialised change: PG_JSON fields for property graphs, Stmt (an N-Quads line) for SPARQL.

type Log

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

Log is a concurrency-safe commit log.

func New

func New() *Log

New returns an empty, disabled log.

func (*Log) Commit

func (l *Log) Commit(changes []Change)

Commit records one transaction's changes under the next commit number; it is a no-op when disabled or empty.

func (*Log) Enabled

func (l *Log) Enabled() bool

Enabled reports whether commits are being recorded.

func (*Log) Export

func (l *Log) Export() ([]byte, error)

Export serialises the log for persistence; nil when nothing was ever recorded.

func (*Log) Import

func (l *Log) Import(data []byte) error

Import replaces the log contents with an Export dump; the policy is kept.

func (*Log) Policy

func (l *Log) Policy() Policy

Policy returns the current policy.

func (*Log) Read

func (l *Log) Read(q Query) (Page, error)

Read returns up to q.Limit records from the requested position.

func (*Log) Reset

func (l *Log) Reset()

Reset discards every record and restarts commit numbering.

func (*Log) SetClock

func (l *Log) SetClock(now func() time.Time)

SetClock replaces the time source.

func (*Log) SetPolicy

func (l *Log) SetPolicy(p Policy)

SetPolicy replaces the recording policy.

func (*Log) Size

func (l *Log) Size() (int, int)

Size returns the retained record count and their serialised size in bytes.

type Page

type Page struct {
	Records    []Record
	LastCommit int64
	LastOp     int64
	LastTimeMs int64
}

Page is the result of a read: lastEvent is the id of the final record, or the newest record when empty.

type Policy

type Policy struct {
	Retention time.Duration
	Enabled   bool
}

Policy gates recording and sets retention; it mirrors neptune_streams and neptune_streams_expiry_days.

type Query

type Query struct {
	Iterator  string
	CommitNum int64
	OpNum     int64
	Limit     int
}

Query selects where to start reading.

type Record

type Record struct {
	Op          string `json:"op"`
	Data        Data   `json:"data"`
	CommitNum   int64  `json:"commitNum"`
	OpNum       int64  `json:"opNum"`
	TimestampMs int64  `json:"commitTimestamp"`
	IsLastOp    bool   `json:"isLastOp,omitempty"`
}

Record is a numbered change as stored and served.

type Value

type Value struct {
	Value    any    `json:"value"`
	DataType string `json:"dataType"`
}

Value is a PG_JSON typed value.

Jump to

Keyboard shortcuts

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