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 the upgrade tool for CORS (depreciated predicates) change #7486

Merged
merged 23 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5d6ab46
s3 handler for export backup
aman-bansal Feb 18, 2021
bd364b8
fixing leaks and bugs with export
aman-bansal Feb 18, 2021
18a62c5
fixing s3 restore
aman-bansal Feb 19, 2021
1b5cb7f
fixing export input option
aman-bansal Feb 19, 2021
92528db
adding cors to the schema
aman-bansal Feb 19, 2021
34e5277
fixing cors export
aman-bansal Feb 22, 2021
eb158cf
finalizing contract and everything
aman-bansal Feb 22, 2021
e7a0eaa
removing redundant
aman-bansal Feb 22, 2021
1b69747
adding comments to simplify
aman-bansal Feb 22, 2021
ff7bf34
refactoring export code a bit
aman-bansal Feb 23, 2021
894771d
making file handler, s3 handler refactor + export backup to work cons…
aman-bansal Feb 23, 2021
5bef5ab
fix the cors issue in backup backward compatibility
NamanJain8 Feb 25, 2021
08cfa22
address comments
NamanJain8 Mar 2, 2021
ea0e9cd
Merge branch 'master' into naman/export-backup
NamanJain8 Mar 2, 2021
2a7ed62
Merge branch 'master' into naman/export-backup
NamanJain8 Mar 3, 2021
5e3d2e5
basic working
NamanJain8 Mar 4, 2021
1a1827e
add support for TLS and slash in upgrade tool
NamanJain8 Mar 10, 2021
95d964d
fix export_backup tool for fixing cors
NamanJain8 Mar 14, 2021
29bc90d
Merge branch 'master' into naman/export-backup
NamanJain8 Mar 15, 2021
a909a27
clean up
NamanJain8 Mar 15, 2021
72b1887
Merge branch 'naman/export-backup' of github.com:dgraph-io/dgraph int…
NamanJain8 Mar 15, 2021
f92d558
add persistent query fix
NamanJain8 Mar 16, 2021
813d0aa
address comments
NamanJain8 Mar 17, 2021
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
29 changes: 27 additions & 2 deletions ee/backup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"golang.org/x/sync/errgroup"

"github.com/dgraph-io/badger/v3"
"github.com/dgraph-io/badger/v3/options"
"golang.org/x/sync/errgroup"

"google.golang.org/grpc/credentials"

"github.com/dgraph-io/dgraph/ee"
"github.com/dgraph-io/dgraph/ee/enc"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/upgrade"
"github.com/dgraph-io/dgraph/worker"
"github.com/dgraph-io/dgraph/x"
"github.com/dgraph-io/ristretto/z"
Expand Down Expand Up @@ -59,6 +61,7 @@ var opt struct {
destination string
format string
verbose bool
upgrade bool // used by export backup command.
}

func init() {
Expand Down Expand Up @@ -324,6 +327,7 @@ func initExportBackup() {
Annotations: map[string]string{"group": "tool"},
}

ExportBackup.Cmd.SetHelpTemplate(x.NonRootTemplate)
flag := ExportBackup.Cmd.Flags()
flag.StringVarP(&opt.location, "location", "l", "",
`Sets the location of the backup. Both file URIs and s3 are supported.
Expand All @@ -332,6 +336,10 @@ func initExportBackup() {
"The folder to which export the backups.")
flag.StringVarP(&opt.format, "format", "f", "rdf",
"The format of the export output. Accepts a value of either rdf or json")
flag.BoolVar(&opt.upgrade, "upgrade", false,
`If true, retrieve the CORS from DB and append at the end of GraphQL schema.
It also deletes the deprecated types and predicates.
Use this option when exporting a backup of 20.11 for loading onto 21.03.`)
enc.RegisterFlags(flag)
}

Expand Down Expand Up @@ -376,6 +384,23 @@ func runExportBackup() error {
"inside DB at %s: %v", dir, err)
continue
}
if opt.upgrade && gid == 1 {
// Query the cors in badger db and append it at the end of GraphQL schema.
// This change was introduced in v21.03. Backups with 20.07 <= version < 21.03
// should apply this.
db, err := badger.OpenManaged(badger.DefaultOptions(dir).
WithNumVersionsToKeep(math.MaxInt32).
WithEncryptionKey(opt.key))
if err != nil {
return err
}
if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {
return errors.Wrapf(err, "while fixing cors")
}
if err := db.Close(); err != nil {
return err
}
}
eg.Go(func() error {
return worker.StoreExport(&pb.ExportRequest{
GroupId: uint32(gid),
Expand Down
23 changes: 23 additions & 0 deletions upgrade/change_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,28 @@ func init() {
// can't handle every scenario. So, it is best to let the user do it.
},
},
{
introducedIn: &version{major: 21, minor: 3, patch: 0},
changes: []*change{
{
name: "Upgrade Persistent Query",
description: "This updates the persisted query from old format to new format." +
"Persistent query had 2 predicates which have been merged into a single " +
"predicate dgraph.graphql.p_query. " +
"For more info, see: https://github.com/dgraph-io/dgraph/pull/7451",
minFromVersion: &version{major: 20, minor: 11, patch: 0},
applyFunc: upgradePersitentQuery,
},
{
name: "Upgrade CORS",
description: "This updates GraphQL schema to contain the CORS information. " +
"Some of the dgraph internal predicates are removed in v21.03.0. " +
"dgraph.cors that used to store CORS information is one of them. " +
"For more info, see: https://github.com/dgraph-io/dgraph/pull/7431",
minFromVersion: &version{major: 20, minor: 11, patch: 0},
applyFunc: upgradeCORS,
},
},
},
}
}
12 changes: 5 additions & 7 deletions upgrade/change_v20.03.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

"github.com/dgraph-io/dgo/v200/protos/api"
"github.com/dgraph-io/dgraph/x"
)

const (
Expand All @@ -47,14 +48,11 @@ type rule struct {
type rules []rule

func upgradeACLRules() error {
dg, conn, err := getDgoClient(true)
if err != nil {
return fmt.Errorf("error getting dgo client: %w", err)
}
defer conn.Close()
dg, cb := x.GetDgraphClient(Upgrade.Conf, true)
defer cb()

data := make(map[string][]group)
if err = getQueryResult(dg, queryACLGroupsBefore_v20_03_0, &data); err != nil {
if err := getQueryResult(dg, queryACLGroupsBefore_v20_03_0, &data); err != nil {
return fmt.Errorf("error querying old ACL rules: %w", err)
}

Expand Down Expand Up @@ -118,7 +116,7 @@ func upgradeACLRules() error {

deleteOld := Upgrade.Conf.GetBool("deleteOld")
if deleteOld {
err = alterWithClient(dg, &api.Operation{
err := alterWithClient(dg, &api.Operation{
DropOp: api.Operation_ATTR,
DropValue: "dgraph.group.acl",
})
Expand Down
12 changes: 5 additions & 7 deletions upgrade/change_v20.07.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/dgraph-io/dgo/v200"
"github.com/dgraph-io/dgo/v200/protos/api"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/x"
)

const (
Expand Down Expand Up @@ -128,19 +129,16 @@ func upgradeAclTypeNames() error {
}

// get dgo client
dg, conn, err := getDgoClient(true)
if err != nil {
return fmt.Errorf("error getting dgo client: %w", err)
}
defer conn.Close()
dg, cb := x.GetDgraphClient(Upgrade.Conf, true)
defer cb()

// apply upgrades for old ACL type names, one by one.
for _, typeNameInfo := range aclTypeNameInfo {
if err = typeNameInfo.updateTypeName(dg); err != nil {
if err := typeNameInfo.updateTypeName(dg); err != nil {
return fmt.Errorf("error upgrading ACL type name from `%s` to `%s`: %w",
typeNameInfo.oldTypeName, typeNameInfo.newTypeName, err)
}
if err = typeNameInfo.updateTypeSchema(dg); err != nil {
if err := typeNameInfo.updateTypeSchema(dg); err != nil {
return fmt.Errorf("error upgrading schema for old ACL type `%s`: %w",
typeNameInfo.oldTypeName, err)
}
Expand Down
Loading