-
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.
fix(backup): handle manifest version logic, update manifest version t…
…o 2105 (#7825) The backward compatibility of the backup's manifest was broken by #7810, although the tool was added (#7815) that enables smooth migration of manifest. This PR makes backup backward compatible, by updating the manifest(in-memory) after reading.
- Loading branch information
1 parent
35ecaaa
commit 7f8ec2f
Showing
18 changed files
with
297 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// +build !oss | ||
|
||
/* | ||
* Copyright 2021 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 updatemanifest | ||
|
||
import ( | ||
"encoding/binary" | ||
"log" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"github.com/dgraph-io/dgraph/ee" | ||
"github.com/dgraph-io/dgraph/protos/pb" | ||
"github.com/dgraph-io/dgraph/worker" | ||
"github.com/dgraph-io/dgraph/x" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
logger = log.New(os.Stderr, "", 0) | ||
// UpdateManifest is the sub-command invoked when running "dgraph update_manifest". | ||
UpdateManifest x.SubCommand | ||
) | ||
|
||
var opt struct { | ||
location string | ||
key []byte | ||
} | ||
|
||
func init() { | ||
UpdateManifest.Cmd = &cobra.Command{ | ||
Use: "update_manifest", | ||
Short: "Run the Dgraph update tool to update the manifest from v21.03 to latest.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := run(); err != nil { | ||
logger.Fatalf("%v\n", err) | ||
} | ||
}, | ||
Annotations: map[string]string{"group": "tool"}, | ||
} | ||
UpdateManifest.EnvPrefix = "DGRAPH_UPDATE_MANIFEST" | ||
UpdateManifest.Cmd.SetHelpTemplate(x.NonRootTemplate) | ||
|
||
flag := UpdateManifest.Cmd.Flags() | ||
flag.StringVarP(&opt.location, "location", "l", "", | ||
`Sets the location of the backup. Both file URIs and s3 are supported. | ||
This command will take care of all the full + incremental backups present in the location.`) | ||
ee.RegisterEncFlag(flag) | ||
} | ||
|
||
// Invalid bytes are replaced with the Unicode replacement rune. | ||
// See https://golang.org/pkg/encoding/json/#Marshal | ||
const replacementRune = rune('\ufffd') | ||
|
||
func parseNsAttr(attr string) (uint64, string, error) { | ||
if strings.ContainsRune(attr, replacementRune) { | ||
return 0, "", errors.New("replacement char found") | ||
} | ||
return binary.BigEndian.Uint64([]byte(attr[:8])), attr[8:], nil | ||
} | ||
|
||
func run() error { | ||
keys, err := ee.GetKeys(UpdateManifest.Conf) | ||
if err != nil { | ||
return err | ||
} | ||
opt.key = keys.EncKey | ||
uri, err := url.Parse(opt.location) | ||
if err != nil { | ||
return errors.Wrapf(err, "while parsing location") | ||
} | ||
handler, err := worker.NewUriHandler(uri, nil) | ||
if err != nil { | ||
return errors.Wrapf(err, "while creating uri handler") | ||
} | ||
masterManifest, err := worker.GetManifestNoUpgrade(handler, uri) | ||
if err != nil { | ||
return errors.Wrapf(err, "while getting manifest") | ||
} | ||
|
||
update := func(manifest *worker.Manifest) { | ||
for gid, preds := range manifest.Groups { | ||
parsedPreds := preds[:0] | ||
for _, pred := range preds { | ||
ns, attr, err := parseNsAttr(pred) | ||
if err != nil { | ||
logger.Printf("Unable to parse the pred: %v", pred) | ||
continue | ||
} | ||
parsedPreds = append(parsedPreds, x.NamespaceAttr(ns, attr)) | ||
} | ||
manifest.Groups[gid] = parsedPreds | ||
} | ||
for _, op := range manifest.DropOperations { | ||
if op.DropOp == pb.DropOperation_ATTR { | ||
ns, attr, err := parseNsAttr(op.DropValue) | ||
if err != nil { | ||
logger.Printf("Unable to parse the drop operation %+v pred: %v", | ||
op, []byte(op.DropValue)) | ||
continue | ||
} | ||
op.DropValue = x.NamespaceAttr(ns, attr) | ||
} | ||
} | ||
} | ||
|
||
// Update the master manifest with the changes for drop operations and group predicates. | ||
for _, manifest := range masterManifest.Manifests { | ||
if manifest.Version == 2103 { | ||
update(manifest) | ||
} | ||
} | ||
|
||
// Rewrite the master manifest. | ||
return errors.Wrap(worker.CreateManifest(handler, uri, masterManifest), "rewrite failed") | ||
} |
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
Binary file added
BIN
+456 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095641.969/r9-g1.backup
Binary file not shown.
Binary file added
BIN
+154 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095641.969/r9-g2.backup
Binary file not shown.
Binary file added
BIN
+154 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095641.969/r9-g3.backup
Binary file not shown.
Binary file added
BIN
+641 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095716.130/r21-g1.backup
Binary file not shown.
Binary file added
BIN
+154 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095716.130/r21-g2.backup
Binary file not shown.
Binary file added
BIN
+154 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095716.130/r21-g3.backup
Binary file not shown.
Binary file added
BIN
+410 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095726.320/r26-g1.backup
Binary file not shown.
Binary file added
BIN
+154 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095726.320/r26-g2.backup
Binary file not shown.
Binary file added
BIN
+154 Bytes
systest/backup/filesystem/data/to_restore/3/dgraph.20210517.095726.320/r26-g3.backup
Binary file not shown.
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 @@ | ||
{"Manifests":[{"type":"full","since":0,"read_ts":9,"groups":{"1":["\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p1","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.p_query","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.xid","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.schema","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.drop.op","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.type","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p3","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p2"],"2":[],"3":[]},"backup_id":"quirky_kapitsa4","backup_num":1,"version":2103,"path":"dgraph.20210517.095641.969","encrypted":false,"drop_operations":null,"compression":"snappy"},{"type":"incremental","since":0,"read_ts":21,"groups":{"1":["\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.drop.op","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p1","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.schema","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.p_query","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p3","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.xid","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p4","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p2","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.type"],"2":[],"3":[]},"backup_id":"quirky_kapitsa4","backup_num":2,"version":2103,"path":"dgraph.20210517.095716.130","encrypted":false,"drop_operations":[{"drop_op":1}],"compression":"snappy"},{"type":"incremental","since":0,"read_ts":26,"groups":{"1":["\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p4","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p2","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.type","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p1","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.schema","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.p_query","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p3","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.drop.op","\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.xid"],"2":[],"3":[]},"backup_id":"quirky_kapitsa4","backup_num":3,"version":2103,"path":"dgraph.20210517.095726.320","encrypted":false,"drop_operations":[{"drop_op":2,"drop_value":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000p3"}],"compression":"snappy"}]} |
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
Oops, something went wrong.