Skip to content

Commit

Permalink
add internal predicate for string namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Jan 21, 2025
1 parent 053a440 commit 6d07a2c
Show file tree
Hide file tree
Showing 23 changed files with 305 additions and 200 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-dgraph-core-upgrade-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
#!/bin/bash
# go env settings
export GOPATH=~/go
export DGRAPH_UPGRADE_MAIN_ONLY=true
# move the binary
cp dgraph/dgraph ~/go/bin/dgraph
# run the core upgrade tests
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci-dgraph-system-upgrade-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
#!/bin/bash
# go env settings
export GOPATH=~/go
export DGRAPH_UPGRADE_MAIN_ONLY=true
# move the binary
cp dgraph/dgraph ~/go/bin/dgraph
# run the sytem upgrade tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
#!/bin/bash
# go env settings
export GOPATH=~/go
export DGRAPH_UPGRADE_MAIN_ONLY=false
# move the binary
cp dgraph/dgraph ~/go/bin/dgraph
# run the tests
Expand Down
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "trunk.io",
"editor.trimAutoWhitespace": true,
"trunk.autoInit": false
"trunk.autoInit": false,
"[go]": {
"editor.defaultFormatter": "golang.go"
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
}
6 changes: 3 additions & 3 deletions contrib/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ RUN rm -rf /var/lib/apt/lists/*

# only update, don't run upgrade
# use cache busting to avoid old versions
# remove /var/lib/apt/lists/* to reduce image size.
# see: https://docs.docker.com/develop/develop-images/dockerfile_best-practices
# remove /var/lib/apt/lists/* to reduce image size.
# see: https://docs.docker.com/develop/develop-images/dockerfile_best-practices
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
htop \
Expand All @@ -33,4 +33,4 @@ RUN mkdir /dgraph
WORKDIR /dgraph

ENV GODEBUG=madvdontneed=1
CMD ["dgraph"] # Shows the dgraph version and commands available.
CMD ["dgraph"]
8 changes: 5 additions & 3 deletions dgraphtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func AllUpgradeCombos(v20 bool) []UpgradeCombo {
mainCombos := []UpgradeCombo{
{"v23.1.0", localVersion, BackupRestore},
{"v23.1.0", localVersion, InPlace},
{"v24.0.0", localVersion, BackupRestore},
{"v24.0.0", localVersion, InPlace},
}

if v20 {
Expand All @@ -90,10 +92,10 @@ func AllUpgradeCombos(v20 bool) []UpgradeCombo {
}...)
}

if os.Getenv("DGRAPH_UPGRADE_MAIN_ONLY") == "true" {
return mainCombos
} else {
if os.Getenv("DGRAPH_UPGRADE_MAIN_ONLY") == "false" {
return fixedVersionCombos
} else {
return mainCombos
}
}

Expand Down
5 changes: 3 additions & 2 deletions dgraphtest/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func runGitClone() error {
// a copy of this folder by running git clone using this already cloned dgraph
// repo. After the quick clone, we update the original URL to point to the
// GitHub dgraph repo and perform a "git fetch".
log.Printf("[INFO] cloning dgraph repo from [%v]", baseRepoDir)
cmd := exec.Command("git", "clone", baseRepoDir, repoDir)
if out, err := cmd.CombinedOutput(); err != nil {
return errors.Wrapf(err, "error cloning dgraph repo\noutput:%v", string(out))
Expand Down Expand Up @@ -224,8 +225,8 @@ func IsHigherVersion(higher, lower string) (bool, error) {
cmd := exec.Command("git", "merge-base", "--is-ancestor", lower, higher)
cmd.Dir = repoDir
if out, err := cmd.CombinedOutput(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
return exitError.ExitCode() == 0, nil
if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 1 {
return false, nil
}

return false, errors.Wrapf(err, "error checking if [%v] is ancestor of [%v]\noutput:%v",
Expand Down
2 changes: 1 addition & 1 deletion edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ func validateAndConvertFacets(nquads []*api.NQuad) error {
// validateForGraphql validate nquads for graphql
func validateForGraphql(nq *api.NQuad, isGraphql bool) error {
// Check whether the incoming predicate is graphql reserved predicate or not.
if !isGraphql && x.IsGraphqlReservedPredicate(nq.Predicate) {
if !isGraphql && x.IsOtherReservedPredicate(nq.Predicate) {
return errors.Errorf("Cannot mutate graphql reserved predicate %s", nq.Predicate)
}
return nil
Expand Down
179 changes: 173 additions & 6 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const (
}`

// This is the groot schema after adding @unique directive to the dgraph.xid predicate
newGrootSchema = `{
uniqueXidGrootSchema = `{
"schema": [
{
"predicate": "dgraph.acl.rule",
Expand Down Expand Up @@ -301,6 +301,169 @@ const (
"name": "dgraph.type.User"
}
]
}`

grootSchemaWithNamespaceSchema = `{
"schema": [
{
"predicate": "dgraph.acl.rule",
"type": "uid",
"list": true
},
{
"predicate":"dgraph.drop.op",
"type":"string"
},
{
"predicate":"dgraph.graphql.p_query",
"type":"string",
"index":true,
"tokenizer":["sha256"]
},
{
"predicate": "dgraph.graphql.schema",
"type": "string"
},
{
"predicate": "dgraph.graphql.xid",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"upsert": true
},
{
"predicate": "dgraph.namespace.id",
"type": "int",
"index": true,
"tokenizer": [
"int"
],
"upsert": true,
"unique": true
},
{
"predicate": "dgraph.namespace.name",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"upsert": true,
"unique": true
},
{
"predicate": "dgraph.password",
"type": "password"
},
{
"predicate": "dgraph.rule.permission",
"type": "int"
},
{
"predicate": "dgraph.rule.predicate",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"upsert": true
},
{
"predicate": "dgraph.type",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"list": true
},
{
"predicate": "dgraph.user.group",
"type": "uid",
"reverse": true,
"list": true
},
{
"predicate": "dgraph.xid",
"type": "string",
"index": true,
"tokenizer": [
"exact"
],
"upsert": true,
"unique": true
}
],
"types": [
{
"fields": [
{
"name": "dgraph.graphql.schema"
},
{
"name": "dgraph.graphql.xid"
}
],
"name": "dgraph.graphql"
},
{
"fields": [
{
"name": "dgraph.graphql.p_query"
}
],
"name": "dgraph.graphql.persisted_query"
},
{
"fields": [
{
"name": "dgraph.namespace.name"
},
{
"name": "dgraph.namespace.id"
}
],
"name": "dgraph.namespace"
},
{
"fields": [
{
"name": "dgraph.xid"
},
{
"name": "dgraph.acl.rule"
}
],
"name": "dgraph.type.Group"
},
{
"fields": [
{
"name": "dgraph.rule.predicate"
},
{
"name": "dgraph.rule.permission"
}
],
"name": "dgraph.type.Rule"
},
{
"fields": [
{
"name": "dgraph.xid"
},
{
"name": "dgraph.password"
},
{
"name": "dgraph.user.group"
}
],
"name": "dgraph.type.User"
}
]
}`
)

Expand Down Expand Up @@ -567,12 +730,12 @@ var (
func alterPreDefinedPredicates(t *testing.T, dg *dgo.Dgraph, clusterVersion string) {
ctx := context.Background()

// Commit daa5805739ed258e913a157c6e0f126b2291b1b0 represents the latest update to the main branch.
// Commit 532df27a09ba25f88687bab344e3add2b81b5c23 represents the latest update to the main branch.
// In this commit, the @unique directive is not applied to ACL predicates.
// Therefore, we are now deciding which schema to test.
// 'newGrootSchema' refers to the default schema with the @unique directive defined on ACL predicates.
// 'oldGrootSchema' refers to the default schema without the @unique directive on ACL predicates.
supported, err := dgraphtest.IsHigherVersion(clusterVersion, "daa5805739ed258e913a157c6e0f126b2291b1b0")
supported, err := dgraphtest.IsHigherVersion(clusterVersion, "532df27a09ba25f88687bab344e3add2b81b5c23")
require.NoError(t, err)
if supported {
require.NoError(t, dg.Alter(ctx, &api.Operation{
Expand Down Expand Up @@ -2254,10 +2417,14 @@ func (asuite *AclTestSuite) TestSchemaQueryWithACL() {
require.NoError(t, gc.DropAll())
resp, err := gc.Query(schemaQuery)
require.NoError(t, err)
supported, err := dgraphtest.IsHigherVersion(asuite.dc.GetVersion(), "daa5805739ed258e913a157c6e0f126b2291b1b0")
uniqueSchemaSupported, err := dgraphtest.IsHigherVersion(asuite.dc.GetVersion(), "532df27a09ba25f88687bab344e3add2b81b5c23")
require.NoError(t, err)
if supported {
require.JSONEq(t, newGrootSchema, string(resp.GetJson()))
nsSchemaSupported, err := dgraphtest.IsHigherVersion(asuite.dc.GetVersion(), "053a44054dc665f573ee7b92136b551a7b70c37c")
require.NoError(t, err)
if nsSchemaSupported {
require.JSONEq(t, grootSchemaWithNamespaceSchema, string(resp.GetJson()))
} else if uniqueSchemaSupported {
require.JSONEq(t, uniqueXidGrootSchema, string(resp.GetJson()))
} else {
require.JSONEq(t, oldGrootSchema, string(resp.GetJson()))
}
Expand Down
2 changes: 1 addition & 1 deletion ee/acl/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (asuite *AclTestSuite) Upgrade() {
}

func TestACLSuite(t *testing.T) {
for _, uc := range dgraphtest.AllUpgradeCombos(true) {
for _, uc := range dgraphtest.AllUpgradeCombos(false) {
log.Printf("running upgrade tests for config: %+v", uc)
aclSuite := AclTestSuite{uc: uc}
suite.Run(t, &aclSuite)
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/philhofer/fwd v1.0.0 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
Expand All @@ -147,7 +146,6 @@ require (
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tinylib/msgp v1.1.2 // indirect
github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect
Expand Down
Loading

0 comments on commit 6d07a2c

Please sign in to comment.