chore: add abstraction for worker operations#9578
Draft
matthewmcneely wants to merge 6 commits intomainfrom
Draft
chore: add abstraction for worker operations#9578matthewmcneely wants to merge 6 commits intomainfrom
matthewmcneely wants to merge 6 commits intomainfrom
Conversation
Contributor
Author
|
Here's an example implementation that would work for an internal testing harness. // Enable embedded mode with Zero hooks to bypass distributed Zero node
hooks.Enable(&hooks.Config{
ZeroHooks: hooks.ZeroHooksFns{
AssignUIDsFn: func(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {
num.Type = pb.Num_UID
return engine.z.nextUIDs(num)
},
AssignTimestampsFn: func(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {
ts, err := engine.z.nextTs()
if err != nil {
return nil, err
}
return &pb.AssignedIds{StartId: ts, EndId: ts}, nil
},
AssignNsIDsFn: func(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {
num.Type = pb.Num_NS_ID
nsID, err := engine.z.nextNamespace()
if err != nil {
return nil, err
}
return &pb.AssignedIds{StartId: nsID, EndId: nsID}, nil
},
CommitOrAbortFn: func(ctx context.Context, tc *api.TxnContext) (*api.TxnContext, error) {
if tc.Aborted {
return &api.TxnContext{StartTs: tc.StartTs, Aborted: true}, nil
}
commitTs, err := engine.z.nextTs()
if err != nil {
return nil, err
}
// Apply the commit to the oracle
delta := &pb.OracleDelta{
Txns: []*pb.TxnStatus{{StartTs: tc.StartTs, CommitTs: commitTs}},
}
posting.Oracle().ProcessDelta(delta)
return &api.TxnContext{StartTs: tc.StartTs, CommitTs: commitTs}, nil
},
ApplyMutationsFn: func(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error) {
// Create a proposal with the mutations
p := &pb.Proposal{Mutations: m}
err := worker.ApplyMutations(ctx, p)
return &api.TxnContext{StartTs: m.StartTs}, err
},
},
})Then one could directly access (&edgraph.Server{}).QueryNoAuth(ctx, &api.Request{...}}) |
248eb8f to
15ef722
Compare
mlwelles
approved these changes
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a pluggable hooks framework that abstracts Zero-related operations in the worker package, enabling Dgraph to run in embedded mode without a separate Zero process -- many "unit" tests that aren't reliant on a full networked cluster would be great candidates for the abstraction.
Motivation
To support embedded deployment scenarios where Dgraph runs as a library within another application or in testing, the tight coupling between the worker package and Zero network operations needed to be abstracted. This allows alternative implementations to provide UID assignment, timestamp allocation, and transaction coordination without requiring a running Zero cluster.
Changes
New Package:
hooks/Testing
-raceflag covering:Checklist
Conventional Commits syntax, leading
with
fix:,feat:,chore:,ci:, etc.