Skip to content

Commit

Permalink
Remove LastBackupStatus (#7699)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza authored Apr 7, 2021
1 parent ba817e9 commit dd183aa
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 429 deletions.
1 change: 0 additions & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,6 @@ func (s *Server) Health(ctx context.Context, all bool) (*api.Response, error) {
Version: x.Version(),
Uptime: int64(time.Since(x.WorkerConfig.StartTime) / time.Second),
LastEcho: time.Now().Unix(),
LastBackup: worker.LastBackupStatus.Load().(string),
Ongoing: worker.GetOngoingTasks(),
Indexing: schema.GetIndexingPredicates(),
EeFeatures: worker.GetEEFeaturesList(),
Expand Down
1 change: 0 additions & 1 deletion protos/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ message HealthInfo {
repeated string indexing = 9;
repeated string ee_features = 10;
uint64 max_assigned = 11;
string last_backup = 12;
}

message Tablet {
Expand Down
712 changes: 330 additions & 382 deletions protos/pb/pb.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion systest/backup/encryption/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func runBackup(t *testing.T, numExpectedFiles, numExpectedDirs int) []string {
func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles,
numExpectedDirs int) []string {
testutil.StartBackupHttps(t, backupDst, forceFull)
testutil.WaitForBackup(t)
testutil.WaitForTask(t, "opBackup")

// Verify that the right amount of files and directories were created.
copyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/backup/filesystem/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func runBackup(t *testing.T, numExpectedFiles, numExpectedDirs int) []string {

func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, numExpectedDirs int) []string {
testutil.StartBackupHttps(t, alphaBackupDir, forceFull)
testutil.WaitForBackup(t)
testutil.WaitForTask(t, "opBackup")

// Verify that the right amount of files and directories were created.
common.CopyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/backup/minio-large/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func runBackup(t *testing.T) {
buf, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
require.Contains(t, string(buf), "Backup queued successfully")
testutil.WaitForBackup(t)
testutil.WaitForTask(t, "opBackup")

// Verify that the right amount of files and directories were created.
copyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/backup/minio/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func runBackup(t *testing.T, numExpectedFiles, numExpectedDirs int) []string {
func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles,
numExpectedDirs int) []string {
testutil.StartBackupHttps(t, backupDst, forceFull)
testutil.WaitForBackup(t)
testutil.WaitForTask(t, "opBackup")

// Verify that the right amount of files and directories were created.
copyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/backup/multi-tenancy/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func runBackupInternal(t *testing.T, token *testutil.HttpToken, forceFull bool,
}
require.NoError(t, json.Unmarshal(resp.Data, &result))
require.Contains(t, result.Backup.Response.Message, "Backup queued successfully")
testutil.WaitForBackup(t)
testutil.WaitForTask(t, "opBackup")

// Verify that the right amount of files and directories were created.
common.CopyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/online-restore/online_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func backup(t *testing.T, backupDir string) {
}
testutil.MakeGQLRequestWithTLS(t, backupParams, testutil.GetAlphaClientConfig(t)).
RequireNoGraphQLErrors(t)
testutil.WaitForBackup(t)
testutil.WaitForTask(t, "opBackup")
}

func backupRestoreAndVerify(t *testing.T, dg *dgo.Dgraph, backupDir, queryToVerify,
Expand Down
28 changes: 0 additions & 28 deletions testutil/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,6 @@ func StartBackupHttps(t *testing.T, backupDst string, forceFull bool) {
require.Contains(t, string(responseBody), "Backup queued successfully")
}

func WaitForBackup(t *testing.T) {
healthUrl := "http://" + SockAddrHttp + "/health"
for {
health := func() []pb.HealthInfo {
response, err := http.Get(healthUrl)
require.NoError(t, err)
defer response.Body.Close()

var health []pb.HealthInfo
decoder := json.NewDecoder(response.Body)
err = decoder.Decode(&health)
require.NoError(t, err)
require.Len(t, health, 1)

return health
}()

status := health[0].LastBackup
if strings.HasPrefix(status, "COMPLETED: ") {
break
}
require.True(t, status == "" || strings.HasPrefix(status, "STARTED: "),
"backup failed: status: %s", status)

time.Sleep(4 * time.Second)
}
}

func WaitForRestore(t *testing.T, dg *dgo.Dgraph) {
for {
resp, err := http.Get("http://" + SockAddrHttp + "/health")
Expand Down
32 changes: 32 additions & 0 deletions testutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"time"

"github.com/dgraph-io/dgraph/gql"
"github.com/dgraph-io/dgraph/protos/pb"

"github.com/dgraph-io/dgo/v200"
"github.com/dgraph-io/dgo/v200/protos/api"
Expand Down Expand Up @@ -532,3 +533,34 @@ func GetAlphaClientConfig(t *testing.T) *tls.Config {
require.NoError(t, err)
return tlsConf
}

func WaitForTask(t *testing.T, task string) {
healthUrl := "http://" + SockAddrHttp + "/health"
for {
time.Sleep(5 * time.Second)

var health []pb.HealthInfo
func() {
// #nosec G107
response, err := http.Get(healthUrl)
require.NoError(t, err)
defer response.Body.Close()

decoder := json.NewDecoder(response.Body)
err = decoder.Decode(&health)
require.NoError(t, err)
require.Len(t, health, 1)
}()

completed := true
for _, ongoingTask := range health[0].Ongoing {
if ongoingTask == task {
completed = false
break
}
}
if completed {
break
}
}
}
7 changes: 0 additions & 7 deletions worker/backup_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"math"
"sync"
"sync/atomic"

"github.com/dgraph-io/badger/v3"
"github.com/pkg/errors"
Expand All @@ -29,12 +28,6 @@ import (
"github.com/dgraph-io/dgraph/x"
)

var LastBackupStatus atomic.Value

func init() {
LastBackupStatus.Store("")
}

// predicateSet is a map whose keys are predicates. It is meant to be used as a set.
type predicateSet map[string]struct{}

Expand Down
8 changes: 4 additions & 4 deletions worker/backup_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest, forceFull
}

if err := x.HealthCheck(); err != nil {
glog.Errorf("Backup canceled, not ready to accept requests: %s", err)
glog.Errorf("Backup canceled: not ready to accept requests: %s", err)
return err
}

Expand All @@ -117,11 +117,11 @@ func ProcessBackupRequest(ctx context.Context, req *pb.BackupRequest, forceFull
backupLock.Lock()
defer backupLock.Unlock()

LastBackupStatus.Store(fmt.Sprintf("STARTED: %s", time.Now().Format(time.RFC3339)))
glog.Infof("Backup started: %s", req.Destination)
if err := doBackup(ctx, req, forceFull); err != nil {
LastBackupStatus.Store(fmt.Sprintf("ERROR: %s: %s", time.Now().Format(time.RFC3339), err))
glog.Errorf("Backup error: %s: %s", err, req.Destination)
} else {
LastBackupStatus.Store(fmt.Sprintf("COMPLETED: %s", time.Now().Format(time.RFC3339)))
glog.Infof("Backup complete: %s", req.Destination)
}
}()

Expand Down

0 comments on commit dd183aa

Please sign in to comment.