-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update license headers for Dgraph Community License files. (#2794)
* Rename backup_oss.go -> backup.go * Rename backup.go -> backup_ee.go
- v24.1.1-test1
- v24.1.0
- v24.1.0-rc6
- v24.1.0-rc5
- v24.1.0-rc4
- v24.1-rc3
- v24.1-rc2
- v24.1-rc1
- v24.0.6-test1
- v24.0.6-alpha3
- v24.0.6-alpha2
- v24.0.6-alpha1
- v24.0.5
- v24.0.4
- v24.0.2
- v24.0.2-rc1
- v24.0.1
- v24.0.0
- v24.0.0-rc1
- v24.0.0-alpha3
- v24.0.0-alpha2
- v24.0.0-alpha
- v23.1.1
- v23.1.0
- v23.1.0-rc2
- v23.1.0-rc1
- v23.0.1
- v23.0.0
- v23.0.0-rc1
- v23.0.0-beta1
- v22.0.2
- v22.0.1
- v22.0.0
- v22.0.0-RC1-20221003
- v22-schema-upload-fix
- v21.12.0
- v21.09.0-rc2
- v21.09.0-rc1
- v21.03.2
- v21.03.1
- v21.03.0
- v21.03.0-99-g4a03c144a-slash
- v21.03.0-98-g19f71a78a-slash
- v21.03.0-92-g0c9f60156
- v20.11.3
- v20.11.3-rc1
- v20.11.2
- v20.11.2-rc1
- v20.11.1
- v20.11.1-rc2
- v20.11.1-rc1
- v20.11.0
- v20.11.0-rc5
- v20.11.0-rc4
- v20.11.0-rc3
- v20.11.0-rc2
- v20.11.0-rc1
- v20.07.3
- v20.07.3-rc1
- v20.07.2
- v20.07.2-rc1
- v20.07.1
- v20.07.1-rc1
- v20.07.0
- v20.07.0-rc1
- v20.07.0-beta.Jun22
- v20.07.0-beta.Jun15
- v20.07-slash-20200810
- v20.03.7
- v20.03.7-rc1
- v20.03.6
- v20.03.6-rc1
- v20.03.5
- v20.03.5-rc1
- v20.03.4
- v20.03.4-rc2
- v20.03.4-rc1
- v20.03.3
- v20.03.3-rc1
- v20.03.2
- v20.03.1
- v20.03.0
- v20.03.0-beta.20200320
- v2.0.0-rc1
- v2.0.0-beta1
- v1.2.8
- v1.2.8-rc1
- v1.2.7
- v1.2.7-rc1
- v1.2.6
- v1.2.6-rc2
- v1.2.6-rc1
- v1.2.5
- v1.2.5-rc1
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.2.0-rc1
- v1.1.1
- v1.1.1-rc2
- v1.1.1-rc1
- v1.1.0
- v1.1.0-rc3
- v1.1.0-rc2
- v1.1.0-rc1
- v1.0.18
- v1.0.18-rc4
- v1.0.18-rc3
- v1.0.18-rc2
- v1.0.18-rc1
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.15-rc9
- v1.0.15-rc8
- v1.0.15-rc7
- v1.0.15-rc6
- v1.0.15-rc5
- v1.0.15-rc4
- v1.0.15-rc3
- v1.0.15-rc2
- v1.0.15-rc1
- v1.0.14
- v1.0.14-rc2
- v1.0.14-rc1
- v1.0.14-opencensus-2
- v1.0.14-opencensus
- v1.0.14-3
- v1.0.13
- v1.0.13-opencensus
- v1.0.12
- v1.0.12-rc7
- v1.0.12-rc6
- v1.0.12-rc5
- v1.0.12-rc4
- v1.0.12-rc3
- v1.0.12-rc2
- v1.0.12-rc1
- v1.0.11
- v1.0.11-rc4
- v1.0.11-nolru
- release/v20.11-rc1
- help
Showing
7 changed files
with
148 additions
and
154 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// +build !oss | ||
|
||
/* | ||
* Copyright 2018 Dgraph Labs, Inc. and Contributors | ||
* | ||
* Licensed under the Dgraph Community License (the "License"); you | ||
* may not use this file except in compliance with the License. You | ||
* may obtain a copy of the License at | ||
* | ||
* https://github.com/dgraph-io/dgraph/blob/master/licenses/DCL.txt | ||
*/ | ||
|
||
package worker | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/dgraph-io/dgraph/ee/backup" | ||
"github.com/dgraph-io/dgraph/posting" | ||
"github.com/dgraph-io/dgraph/protos/pb" | ||
"github.com/dgraph-io/dgraph/x" | ||
|
||
"github.com/golang/glog" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
func backupProcess(ctx context.Context, req *pb.BackupRequest) error { | ||
glog.Infof("Backup request: group %d at %d", req.GroupId, req.ReadTs) | ||
if err := ctx.Err(); err != nil { | ||
glog.Errorf("Context error during backup: %v\n", err) | ||
return err | ||
} | ||
// sanity, make sure this is our group. | ||
if groups().groupId() != req.GroupId { | ||
return x.Errorf("Backup request group mismatch. Mine: %d. Requested: %d\n", | ||
groups().groupId(), req.GroupId) | ||
} | ||
// wait for this node to catch-up. | ||
if err := posting.Oracle().WaitForTs(ctx, req.ReadTs); err != nil { | ||
return err | ||
} | ||
// create backup request and process it. | ||
br := &backup.Request{DB: pstore, Backup: req} | ||
// calculate estimated upload size | ||
for _, t := range groups().tablets { | ||
if t.GroupId == req.GroupId { | ||
br.Sizex += uint64(float64(t.Space) * 1.2) | ||
} | ||
} | ||
return br.Process(ctx) | ||
} | ||
|
||
// Backup handles a request coming from another node. | ||
func (w *grpcWorker) Backup(ctx context.Context, req *pb.BackupRequest) (*pb.Status, error) { | ||
var resp pb.Status | ||
glog.V(2).Infof("Received backup request via Grpc: %+v", req) | ||
if err := backupProcess(ctx, req); err != nil { | ||
resp.Code = -1 | ||
resp.Msg = err.Error() | ||
return &resp, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
func backupGroup(ctx context.Context, in pb.BackupRequest) error { | ||
glog.V(2).Infof("Sending backup request: %+v\n", in) | ||
// this node is part of the group, process backup. | ||
if groups().groupId() == in.GroupId { | ||
return backupProcess(ctx, &in) | ||
} | ||
|
||
// send request to any node in the group. | ||
pl := groups().AnyServer(in.GroupId) | ||
if pl == nil { | ||
return x.Errorf("Couldn't find a server in group %d", in.GroupId) | ||
} | ||
status, err := pb.NewWorkerClient(pl.Get()).Backup(ctx, &in) | ||
if err != nil { | ||
glog.Errorf("Backup error group %d: %s", in.GroupId, err) | ||
return err | ||
} | ||
if status.Code != 0 { | ||
err := x.Errorf("Backup error group %d: %s", in.GroupId, status.Msg) | ||
glog.Errorln(err) | ||
return err | ||
} | ||
glog.V(2).Infof("Backup request to gid=%d. OK\n", in.GroupId) | ||
return nil | ||
} | ||
|
||
// BackupOverNetwork handles a request coming from an HTTP client. | ||
func BackupOverNetwork(pctx context.Context, target string) error { | ||
ctx, cancel := context.WithCancel(pctx) | ||
defer cancel() | ||
|
||
// Check that this node can accept requests. | ||
if err := x.HealthCheck(); err != nil { | ||
glog.Errorf("Backup canceled, not ready to accept requests: %s", err) | ||
return err | ||
} | ||
|
||
// Get ReadTs from zero and wait for stream to catch up. | ||
ts, err := Timestamps(ctx, &pb.Num{ReadOnly: true}) | ||
if err != nil { | ||
glog.Errorf("Unable to retrieve readonly timestamp for backup: %s", err) | ||
return err | ||
} | ||
|
||
gids := groups().KnownGroups() | ||
req := pb.BackupRequest{ | ||
ReadTs: ts.ReadOnly, | ||
Target: target, | ||
UnixTs: time.Now().UTC().Format("20060102.1504"), | ||
} | ||
glog.Infof("Created backup request: %+v. Groups=%v\n", req, gids) | ||
|
||
// This will dispatch the request to all groups and wait for their response. | ||
// If we receive any failures, we cancel the process. | ||
errCh := make(chan error, 1) | ||
for _, gid := range gids { | ||
req.GroupId = gid | ||
go func() { | ||
errCh <- backupGroup(ctx, req) | ||
}() | ||
} | ||
|
||
for i := 0; i < len(gids); i++ { | ||
err := <-errCh | ||
if err != nil { | ||
glog.Errorf("Error received during backup: %v", err) | ||
return err | ||
} | ||
} | ||
req.GroupId = 0 | ||
glog.Infof("Backup for req: %+v. OK.\n", req) | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.