Documentation
¶
Overview ¶
Package hooks provides configuration and hooks for running Dgraph in embedded mode.
The initialization functions that would create import cycles are intentionally left to the host application, which wires up the individual packages (edgraph, worker, posting, schema, x) directly.
Usage:
- Call hooks.Enable() with your ZeroHooks configuration.
- Initialize packages directly: edgraph.Init(), worker.State.InitStorage(), etc.
- The hooks in this package are then called automatically by worker functions.
- Call hooks.Disable() when shutting down.
Index ¶
- func Disable()
- func Enable(cfg *Config)
- func IsEnabled() bool
- func SetDefaultZeroHooks(h ZeroHooks)
- type Config
- type ZeroHooks
- type ZeroHooksFns
- func (h ZeroHooksFns) ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error)
- func (h ZeroHooksFns) AssignNsIDs(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
- func (h ZeroHooksFns) AssignTimestamps(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
- func (h ZeroHooksFns) AssignUIDs(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
- func (h ZeroHooksFns) CommitOrAbort(ctx context.Context, tc *api.TxnContext) (*api.TxnContext, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Enable ¶
func Enable(cfg *Config)
Enable activates embedded mode with the given configuration. This must be called before any Dgraph operations.
func SetDefaultZeroHooks ¶
func SetDefaultZeroHooks(h ZeroHooks)
SetDefaultZeroHooks registers the fallback ZeroHooks used when embedded mode is disabled or Config.ZeroHooks is nil. The worker package calls this from its init.
Types ¶
type Config ¶
type Config struct {
// ZeroHooks overrides the Zero operations the worker performs. When nil, the
// default network-backed hooks registered by the worker package are used.
ZeroHooks ZeroHooks
}
Config holds the configuration for embedded mode operation.
type ZeroHooks ¶
type ZeroHooks interface {
AssignUIDs(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
AssignTimestamps(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
AssignNsIDs(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
CommitOrAbort(ctx context.Context, tc *api.TxnContext) (*api.TxnContext, error)
ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error)
}
ZeroHooks abstracts the Zero-coordinated operations the worker depends on: UID/namespace/timestamp assignment, transaction commit, and mutation application. The default implementation talks to a Zero cluster over the network; embedded deployments supply their own via Config.ZeroHooks.
The worker entry points set pb.Num.Type before calling AssignUIDs and AssignNsIDs, so implementations receive a fully-typed request and need not set it themselves.
type ZeroHooksFns ¶
type ZeroHooksFns struct {
AssignUIDsFn func(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
AssignTimestampsFn func(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
AssignNsIDsFn func(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
CommitOrAbortFn func(ctx context.Context, tc *api.TxnContext) (*api.TxnContext, error)
ApplyMutationsFn func(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error)
}
ZeroHooksFns adapts a set of plain functions into a ZeroHooks implementation, letting callers override individual operations without declaring a new type.
func (ZeroHooksFns) ApplyMutations ¶
func (h ZeroHooksFns) ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error)
func (ZeroHooksFns) AssignNsIDs ¶
func (h ZeroHooksFns) AssignNsIDs(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
func (ZeroHooksFns) AssignTimestamps ¶
func (h ZeroHooksFns) AssignTimestamps(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
func (ZeroHooksFns) AssignUIDs ¶
func (h ZeroHooksFns) AssignUIDs(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error)
func (ZeroHooksFns) CommitOrAbort ¶
func (h ZeroHooksFns) CommitOrAbort(ctx context.Context, tc *api.TxnContext) (*api.TxnContext, error)