Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update license headers for Dgraph Community License files. #2794

Merged
merged 1 commit into from
Nov 30, 2018
Merged
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 ee/backup/backup.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ee/backup/file_handler.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ee/backup/s3_handler.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ee/backup/writer.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
116 changes: 7 additions & 109 deletions worker/backup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !oss
// +build oss

/*
* Copyright 2018 Dgraph Labs, Inc. and Contributors
Expand All @@ -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)
}
137 changes: 137 additions & 0 deletions worker/backup_ee.go
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
}
41 changes: 0 additions & 41 deletions worker/backup_oss.go

This file was deleted.