Skip to content

Inconsistent query results between instances #1750

@emersonwood

Description

@emersonwood

OS: Ubuntu 16.04.3 LTS
Go: go version go1.9.1 linux/amd64
Dgraph: 9830b79
Go GRPC: v1.7.2

Hey there,

I've got a basic program (pasted at the bottom) that ingests 3 quads and then queries 3 quads, checking the output data against expected data.

The checks pass if the ingest and query both run in the same instance of the program, which is expected.

The checks fail if the ingest and query are run in seperate instances of the program; ie:

  1. Comment out query code
  2. Run program (only ingests)
  3. Program finishes

then

  1. Comment out schema and ingest code
  2. Run program (only queries)
  3. Program finishes

The first node is always returned, but the other two nodes aren't if the ingest and query are run separately.

I can't think of any reason why the results would be different considering that the client is being recreated between the ingest and query.

Any help would be greatly appreciated.

main.go

package main

import (
	"bytes"
	"context"
	"fmt"
	"log"

	"github.com/dgraph-io/dgraph/client"
	"github.com/dgraph-io/dgraph/protos"
	"github.com/dgraph-io/dgraph/x"
	"google.golang.org/grpc"
)

const targetAddr = "localhost:9080"

func main() {

	// Setup dgraph client
	ctx := context.Background()
	conn, err := grpc.Dial(targetAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatal(err)
	}
	pc := protos.NewDgraphClient(conn)
	c := client.NewDgraphClient(pc)

	// Set schema
	op := &protos.Operation{}
	op.Schema = `name: string @index(fulltext) .`
	x.Check(c.Alter(ctx, op))

	// Ingest
	TestInsert3Quads(ctx, c)
	conn.Close()

	// Refresh client
	conn.Close()
	ctx = context.Background()
	conn, err = grpc.Dial(targetAddr, grpc.WithInsecure())
	if err != nil {
		log.Fatal(err)
	}
	pc = protos.NewDgraphClient(conn)
	c = client.NewDgraphClient(pc)

	// Query
	TestQuery3Quads(ctx, c)
	conn.Close()
}

func TestInsert3Quads(ctx context.Context, c *client.Dgraph) {
	txn := c.NewTxn()

	mu := &protos.Mutation{}
	quad := &protos.NQuad{
		Subject:     "200",
		Predicate:   "name",
		ObjectValue: &protos.Value{&protos.Value_StrVal{"ok 200"}},
	}
	mu.Set = []*protos.NQuad{quad}
	_, err := txn.Mutate(ctx, mu)
	if err != nil {
		log.Fatalf("Error while running mutation: %v\n", err)
	}

	mu = &protos.Mutation{}
	quad = &protos.NQuad{
		Subject:     "300",
		Predicate:   "name",
		ObjectValue: &protos.Value{&protos.Value_StrVal{"ok 300"}},
	}
	mu.Set = []*protos.NQuad{quad}
	_, err = txn.Mutate(ctx, mu)
	if err != nil {
		log.Fatalf("Error while running mutation: %v\n", err)
	}

	mu = &protos.Mutation{}
	quad = &protos.NQuad{
		Subject:     "400",
		Predicate:   "name",
		ObjectValue: &protos.Value{&protos.Value_StrVal{"ok 400"}},
	}
	mu.Set = []*protos.NQuad{quad}
	_, err = txn.Mutate(ctx, mu)
	if err != nil {
		log.Fatalf("Error while running mutation: %v\n", err)
	}

	x.Check(txn.Commit(ctx))
}

func TestQuery3Quads(ctx context.Context, c *client.Dgraph) {
	txn := c.NewTxn()
	q := fmt.Sprint(`{ me(func: uid(200, 300, 400)) { name }}`)
	resp, err := txn.Query(ctx, q)
	if err != nil {
		log.Fatalf("Error while running query: %v\n", err)
	}
	fmt.Printf("Response JSON: %q\n", resp.Json)
	x.AssertTrue(bytes.Equal(resp.Json, []byte("{\"me\":[{\"name\":\"ok 200\"},{\"name\":\"ok 300\"},{\"name\":\"ok 400\"}]}")))
	x.AssertTrue(resp.Txn.StartTs > 0)
	x.Check(txn.Commit(ctx))
}
`

Metadata

Metadata

Assignees

Labels

kind/bugSomething is broken.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions