Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-dgraph-integration2-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
dgraph-integration2-tests:
if: github.event.pull_request.draft == false
runs-on: warp-ubuntu-latest-x64-4x
timeout-minutes: 30
timeout-minutes: 60
steps:
- uses: actions/checkout@v5
with:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2=1.0.8-5+b1 \
git=1:2.39.5-0+deb12u2 \
&& rm -rf /var/lib/apt/lists/*
ARG TARGETARCH=amd64
ARG TARGETOS=linux
WORKDIR /go/src/repo
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN CGO_ENABLED=0 make
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make

###################### Stage II ######################
FROM ubuntu:24.04
Expand Down
28 changes: 17 additions & 11 deletions dgraph/cmd/dgraphimport/import_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,18 @@ func streamSnapshotForGroup(ctx context.Context, dc apiv2.DgraphClient, pdir str
if err != nil {
return fmt.Errorf("failed to start external snapshot stream for group %d: %w", groupId, err)
}

defer func() {
if _, err := out.CloseAndRecv(); err != nil {
glog.Errorf("failed to close the stream for group [%v]: %v", groupId, err)
}

glog.Infof("[import] Group [%v]: Received ACK ", groupId)
_ = out.CloseSend()
}()

// Open the BadgerDB instance at the specified directory
opt := badger.DefaultOptions(pdir)
opt.ReadOnly = true
ps, err := badger.OpenManaged(opt)
if err != nil {
glog.Errorf("failed to open BadgerDB at [%s]: %v", pdir, err)
return fmt.Errorf("failed to open BadgerDB at [%v]: %v", pdir, err)
}

defer func() {
if err := ps.Close(); err != nil {
glog.Warningf("[import] Error closing BadgerDB: %v", err)
Expand All @@ -154,17 +149,18 @@ func streamSnapshotForGroup(ctx context.Context, dc apiv2.DgraphClient, pdir str
glog.Infof("[import] Sending request for streaming external snapshot for group ID [%v]", groupId)
groupReq := &apiv2.StreamExtSnapshotRequest{GroupId: groupId}
if err := out.Send(groupReq); err != nil {
return fmt.Errorf("failed to send request for streaming external snapshot for group ID [%v] to the server: %w",
groupId, err)
return fmt.Errorf("failed to send request for group ID [%v] to the server: %w", groupId, err)
}
if _, err := out.Recv(); err != nil {
return fmt.Errorf("failed to receive response for group ID [%v] from the server: %w", groupId, err)
}
glog.Infof("[import] Group [%v]: Received ACK for sending group request", groupId)

// Configure and start the BadgerDB stream
glog.Infof("[import] Starting BadgerDB stream for group [%v]", groupId)

if err := streamBadger(ctx, ps, out, groupId); err != nil {
return fmt.Errorf("badger streaming failed for group [%v]: %v", groupId, err)
}

return nil
}

Expand All @@ -180,6 +176,11 @@ func streamBadger(ctx context.Context, ps *badger.DB, out apiv2.Dgraph_StreamExt
if err := out.Send(&apiv2.StreamExtSnapshotRequest{Pkt: p}); err != nil && !errors.Is(err, io.EOF) {
return fmt.Errorf("failed to send data chunk: %w", err)
}
if _, err := out.Recv(); err != nil {
return fmt.Errorf("failed to receive response for group ID [%v] from the server: %w", groupId, err)
}
glog.Infof("[import] Group [%v]: Received ACK for sending data chunk", groupId)

return nil
}

Expand All @@ -196,5 +197,10 @@ func streamBadger(ctx context.Context, ps *badger.DB, out apiv2.Dgraph_StreamExt
return fmt.Errorf("failed to send 'done' signal for group [%d]: %w", groupId, err)
}

if _, err := out.Recv(); err != nil {
return fmt.Errorf("failed to receive response for group ID [%v] from the server: %w", groupId, err)
}
glog.Infof("[import] Group [%v]: Received ACK for sending completion signal", groupId)

return nil
}
12 changes: 6 additions & 6 deletions dgraph/cmd/dgraphimport/import_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build integration
//go:build integration2

/*
* SPDX-FileCopyrightText: © Hypermode Inc. <[email protected]>
Expand Down Expand Up @@ -77,7 +77,8 @@ func TestDrainModeAfterStartSnapshotStream(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := dgraphtest.NewClusterConfig().WithNumAlphas(tt.numAlphas).WithNumZeros(tt.numZeros).WithReplicas(tt.replicas)
conf := dgraphtest.NewClusterConfig().WithNumAlphas(tt.numAlphas).
WithNumZeros(tt.numZeros).WithReplicas(tt.replicas)
c, err := dgraphtest.NewLocalCluster(conf)
require.NoError(t, err)
defer func() { c.Cleanup(t.Failed()) }()
Expand Down Expand Up @@ -270,14 +271,12 @@ func runImportTest(t *testing.T, tt testcase) {
require.NoError(t, targetCluster.StopAlpha(alphaID))
}
}

if tt.err != "" {
err := Import(context.Background(), connectionString, outDir)
require.Error(t, err)
require.ErrorContains(t, err, tt.err)
return
}

require.NoError(t, Import(context.Background(), connectionString, outDir))

for group, alphas := range alphaGroups {
Expand All @@ -289,7 +288,6 @@ func runImportTest(t *testing.T, tt testcase) {
}

require.NoError(t, targetCluster.HealthCheck(false))

t.Log("Import completed")

for i := 0; i < tt.targetAlphas; i++ {
Expand Down Expand Up @@ -336,7 +334,9 @@ func setupBulkCluster(t *testing.T, numAlphas int, encrypted bool) (*dgraphtest.
}

// setupTargetCluster creates and starts a cluster that will receive the imported data
func setupTargetCluster(t *testing.T, numAlphas, replicasFactor int) (*dgraphtest.LocalCluster, *dgraphapi.GrpcClient, func()) {
func setupTargetCluster(t *testing.T, numAlphas, replicasFactor int) (
*dgraphtest.LocalCluster, *dgraphapi.GrpcClient, func()) {

conf := dgraphtest.NewClusterConfig().
WithNumAlphas(numAlphas).
WithNumZeros(3).
Expand Down
12 changes: 12 additions & 0 deletions dgraph/cmd/dgraphimport/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func init() {

flag := ImportCmd.Cmd.Flags()
flag.StringP("files", "f", "", "Location of *.rdf(.gz) or *.json(.gz) file(s) to load.")
flag.StringP("snapshot-dir", "p", "", "Location of p directory")
flag.StringP("schema", "s", "", "Location of DQL schema file.")
flag.StringP("graphql_schema", "g", "", "Location of the GraphQL schema file.")
flag.StringP("graphql-schema", "", "", "Location of the GraphQL schema file.")
Expand Down Expand Up @@ -72,6 +73,17 @@ func run() {
os.Exit(1)
}

// if snapshot p directory is already provided, there is no need to run bulk loader
if ImportCmd.Conf.GetString("snapshot-dir") != "" {
connStr := ImportCmd.Conf.GetString("conn-str")
snapshotDir := ImportCmd.Conf.GetString("snapshot-dir")
if err := Import(context.Background(), connStr, snapshotDir); err != nil {
fmt.Println("Failed to import data:", err)
os.Exit(1)
}
return
}

cacheSize := 64 << 20 // These are the default values. User can overwrite them using --badger.
cacheDefaults := fmt.Sprintf("indexcachesize=%d; blockcachesize=%d; ",
(70*cacheSize)/100, (30*cacheSize)/100)
Expand Down
6 changes: 5 additions & 1 deletion dgraphtest/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,12 @@ func (c *LocalCluster) BulkLoad(opts BulkOpts) error {
args = append(args, "-g", strings.Join(opts.GQLSchemaFiles, ","))
}

dgraphCmdPath := os.Getenv("DGRAPH_CMD_PATH")
if dgraphCmdPath == "" {
dgraphCmdPath = filepath.Join(c.tempBinDir, "dgraph")
}
log.Printf("[INFO] running bulk loader with args: [%v]", strings.Join(args, " "))
cmd := exec.Command(filepath.Join(c.tempBinDir, "dgraph"), args...)
cmd := exec.Command(dgraphCmdPath, args...)
if out, err := cmd.CombinedOutput(); err != nil {
return errors.Wrapf(err, "error running bulk loader: %v", string(out))
} else {
Expand Down
12 changes: 7 additions & 5 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1829,18 +1829,20 @@ func (s *ServerV25) UpdateExtSnapshotStreamingState(ctx context.Context,

groups, err := worker.ProposeDrain(ctx, req)
if err != nil {
glog.Errorf("[import] failed to propose drain mode: %v", err)
return nil, err
}

resp := &apiv2.UpdateExtSnapshotStreamingStateResponse{Groups: groups}

return resp, nil
return &apiv2.UpdateExtSnapshotStreamingStateResponse{Groups: groups}, nil
}

func (s *ServerV25) StreamExtSnapshot(stream apiv2.Dgraph_StreamExtSnapshotServer) error {
defer x.ExtSnapshotStreamingState(false)

return worker.InStream(stream)
if err := worker.InStream(stream); err != nil {
glog.Errorf("[import] failed to stream external snapshot: %v", err)
return err
}
return nil
}

// CommitOrAbort commits or aborts a transaction.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/HdrHistogram/hdrhistogram-go v1.1.2
github.com/IBM/sarama v1.45.2
github.com/Masterminds/semver/v3 v3.4.0
github.com/blevesearch/bleve/v2 v2.5.3
github.com/blevesearch/bleve/v2 v2.5.2
github.com/dgraph-io/badger/v4 v4.8.0
github.com/dgraph-io/dgo/v250 v250.0.0-preview4.0.20250619041351-4a519e53fb9d
github.com/dgraph-io/dgo/v250 v250.0.0-preview4.0.20250904103701-6633ef279458
github.com/dgraph-io/gqlgen v0.13.2
github.com/dgraph-io/gqlparser/v2 v2.2.2
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCkcs2uw7w4=
github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/blevesearch/bleve/v2 v2.5.3 h1:9l1xtKaETv64SZc1jc4Sy0N804laSa/LeMbYddq1YEM=
github.com/blevesearch/bleve/v2 v2.5.3/go.mod h1:Z/e8aWjiq8HeX+nW8qROSxiE0830yQA071dwR3yoMzw=
github.com/blevesearch/bleve/v2 v2.5.2 h1:Ab0r0MODV2C5A6BEL87GqLBySqp/s9xFgceCju6BQk8=
github.com/blevesearch/bleve/v2 v2.5.2/go.mod h1:5Dj6dUQxZM6aqYT3eutTD/GpWKGFSsV8f7LDidFbwXo=
github.com/blevesearch/bleve_index_api v1.2.8 h1:Y98Pu5/MdlkRyLM0qDHostYo7i+Vv1cDNhqTeR4Sy6Y=
github.com/blevesearch/bleve_index_api v1.2.8/go.mod h1:rKQDl4u51uwafZxFrPD1R7xFOwKnzZW7s/LSeK4lgo0=
github.com/blevesearch/geo v0.2.4 h1:ECIGQhw+QALCZaDcogRTNSJYQXRtC8/m8IKiA706cqk=
Expand Down Expand Up @@ -132,8 +132,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/badger/v4 v4.8.0 h1:JYph1ChBijCw8SLeybvPINizbDKWZ5n/GYbz2yhN/bs=
github.com/dgraph-io/badger/v4 v4.8.0/go.mod h1:U6on6e8k/RTbUWxqKR0MvugJuVmkxSNc79ap4917h4w=
github.com/dgraph-io/dgo/v250 v250.0.0-preview4.0.20250619041351-4a519e53fb9d h1:9PLyvZY1Nih05g+2womk+kNnX3Gb20kx5BsK3foA5a8=
github.com/dgraph-io/dgo/v250 v250.0.0-preview4.0.20250619041351-4a519e53fb9d/go.mod h1:gLr7uM+x/8PjSQJ4Ca9kfQF15uBzruDzRK3bnELt3vE=
github.com/dgraph-io/dgo/v250 v250.0.0-preview4.0.20250904103701-6633ef279458 h1:X1mVe/Lc0sb6Y+O4nmkXq0wa0QIZPaDhWbULh0ynAPs=
github.com/dgraph-io/dgo/v250 v250.0.0-preview4.0.20250904103701-6633ef279458/go.mod h1:H3PcQuhmfzSC/1I7FLJYOxntpk3UG6lmZAyv0QxRm+o=
github.com/dgraph-io/gqlgen v0.13.2 h1:TNhndk+eHKj5qE7BenKKSYdSIdOGhLqxR1rCiMso9KM=
github.com/dgraph-io/gqlgen v0.13.2/go.mod h1:iCOrOv9lngN7KAo+jMgvUPVDlYHdf7qDwsTkQby2Sis=
github.com/dgraph-io/gqlparser/v2 v2.1.1/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
Expand Down
1 change: 1 addition & 0 deletions protos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ regenerate: tidy-deps copy-protos check clean
@protoc \
--proto_path=/usr/local/include \
--proto_path=/usr/include \
--proto_path=/opt/homebrew/include/google/protobuf \
--proto_path=${PROTO_PATH} \
--go_out=pb --go-grpc_out=pb \
--go_opt=paths=source_relative \
Expand Down
2 changes: 1 addition & 1 deletion protos/depcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function CompareSemVer() {

function CheckProtobufIncludes() {
echo -n "Checking for directory /usr/include/google/protobuf or /usr/local/include/google/protobuf... "
if !([[ -d /usr/include/google/protobuf ]] || [[ -d /usr/local/include/google/protobuf ]]); then
if !([[ -d /usr/include/google/protobuf ]] || [[ -d /usr/local/include/google/protobuf ]] || [[ -d /opt/homebrew/include/google/protobuf ]]); then
echo "FAIL" >&2
echo "Missing protobuf headers in /usr/include/google/protobuf or /usr/local/include/google/protobuf:" \
"directory not found." >&2
Expand Down
16 changes: 12 additions & 4 deletions protos/patch_pb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
# This patch script applies the necessary changes to pb.pb.go.
PB_GEN_FILE="./pb/pb.pb.go"

sed -i 's/SessionToken string/SessionToken Sensitive/' "${PB_GEN_FILE}"
sed -i 's/SecretKey string/SecretKey Sensitive/' "${PB_GEN_FILE}"
# Function to perform in-place sed that works on both macOS and Linux
sed_inplace() {
local tmpfile
tmpfile=$(mktemp)
sed "$1" "$2" >"${tmpfile}" && mv "${tmpfile}" "$2"
rm -f "${tmpfile}"
}

sed -i 's/GetSessionToken() string {/GetSessionToken() Sensitive {/' "${PB_GEN_FILE}"
sed -i 's/GetSecretKey() string/GetSecretKey() Sensitive/' "${PB_GEN_FILE}"
# Apply the replacements using the cross-platform function
sed_inplace 's/SessionToken string/SessionToken Sensitive/' "${PB_GEN_FILE}"
sed_inplace 's/SecretKey string/SecretKey Sensitive/' "${PB_GEN_FILE}"
sed_inplace 's/GetSessionToken() string {/GetSessionToken() Sensitive {/' "${PB_GEN_FILE}"
sed_inplace 's/GetSecretKey() string/GetSecretKey() Sensitive/' "${PB_GEN_FILE}"

echo "Patches applied successfully."
2 changes: 1 addition & 1 deletion protos/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ service Worker {
rpc DeleteNamespace(DeleteNsRequest) returns (Status) {}
rpc TaskStatus(TaskStatusRequest) returns (TaskStatusResponse) {}
rpc UpdateExtSnapshotStreamingState(api.v2.UpdateExtSnapshotStreamingStateRequest) returns (Status) {}
rpc StreamExtSnapshot(stream api.v2.StreamExtSnapshotRequest) returns (api.v2.StreamExtSnapshotResponse) {}
rpc StreamExtSnapshot(stream api.v2.StreamExtSnapshotRequest) returns (stream api.v2.StreamExtSnapshotResponse) {}
}

message TabletResponse {
Expand Down
9 changes: 5 additions & 4 deletions protos/pb/pb.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions protos/pb/pb_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading