-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix(enterprise): Set version correctly post marshalling during restore #7018
Changes from 5 commits
3dc892c
30dbe32
994984d
4172438
387fb20
44a1482
314ac55
ba4ba82
6232050
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,19 +40,87 @@ import ( | |
) | ||
|
||
var ( | ||
copyBackupDir = "./data/backups_copy" | ||
restoreDir = "./data/restore" | ||
testDirs = []string{restoreDir} | ||
|
||
alphaBackupDir = "/data/backups" | ||
|
||
copyBackupDir = "./data/backups_copy" | ||
restoreDir = "./data/restore" | ||
testDirs = []string{restoreDir, exporterDir} | ||
exporterDir = "data/exporter" | ||
alphaBackupDir = "/data/backups" | ||
oldBackupDir = "/data/to_restore" | ||
alphaContainers = []string{ | ||
"alpha1", | ||
"alpha2", | ||
"alpha3", | ||
} | ||
) | ||
|
||
func sendRestoreRequest(t *testing.T, location string) int { | ||
if location == "" { | ||
location = "/data/backup" | ||
} | ||
params := testutil.GraphQLParams{ | ||
Query: `mutation restore($location: String!) { | ||
restore(input: {location: $location}) { | ||
code | ||
message | ||
restoreId | ||
} | ||
}`, | ||
Variables: map[string]interface{}{ | ||
"location": location, | ||
}, | ||
} | ||
resp := testutil.MakeGQLRequest(t, ¶ms) | ||
resp.RequireNoGraphQLErrors(t) | ||
|
||
var restoreResp struct { | ||
Restore struct { | ||
Code string | ||
Message string | ||
RestoreId int | ||
} | ||
} | ||
|
||
require.NoError(t, json.Unmarshal(resp.Data, &restoreResp)) | ||
require.Equal(t, restoreResp.Restore.Code, "Success") | ||
require.Greater(t, restoreResp.Restore.RestoreId, 0) | ||
return restoreResp.Restore.RestoreId | ||
} | ||
|
||
// This test takes a backup and then restores an old backup in a cluster incrementally. | ||
// Next, cleans up the cluster and tries restoring the backups above. | ||
func TestBackupOfOldRestore(t *testing.T) { | ||
rahulgurnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dirSetup(t) | ||
copyOldBackupDir(t) | ||
|
||
dg, err := testutil.DgraphClient(testutil.SockAddr) | ||
x.Check(err) | ||
rahulgurnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx := context.Background() | ||
|
||
require.NoError(t, dg.Alter(ctx, &api.Operation{DropAll: true})) | ||
rahulgurnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
time.Sleep(2 * time.Second) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please confirm that these sleeps are good enough by running the tests multiple times. Otherwise these can be flaky. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Ran it 10 times locally. |
||
|
||
_ = runBackup(t, 3, 1) | ||
|
||
_ = sendRestoreRequest(t, oldBackupDir) | ||
time.Sleep(3 * time.Second) | ||
|
||
resp, err := dg.NewTxn().Query(context.Background(), `{ authors(func: has(Author.name)) { count(uid) } }`) | ||
x.Check(err) | ||
rahulgurnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.JSONEq(t, "{\"authors\":[{\"count\":1}]}", string(resp.Json)) | ||
|
||
_ = runBackup(t, 6, 2) | ||
|
||
// Clean the cluster and try restoring the backups created above. | ||
require.NoError(t, dg.Alter(ctx, &api.Operation{DropAll: true})) | ||
time.Sleep(2 * time.Second) | ||
_ = sendRestoreRequest(t, alphaBackupDir) | ||
time.Sleep(3 * time.Second) | ||
|
||
resp, err = dg.NewTxn().Query(context.Background(), `{ authors(func: has(Author.name)) { count(uid) } }`) | ||
x.Check(err) | ||
rahulgurnani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.JSONEq(t, "{\"authors\":[{\"count\":1}]}", string(resp.Json)) | ||
} | ||
|
||
func TestBackupFilesystem(t *testing.T) { | ||
conn, err := grpc.Dial(testutil.SockAddr, grpc.WithInsecure()) | ||
require.NoError(t, err) | ||
|
@@ -330,7 +398,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, | |
copyToLocalFs(t) | ||
|
||
files := x.WalkPathFunc(copyBackupDir, func(path string, isdir bool) bool { | ||
return !isdir && strings.HasSuffix(path, ".backup") | ||
return !isdir && strings.HasSuffix(path, ".backup") && strings.HasPrefix(path, "data/backups_copy/dgraph.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would not help because copyBackupDir = ./data/backups_copy |
||
}) | ||
require.Equal(t, numExpectedFiles, len(files)) | ||
|
||
|
@@ -340,7 +408,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, | |
require.Equal(t, numExpectedDirs, len(dirs)) | ||
|
||
manifests := x.WalkPathFunc(copyBackupDir, func(path string, isdir bool) bool { | ||
return !isdir && strings.Contains(path, "manifest.json") | ||
return !isdir && strings.Contains(path, "manifest.json") && strings.HasPrefix(path, "data/backups_copy/dgraph.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
}) | ||
require.Equal(t, numExpectedDirs, len(manifests)) | ||
|
||
|
@@ -403,6 +471,9 @@ func dirCleanup(t *testing.T) { | |
if err := os.RemoveAll(restoreDir); err != nil { | ||
t.Fatalf("Error removing directory: %s", err.Error()) | ||
} | ||
if err := os.RemoveAll(exporterDir); err != nil { | ||
t.Fatalf("Error removing directory: %s", err.Error()) | ||
} | ||
if err := os.RemoveAll(copyBackupDir); err != nil { | ||
t.Fatalf("Error removing directory: %s", err.Error()) | ||
} | ||
|
@@ -413,6 +484,14 @@ func dirCleanup(t *testing.T) { | |
} | ||
} | ||
|
||
func copyOldBackupDir(t *testing.T) { | ||
destPath := testutil.DockerPrefix + "_alpha1_1:/data" | ||
srchPath := "." + oldBackupDir | ||
if err := testutil.DockerCp(srchPath, destPath); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. require.NoError please |
||
t.Fatalf("Error copying files from docker container: %s", err.Error()) | ||
} | ||
} | ||
|
||
func copyToLocalFs(t *testing.T) { | ||
// The original backup files are not accessible because docker creates all files in | ||
// the shared volume as the root user. This restriction is circumvented by using | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see exporterDir being used anywhere. Why do we have it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, cleaned it up