Skip to content

Commit

Permalink
x add internal predicate for string namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Jan 30, 2025
1 parent 8b54856 commit 8f51505
Show file tree
Hide file tree
Showing 28 changed files with 543 additions and 592 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci-dgraph-core-upgrade-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ 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
go test -tags=upgrade \
github.com/hypermodeinc/dgraph/v24/ee/acl \
github.com/hypermodeinc/dgraph/v24/worker \
github.com/hypermodeinc/dgraph/v24/query \
-v -timeout=120m -failfast
go test -v -timeout=120m -failfast -tags=upgrade \
github.com/hypermodeinc/dgraph/v24/ee/acl \
github.com/hypermodeinc/dgraph/v24/worker \
github.com/hypermodeinc/dgraph/v24/query
# clean up docker containers after test execution
go clean -testcache
# sleep
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-dgraph-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
#!/bin/bash
# go env settings
export GOPATH=~/go
go test ./dql -fuzz="Fuzz" -fuzztime="300s" -fuzzminimizetime="120s"
go test -v ./dql -fuzz="Fuzz" -fuzztime="300s" -fuzzminimizetime="120s"
2 changes: 1 addition & 1 deletion .github/workflows/ci-dgraph-oss-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
# move the binary
cp dgraph/dgraph ~/go/bin/dgraph
# run OSS unit tests
go test -timeout=60m -failfast -tags=oss -count=1 ./...
go test -v -timeout=60m -failfast -tags=oss -count=1 ./...
11 changes: 5 additions & 6 deletions .github/workflows/ci-dgraph-system-upgrade-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ 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
go test -tags=upgrade github.com/hypermodeinc/dgraph/v24/systest/mutations-and-queries \
github.com/hypermodeinc/dgraph/v24/systest/plugin \
github.com/hypermodeinc/dgraph/v24/systest/license \
github.com/hypermodeinc/dgraph/v24/systest/multi-tenancy \
-v -timeout=120m -failfast
go test -v -timeout=120m -failfast -tags=upgrade \
github.com/hypermodeinc/dgraph/v24/systest/mutations-and-queries \
github.com/hypermodeinc/dgraph/v24/systest/plugin \
github.com/hypermodeinc/dgraph/v24/systest/license \
github.com/hypermodeinc/dgraph/v24/systest/multi-tenancy
# clean up docker containers after test execution
go clean -testcache
# sleep
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
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"]
10 changes: 5 additions & 5 deletions dgraphtest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func AllUpgradeCombos(v20 bool) []UpgradeCombo {
// In mainCombos list, we keep latest version to current HEAD as well as
// older versions of dgraph to ensure that a change does not cause failures.
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 +90,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
3 changes: 1 addition & 2 deletions dgraphtest/dgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,12 @@ func mountBinary(c *LocalCluster) (mount.Mount, error) {
}

// ShouldSkipTest skips a given test if clusterVersion < minVersion
func ShouldSkipTest(t *testing.T, minVersion, clusterVersion string) error {
func ShouldSkipTest(t *testing.T, minVersion, clusterVersion string) {
supported, err := IsHigherVersion(clusterVersion, minVersion)
if err != nil {
t.Fatal(err)
}
if !supported {
t.Skipf("test is valid for commits greater than [%v]", minVersion)
}
return nil
}
12 changes: 3 additions & 9 deletions dgraphtest/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ func ensureDgraphClone() error {
}
return runGitClone()
}

// we do not return error if git fetch fails because maybe there are no changes
// to pull and it doesn't make sense to fail right now. We can fail later when we
// do not find the reference that we are looking for.
if err := runGitFetch(); err != nil {
log.Printf("[WARNING] error in fetching latest git changes: %v", err)
}
return nil
}

Expand All @@ -92,6 +85,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 @@ -256,8 +250,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
185 changes: 178 additions & 7 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 @@ -2087,7 +2250,7 @@ func (asuite *AclTestSuite) TestQueryUserInfo() {

func (asuite *AclTestSuite) TestQueriesWithUserAndGroupOfSameName() {
t := asuite.T()
dgraphtest.ShouldSkipTest(t, asuite.dc.GetVersion(), "7b1f473ddf01547e24b44f580a68e6b049502d69")
dgraphtest.ShouldSkipTest(t, asuite.dc.GetVersion(), "532df27a09ba25f88687bab344e3add2b81b5c23")
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
defer cancel()

Expand Down Expand Up @@ -2225,6 +2388,10 @@ func (asuite *AclTestSuite) TestSchemaQueryWithACL() {
"fields":[],
"name":"dgraph.graphql.persisted_query"
},
{
"fields": [],
"name": "dgraph.namespace"
},
{
"fields": [],
"name": "dgraph.type.Group"
Expand Down Expand Up @@ -2254,10 +2421,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
Loading

0 comments on commit 8f51505

Please sign in to comment.