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

1.1.0-rc3 @count index on reverse edge fails after exporting/importing database #3893

Closed
mehdiym opened this issue Sep 1, 2019 · 3 comments · Fixed by #3932
Closed

1.1.0-rc3 @count index on reverse edge fails after exporting/importing database #3893

mehdiym opened this issue Sep 1, 2019 · 3 comments · Fixed by #3932
Assignees
Labels
area/import-export Issues related to data import and export. kind/bug Something is broken. status/accepted We accept to investigate/work on it.

Comments

@mehdiym
Copy link

mehdiym commented Sep 1, 2019

  • What version of Dgraph are you using?
    1.1.6-rc3

  • What is the hardware spec (RAM, OS)?
    Linux debian stable 16Go DDR

  • Steps to reproduce the issue (command/config used to run Dgraph).

  1. Export database user "/admin/export" endpoints
  2. Live import database
  3. Query some nodes matching a specific count on reverse edges
  • Expected behaviour and actual result.
    Expected: Get only nodes with the requested count of reverse edges
    Actual: Get any count

Using an old dgraph export doesn't produces the bug.
I will give @danielmai on slack the problematic export file.

@mehdiym
Copy link
Author

mehdiym commented Sep 1, 2019

I compared the valid and the invalid exports, and they are identical, except for the order of n-quads.
Comparing them with cat g01.rdf | sort > dump shows no difference.
It seems order is important, and 1.1.0-rc3 generates an order that creates index issues.

@campoy campoy assigned campoy and mangalaman93 and unassigned campoy Sep 3, 2019
@campoy campoy added area/import-export Issues related to data import and export. kind/bug Something is broken. status/accepted We accept to investigate/work on it. labels Sep 3, 2019
@hackintoshrao
Copy link
Contributor

Would be nice to have automated tests around export and import.

@pawanrawal
Copy link
Contributor

I had a look at this on request by @animesh2049. Here is a small program which reproduces the problem.

package main

import (
	"context"
	"log"
	"sync"

	"github.com/dgraph-io/dgo/v2"
	"github.com/dgraph-io/dgo/v2/protos/api"
	"google.golang.org/grpc"
)

func addFriend(dg *dgo.Dgraph, sourceId string, wg *sync.WaitGroup) {
	defer wg.Done()
	mu := &api.Mutation{
		CommitNow: true,
	}
	mu.SetJson = []byte(`{"uid": "_:b", "friend": [{"uid": "` + sourceId + `"}]}`)
	assigned, err := dg.NewTxn().Mutate(context.Background(), mu)
	if err != nil {
		log.Fatal(err)
	}
	if len(assigned.Uids) != 1 {
		log.Fatal("expected one uid, got none")
	}
}

func main() {
	conn, err := grpc.Dial("127.0.0.1:9180", grpc.WithInsecure())
	if err != nil {
		log.Fatal("While trying to dial gRPC")
	}
	defer conn.Close()

	dc := api.NewDgraphClient(conn)
	dg := dgo.NewDgraphClient(dc)

	op := &api.Operation{}
	op.Schema = `friend: [uid] @count @reverse .`

	ctx := context.Background()
	err = dg.Alter(ctx, op)
	if err != nil {
		log.Fatal(err)
	}

	mu := &api.Mutation{
		CommitNow: true,
	}
	mu.SetJson = []byte(`{"name": "Alice"}`)
	assigned, err := dg.NewTxn().Mutate(ctx, mu)
	if err != nil {
		log.Fatal(err)
	}

	first := ""
	for _, uid := range assigned.Uids {
		first = uid
		break
	}

	numRoutines := 10
	var wg sync.WaitGroup
	wg.Add(numRoutines)
	for i := 0; i < numRoutines; i++ {
		go addFriend(dg, first, &wg)
	}
	wg.Wait()
}

After running this program, the following query should return results but it doesn't.

{
  me(func: eq(count(~friend), 10))  {
    uid
    name
    count(~friend)
  }
}

Instead, this query returns a result.

{
  me(func: eq(count(~friend), 1))  {
    uid
    name
    count(~friend)
  }
}

The root cause of this issue is that reverse count index keys are not added to the conflict keys for a transaction. So concurrent updates go through fine although some of them should have aborted. I'll submit a fix for it.

pawanrawal added a commit that referenced this issue Sep 6, 2019
…ons. (#3932)

This change fixes #3893. Earlier reverse count index keys where not being considered for conflict detection which would lead to inconsistent reverse count key posting lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/import-export Issues related to data import and export. kind/bug Something is broken. status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

6 participants