From 643e79314e3b30646f06232b2806d1da337fe3ab Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Fri, 30 Nov 2018 11:18:20 -0800 Subject: [PATCH] Update license headers for Dgraph Community License files. (#2794) * Rename backup_oss.go -> backup.go * Rename backup.go -> backup_ee.go --- ee/backup/backup.go | 2 +- ee/backup/file_handler.go | 2 +- ee/backup/s3_handler.go | 2 +- ee/backup/writer.go | 2 +- worker/backup.go | 116 ++------------------------------ worker/backup_ee.go | 137 ++++++++++++++++++++++++++++++++++++++ worker/backup_oss.go | 41 ------------ 7 files changed, 148 insertions(+), 154 deletions(-) create mode 100644 worker/backup_ee.go delete mode 100644 worker/backup_oss.go diff --git a/ee/backup/backup.go b/ee/backup/backup.go index 8e471f958dd..f2c2697a11d 100644 --- a/ee/backup/backup.go +++ b/ee/backup/backup.go @@ -1,7 +1,7 @@ // +build !oss /* - * Copyright 2018 Dgraph Labs, Inc. All rights reserved. + * 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 diff --git a/ee/backup/file_handler.go b/ee/backup/file_handler.go index 54e2dce6bc3..c3dadb9255b 100644 --- a/ee/backup/file_handler.go +++ b/ee/backup/file_handler.go @@ -1,7 +1,7 @@ // +build !oss /* - * Copyright 2018 Dgraph Labs, Inc. All rights reserved. + * 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 diff --git a/ee/backup/s3_handler.go b/ee/backup/s3_handler.go index 32d5946039e..02d3bd1b422 100644 --- a/ee/backup/s3_handler.go +++ b/ee/backup/s3_handler.go @@ -1,7 +1,7 @@ // +build !oss /* - * Copyright 2018 Dgraph Labs, Inc. All rights reserved. + * 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 diff --git a/ee/backup/writer.go b/ee/backup/writer.go index ed5262047df..5e3c47d88cd 100644 --- a/ee/backup/writer.go +++ b/ee/backup/writer.go @@ -1,7 +1,7 @@ // +build !oss /* - * Copyright 2018 Dgraph Labs, Inc. All rights reserved. + * 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 diff --git a/worker/backup.go b/worker/backup.go index 9fc2ac749d9..c4abb9d8ece 100644 --- a/worker/backup.go +++ b/worker/backup.go @@ -1,4 +1,4 @@ -// +build !oss +// +build oss /* * Copyright 2018 Dgraph Labs, Inc. and Contributors @@ -19,125 +19,23 @@ package worker import ( - "time" + "errors" - "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) -} +var errNotSupported = errors.New("Feature available only in Dgraph Enterprise Edition.") -// Backup handles a request coming from another node. +// Backup implements the Worker interface. 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 + glog.Infof("Backup failed: %s", errNotSupported) + return &pb.Status{}, 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 + return x.Errorf("Backup failed: %s", errNotSupported) } diff --git a/worker/backup_ee.go b/worker/backup_ee.go new file mode 100644 index 00000000000..bb5e1a78f9f --- /dev/null +++ b/worker/backup_ee.go @@ -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 +} diff --git a/worker/backup_oss.go b/worker/backup_oss.go deleted file mode 100644 index c4abb9d8ece..00000000000 --- a/worker/backup_oss.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build oss - -/* - * Copyright 2018 Dgraph Labs, Inc. and Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package worker - -import ( - "errors" - - "github.com/dgraph-io/dgraph/protos/pb" - "github.com/dgraph-io/dgraph/x" - "github.com/golang/glog" - "golang.org/x/net/context" -) - -var errNotSupported = errors.New("Feature available only in Dgraph Enterprise Edition.") - -// Backup implements the Worker interface. -func (w *grpcWorker) Backup(ctx context.Context, req *pb.BackupRequest) (*pb.Status, error) { - glog.Infof("Backup failed: %s", errNotSupported) - return &pb.Status{}, nil -} - -// BackupOverNetwork handles a request coming from an HTTP client. -func BackupOverNetwork(pctx context.Context, target string) error { - return x.Errorf("Backup failed: %s", errNotSupported) -}