hooks

package
v25.3.8 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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:

  1. Call hooks.Enable() with your ZeroHooks configuration.
  2. Initialize packages directly: edgraph.Init(), worker.State.InitStorage(), etc.
  3. The hooks in this package are then called automatically by worker functions.
  4. Call hooks.Disable() when shutting down.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disable

func Disable()

Disable deactivates embedded mode.

func Enable

func Enable(cfg *Config)

Enable activates embedded mode with the given configuration. This must be called before any Dgraph operations.

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if embedded mode is currently active.

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.

func GetConfig

func GetConfig() *Config

GetConfig returns the current embedded configuration, or nil if not enabled.

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.

func GetHooks

func GetHooks() ZeroHooks

GetHooks returns the active Zero hooks. If embedded mode is not enabled, it returns the default hooks implementation.

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)

Jump to

Keyboard shortcuts

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