Movatterモバイル変換


[0]ホーム

URL:


ddlog

package
v0.0.0-...-ca5ded8Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License:MITImports:7Imported by:0

Details

Repository

github.com/vmware/differential-datalog

Links

Documentation

Overview

Package ddlog contains Go bindings for the DDlog C API.

Index

Constants

This section is empty.

Variables

View Source
var (// StdSomeConstructor is a static string for the "std.Some" DDlog constructor.StdSomeConstructor =NewCString("std.Some")// StdNoneConstructor is a static string for the "std.None" DDlog constructor.StdNoneConstructor =NewCString("std.None")// StdLeftConstructor is a static string for the "std.Left" DDlog constructor.StdLeftConstructor =NewCString("std.Left")// StdRightConstructor is a static string for the "std.Right" DDlog constructor.StdRightConstructor =NewCString("std.Right"))

Functions

funcDefaultErrMsgPrinter

func DefaultErrMsgPrinter(msgstring)

DefaultErrMsgPrinter is the default printer used to display DDlog error messages. It prints themessages to stderr. Override it by calling SetErrMsgPrinter.

funcSetErrMsgPrinter

func SetErrMsgPrinter(errMsgPrinterErrMsgPrinter)

SetErrMsgPrinter overrides the default error message printer used to display DDlog errormessages. An errMsgPrinter set to nil be cause all error messages to be dropped. Concurrent callsto the provided errMsgPrinter will be sequential.

Types

typeCString

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

CString is a wrapper around a C string. This is useful when you want to pre-allocate a "static"string once and use it multiple times, as it avoids multiple calls to C.CString / copies.

funcNewCString

func NewCString(sstring)CString

NewCString creates a new CString. It invokes C.CString which allocates a C string in the C heapusing malloc and copies the contents of the Go string to that location. Because this is a "Cpointer", it is not subject to the restrictions of Go pointers(https://golang.org/cmd/cgo/#hdr-Passing_pointers). It is the caller's responsibility to releasethe allocated memory by calling Free.

func (CString)Free

func (csCString) Free()

Free releases the memory allocated in the C heap for the underlying C string. Do not use theCstring instance after calling this method.

typeCommand

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

Command is a wrapper around a DDlog command (ddlog_cmd *). Creating a Command with one of thefunctions below will never fail; however the command it creates may fail to execute.

funcNewDeleteKeyCommand

func NewDeleteKeyCommand(tableIDTableID, rRecord)Command

NewDeleteKeyCommand creates a delete-by-key command. tableID must have a primary key for thiscommand to work.

funcNewDeleteValCommand

func NewDeleteValCommand(tableIDTableID, rRecord)Command

NewDeleteValCommand creates a delete-by-value command.

funcNewInsertCommand

func NewInsertCommand(tableIDTableID, rRecord)Command

NewInsertCommand creates an insert command.

funcNewInsertOrUpdateCommand

func NewInsertOrUpdateCommand(tableIDTableID, rRecord)Command

NewInsertOrUpdateCommand creates an insert-or-update command.

typeErrMsgPrinter

type ErrMsgPrinter func(msgstring)

ErrMsgPrinter is the function type for the user-provided printer which will be invoked every timeDDlog generates an error.

typeOutRecordDumper

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

OutRecordDumper implements the OutRecordHandler interface: use it to log all the changes receivedfrom DDlog to a file.

funcNewOutRecordDumper

func NewOutRecordDumper(changesFileNamestring) (*OutRecordDumper,error)

NewOutRecordDumper creates an OutRecordDumper instance.

funcNewOutRecordStdoutDumper

func NewOutRecordStdoutDumper() (*OutRecordDumper,error)

NewOutRecordStdoutDumper creates an OutRecordDumper instance which writes all the changesreceived from DDlog to stdout.

func (*OutRecordDumper)Handle

func (d *OutRecordDumper) Handle(p *Program, tableIDTableID, rRecord, weightint64)

Handle logs all the changes received from DDlog to a file. This should roughly match the outputformat from the DDlog CLI. Errors occurring when writing to disk are ignored.

typeOutRecordHandler

type OutRecordHandler interface {// Handle is called for every change reported by DDlog. There will a call to Handle for each// new or deleted record (there is no notion of "modified" output record in DDlog). Handle// will be called exactly once for each new / deleted record.Handle(*Program,TableID,Record,int64)}

OutRecordHandler defines an interface which lets the client register a "callback" (when creatinga Program) for DDlog changes.

typeOutRecordSink

type OutRecordSink struct{}

OutRecordSink implements the OutRecordHandler interface: use it to discard all the changesreceived from DDlog.

funcNewOutRecordSink

func NewOutRecordSink() (*OutRecordSink,error)

NewOutRecordSink creates an OutRecordSink instance.

func (*OutRecordSink)Handle

func (s *OutRecordSink) Handle(p *Program, tableIDTableID, rRecord, weightint64)

Handle will discard all the changes received from DDlog.

typeProgram

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

Program is an instance of a DDlog program. It corresponds to ddlog_prog struct in the C API.

funcNewProgram

func NewProgram(workersuint, outRecordHandlerOutRecordHandler) (*Program,error)

NewProgram creates a new instance of a DDlog Program. workers is the number of worker threadsthat DDlog is allowed to use. outRecordHandler implements the Handle method, which will be calledevery time an output record is created / deleted. If workers is greater than 1, Handle can becalled concurrently from multiple worker threads.

func (*Program)ApplyUpdate

func (p *Program) ApplyUpdate(commandCommand)error

ApplyUpdate applies a single update to DDlog tables. Must be called as part of a transaction.

func (*Program)ApplyUpdates

func (p *Program) ApplyUpdates(commands ...Command)error

ApplyUpdates applies updates to DDlog tables. Must be called as part of a transaction.

func (*Program)ApplyUpdatesAsTransaction

func (p *Program) ApplyUpdatesAsTransaction(commands ...Command)error

ApplyUpdatesAsTransaction starts a transaction, applies updates to DDlog tables and commits thetransaction.

func (*Program)ClearRelation

func (p *Program) ClearRelation(tableIDTableID)error

ClearRelation clears all input relations in the provided table.

func (*Program)CommitTransaction

func (p *Program) CommitTransaction()error

CommitTransaction commits a transaction.

func (*Program)CommitTransactionChangesAsArray

func (p *Program) CommitTransactionChangesAsArray()error

CommitTransactionChangesAsArray commits a transaction. It uses a different implementation fromCommitTransaction, which may yield better performance when many output records aregenerated. Unlike with CommitTransaction, DDlog will not generate one callback for each outputrecord, but will return an array of output records (with weight). Note that we still generateone OutRecordHandler callback for each output record.

func (*Program)DumpInputSnapshot

func (p *Program) DumpInputSnapshot(namestring)error

DumpInputSnapshot dumps current snapshot of input tables to the provided file in a formatsuitable for replay debugging.

func (*Program)GetTableID

func (p *Program) GetTableID(namestring)TableID

GetTableID gets the table id by name.

func (*Program)GetTableName

func (p *Program) GetTableName(tableIDTableID)string

GetTableName gets the table name by id.

func (*Program)GetTableOriginalName

func (p *Program) GetTableOriginalName(namestring)string

GetTableOriginalName gets the table's original name, if the relationhad an 'original=\"name\"' annotation. Otherwise it returnsthe table name itself (if it is a legal table name).

func (*Program)RollbackTransaction

func (p *Program) RollbackTransaction()error

RollbackTransaction rollbacks an ongoing transaction.

func (*Program)StartRecordingCommands

func (p *Program) StartRecordingCommands(namestring)error

StartRecordingCommands creates a file with the provided name to record all the commands sent toDDlog. If the file already exists, it will be truncated.

func (*Program)StartTransaction

func (p *Program) StartTransaction()error

StartTransaction starts a transaction. Note that DDlog does not support nested or concurrenttransactions.

func (*Program)Stop

func (p *Program) Stop()error

Stop stops the DDlog program and deallocates all the resources allocated by DDlog.

func (*Program)StopRecordingCommands

func (p *Program) StopRecordingCommands()error

StopRecordingCommands stops recording the commands sent to DDlog to file and closes the file.

typeRecord

type Record interface {// Free releases the memory associated with a given record. Do not call this method if// ownership of the record has already been transferred to DDlog (e.g. by adding the record// to a command).Free()// Dump returns a string representation of a record.Dump()string// IsNull returns true iff the record is NULL.IsNull()bool// IsBool returns true iff the record is a boolean record.IsBool()bool// IsInt returns true iff the record is an integer record.IsInt()bool// IsString returns true iff the record is a string record.IsString()bool// IsTuple returns true iff the record is a tuple record.IsTuple()bool// IsVector returns true iff the record is a vector record.IsVector()bool// IsMap returns true iff the record is a map record.IsMap()bool// IsSet returns true iff the record is a set record.IsSet()bool// IsStruct returns true iff the record is a struct record.IsStruct()bool// IntBits returns the minimum number of bits required to represent the record if it is an// integer record. It returns 0 if the record is not an integer record.IntBits()int// ToBool returns the value of a boolean record. Behavior is undefined if the record is not// a boolean.ToBool()bool// ToBoolSafe returns the value of a boolean record. Returns an error if the record is not a// boolean.ToBoolSafe() (bool,error)// ToU128 returns the value of an integer record as a Uint128. Behavior is undefined if the// record is not an integer or if its value does not fit into 128 bits.ToU128()uint128.Uint128// ToU128Safe returns the value of an integer record as a Uint128. Returns an error if the// record is not an integer or if its value does not fit into 128 bits.ToU128Safe() (uint128.Uint128,error)// ToU64 returns the value of an integer record as a uint64. Behavior is undefined if the// record is not an integer or if its value does not fit into 64 bits.ToU64()uint64// ToU64Safe returns the value of an integer record as a uint64. Returns an error if the// record is not an integer or if its value does not fit into 64 bits.ToU64Safe() (uint64,error)// ToU32 returns the value of an integer record as a uint32. Behavior is undefined if the// record is not an integer or if its value does not fit into 32 bits.ToU32()uint32// ToU32Safe returns the value of an integer record as a uint32. Returns an error if the// record is not an integer or if its value does not fit into 32 bits.ToU32Safe() (uint32,error)// ToI64 returns the value of an integer record as an int64. Behavior is undefined if the// record is not an integer or if its value does not fit into 64 bits.ToI64()int64// ToI64Safe returns the value of an integer record as an int64. Returns an error if the// record is not an integer or if its value does not fit into 64 bits.ToI64Safe() (int64,error)// ToI32 returns the value of an integer record as an int32. Behavior is undefined if the// record is not an integer or if its value does not fit into 32 bits.ToI32()int32// ToI32Safe returns the value of an integer record as an int32. Returns an error if the// record is not an integer or if its value does not fit into 32 bits.ToI32Safe() (int32,error)// ToString returns the value of a string record. Behavior is undefined if the record is not// a string.ToString()string// ToStringSafe returns the value of a string record. Returns an error if the record is not// a string.ToStringSafe() (string,error)// AsTuple interprets the current record as a tuple, enabling the caller to use methods// which are specific to tuples on the returned object. Behavior is undefined if the record// is not a tuple.AsTuple()RecordTuple// AsTupleSafe interprets the current record as a tuple, enabling the caller to use methods// which are specific to tuples on the returned object. Returns an error if the record is// not a tuple.AsTupleSafe() (RecordTuple,error)// AsVector interprets the current record as a vector, enabling the caller to use methods// which are specific to vectors on the returned object. Behavior is undefined if the record// is not a vector.AsVector()RecordVector// AsVectorSafe interprets the current record as a vector, enabling the caller to use// methods which are specific to vectors on the returned object. Returns an error if the// record is not a vector.AsVectorSafe() (RecordVector,error)// AsMap interprets the current record as a map, enabling the caller to use methods which// are specific to maps on the returned object. Behavior is undefined if the record is not a// map.AsMap()RecordMap// AsMapSafe interprets the current record as a map, enabling the caller to use methods// which are specific to maps on the returned object. Returns an error if the record is not// a map.AsMapSafe() (RecordMap,error)// AsSet interprets the current record as a set, enabling the caller to use methods which// are specific to sets on the returned object. Behavior is undefined if the record is not a// set.AsSet()RecordSet// AsSetSafe interprets the current record as a set, enabling the caller to use methods// which are specific to sets on the returned object. Returns an error if the record is not// a set.AsSetSafe() (RecordSet,error)// AsStruct interprets the current record as a struct, enabling the caller to use methods// which are specific to structs on the returned object. Behavior is undefined if the record// is not a struct.AsStruct()RecordStruct// AsStructSafe interprets the current record as a struct, enabling the caller to use// methods which are specific to structs on the returned object. Returns an error if the// record is not a struct.AsStructSafe() (RecordStruct,error)// contains filtered or unexported methods}

Record represents a DDlog record. It is an interface, rather than simply a wrapper around addlog_record pointer, to provide some type-safety. In particular, some methods are not includedin this interface because they are specific to a type of record (e.g. Push() for a RecordVector).

funcNewRecordBool

func NewRecordBool(vbool)Record

NewRecordBool creates a boolean record.

funcNewRecordI32

func NewRecordI32(vint32)Record

NewRecordI32 creates a record for a signed integer value. Can be used to populate any DDlog fieldof type `signed<N>`, `N<=32`.

funcNewRecordI64

func NewRecordI64(vint64)Record

NewRecordI64 creates a record for a signed integer value. Can be used to populate any DDlog fieldof type `signed<N>`, `N<=64`.

funcNewRecordLeft

func NewRecordLeft(rRecord)Record

NewRecordLeft is a convenience wrapper around NewRecordStructStatic for the std.Leftconstructor.

funcNewRecordNone

func NewRecordNone()Record

NewRecordNone is a convenience wrapper around NewRecordStructStatic for the std.Noneconstructor.

funcNewRecordNull

func NewRecordNull()Record

NewRecordNull returns a NULL record, which can be used as a placeholder for an invalid record.

funcNewRecordRight

func NewRecordRight(rRecord)Record

NewRecordRight is a convenience wrapper around NewRecordStructStatic for the std.Rightconstructor.

funcNewRecordSome

func NewRecordSome(rRecord)Record

NewRecordSome is a convenience wrapper around NewRecordStructStatic for the std.Someconstructor.

funcNewRecordString

func NewRecordString(vstring)Record

NewRecordString creates a record for a string.

funcNewRecordU128

func NewRecordU128(vuint128.Uint128)Record

NewRecordU128 creates a record for an unsigned integer value. Can be used to populate any DDlogfield of type `bit<N>`, `N<=128`.

funcNewRecordU32

func NewRecordU32(vuint32)Record

NewRecordU32 creates a record for an unsigned integer value. Can be used to populate any DDlogfield of type `bit<N>`, `N<=32`.

funcNewRecordU64

func NewRecordU64(vuint64)Record

NewRecordU64 creates a record for an unsigned integer value. Can be used to populate any DDlogfield of type `bit<N>`, `N<=64`.

typeRecordMap

type RecordMap interface {Record// Push appends a key-value pair to the map.Push(rKey, rValueRecord)// KeyAt returns the i-th key of the map. Returns a NULL record if the map has fewer than i// key-value pairs.KeyAt(idxint)Record// ValueAt returns the i-th value of the map. Returns a NULL record if the map has fewer// than i key-value pairs.ValueAt(idxint)Record// At returns the i-th key-value pair of the map. Returns a NULL record if the map has fewer// than i key-value pairs.At(idxint) (Record,Record)// Size returns the number of key-value pairs in the map.Size()int}

RecordMap extends the Record interface for DDlog records of type map.

funcNewRecordMap

func NewRecordMap(records ...Record)RecordMap

NewRecordMap creates a map record with specified key-value pairs.

typeRecordSet

type RecordSet interface {Record// Push appends an element to the set.Push(rValueRecord)// At returns the i-th element of the set. Returns a NULL record if the set has fewer than i// elements.At(idxint)Record// Size returns the number of elements in the set.Size()int}

RecordSet extends the Record interface for DDlog records of type set.

funcNewRecordSet

func NewRecordSet(records ...Record)RecordSet

NewRecordSet creates a set record with specified elements.

typeRecordStruct

type RecordStruct interface {Record// Name returns the constructor name for the struct.Name()string// At returns the i-th field of the struct. Returns a NULL record if the struct has fewer// than i fields.At(idxint)Record}

RecordStruct extends the Record interface for DDlog records of type struct.

funcNewRecordStruct

func NewRecordStruct(constructorstring, records ...Record)RecordStruct

NewRecordStruct creates a struct record with specified constructor name and arguments.

funcNewRecordStructStatic

func NewRecordStructStatic(constructorCString, records ...Record)RecordStruct

NewRecordStructStatic creates a struct record with specified constructor name andarguments. Unlike NewRecordStruct, this function takes a CString for the constructor to avoidmaking an extra copy of the constructor string when it is "static" (known ahead of time).

typeRecordTuple

type RecordTuple interface {Record// Push appends an element to the tuple.Push(rValueRecord)// At returns the i-th element of the tuple. Returns a NULL record if the tuple has fewer// than i elements.At(idxint)Record// Size returns the number of elements in the tuple.Size()int}

RecordTuple extends the Record interface for DDlog records of type tuple.

funcNewRecordPair

func NewRecordPair(r1, r2Record)RecordTuple

NewRecordPair is a convenience way to create a 2-tuple. Such tuples are useful when constructingmaps out of key-value pairs.

funcNewRecordTuple

func NewRecordTuple(records ...Record)RecordTuple

NewRecordTuple creates a tuple record with specified fields.

typeRecordVector

type RecordVector interface {Record// Push appends an element to the vector.Push(rValueRecord)// At returns the i-th element of the vector. Returns a NULL record if the vector has fewer// than i elements.At(idxint)Record// Size returns the number of elements in the vector.Size()int}

RecordVector extends the Record interface for DDlog records of type vector.

funcNewRecordVector

func NewRecordVector(records ...Record)RecordVector

NewRecordVector creates a vector record with specified elements.

typeTableID

type TableIDuint

TableID is a unique table identifier allocated by DDlog.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp