Skip to content

Commit

Permalink
Add drop_data field to api to drop data except schema and types. (#53)
Browse files Browse the repository at this point in the history
This change adds API support for a new operation called drop_data which
will drop all the data but not the schema nor the types. This is useful
when the schema will be resued after dropping the data and the schema is
large enough that recreating it might take more than a couple seconds.
  • Loading branch information
martinmr authored Apr 17, 2019
1 parent 95299da commit 087e431
Show file tree
Hide file tree
Showing 3 changed files with 630 additions and 326 deletions.
32 changes: 21 additions & 11 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"log"
"strings"
"time"

"github.com/dgraph-io/dgo"
Expand All @@ -37,7 +38,22 @@ func getDgraphClient() (*dgo.Dgraph, CancelFunc) {
}

dc := api.NewDgraphClient(conn)
return dgo.NewDgraphClient(dc), func() {
dg := dgo.NewDgraphClient(dc)
ctx := context.Background()

for {
// keep retrying until we succeed or receive a non-retriable error
err = dg.Login(ctx, "groot", "password")
if err == nil || !strings.Contains(err.Error(), "Please retry") {
break
}
time.Sleep(time.Second)
}
if err != nil {
log.Fatalf("While trying to login %v", err.Error())
}

return dg, func() {
if err := conn.Close(); err != nil {
log.Printf("Error while closing connection:%v", err)
}
Expand All @@ -47,9 +63,7 @@ func getDgraphClient() (*dgo.Dgraph, CancelFunc) {
func ExampleDgraph_Alter_dropAll() {
dg, cancel := getDgraphClient()
defer cancel()
op := api.Operation{
DropAll: true,
}
op := api.Operation{DropAll: true}
ctx := context.Background()
if err := dg.Alter(ctx, &op); err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -450,9 +464,7 @@ func ExampleTxn_Mutate_facets() {
defer cancel()
// Doing a dropAll isn't required by the user. We do it here so that we can verify that the
// example runs as expected.
op := api.Operation{
DropAll: true,
}
op := api.Operation{DropAll: true}
ctx := context.Background()
if err := dg.Alter(ctx, &op); err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -957,15 +969,13 @@ func ExampleTxn_Mutate_deletePredicate() {
log.Fatal(err)
}

op = &api.Operation{
DropAttr: "friend",
}
op = &api.Operation{DropAttr: "friend"}
err = dg.Alter(ctx, op)
if err != nil {
log.Fatal(err)
}

op.DropAttr = "married"
op = &api.Operation{DropAttr: "married"}
err = dg.Alter(ctx, op)
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 7 additions & 1 deletion protos/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ message Mutation {
bool ignore_index_conflict = 15; // this field is not parsed and used by the server anymore.
}


message Operation {
string schema = 1;
string drop_attr = 2;
bool drop_all = 3;

enum DropOp {
NONE = 0;
ALL = 1;
DATA = 2;
}
DropOp drop_op = 4;
}

// Worker services.
Expand Down
Loading

0 comments on commit 087e431

Please sign in to comment.