Setup DGraph Cluster on ( Ubuntu20.04, Jammy) - 3 Alpha and 3 Zero ( HA, Recovery, Snapshot, Visibility )

What I want to do

Setup cluster of DGraph in Ubuntu20.04 with 3 Alpha and 3 Zero

What I did

Steps to run as daemon:

[Unit]
Description=dgraph.io data server
Wants=network.target
After=network.target dgraph.service
Requires=dgraph.service

[Service]
Type=simple
ExecStart=/home/sre/dgraph/dgraph alpha --my=VM_IP:7080 --zero=VM_IP:5080 --raft=idx=2 -p /var/run/dgraph/p -w /var/run/dgraph/w
StandardOutput=journal
StandardError=journal
User=root
Group=root

[Install]
WantedBy=multi-user.target
  • mkdir -p /var/run/dgraph/zw, chmod -R 750 /var/run/dgraph
  • ls -ld /var/run/dgraph, ls -ld /var/run/dgraph/zw/
  • sudo systemctl daemon-reload, systemctl status dgraph, systemctl restart dgraph

Post changing the above configuration for different VM’s:

Able to run the DGraph with 3 Alpha and 3 Zero Nodes as Daemon Service in Ubuntu20.04

Zero 1:
ExecStart=/home/sre/dgraph/dgraph zero --my=VM_IP_1:5080 --replicas 3 --raft=idx=1 --wal /var/run/dgraph/zw

Zero 2: 
ExecStart=/home/sre/dgraph/dgraph zero --my=VM_IP_2:5080 --peer VM_IP_1:5080 --replicas 3 --raft=idx=2 --wal /var/run/dgraph/zw

Zero 3:
ExecStart=/home/sre/dgraph/dgraph zero --my=VM_IP_3:5080 --peer VM_IP_1:5080 --replicas 3 --raft=idx=3 --wal /var/run/dgraph/zw


Alpha 1:
ExecStart=/home/ashwani.yadav/dgraph alpha --my=VM_IP_4:7080 --zero=VM_IP_1:5080 --raft=idx=1 -p /var/run/dgraph/p -w /var/run/dgraph/w

Alpha 2:
ExecStart=/home/sre/dgraph/dgraph alpha --my=VM_IP_5:7080 --zero=VM_IP_1:5080 --raft=idx=2 -p /var/run/dgraph/p -w /var/run/dgraph/w

Alpha 3:
ExecStart=/home/sre/dgraph/dgraph alpha --my=VM_IP_6:7080 --zero=VM_IP_1:5080 --raft=idx=3 -p /var/run/dgraph/p -w /var/run/dgraph/w

Now cluster is up and running without any issue, but in the RatelUI only 1 Group is having all the tablets, none of the other Group of Alpha has any tablets, until and unless I am specifically making the schema in it.

My questions are:

Ideally Tablets should be distributed across different Alpha’s in the Group automatically, right ?

Second Issue, I am not able to get my data back. Insertion of data went fine and have given me success on the admin API response, but once I am trying to find the data using Query nothing is showing up ?

How to maintain the snapshot and how to apply snapshot in case recovery is needed ?

Other Images for Query, Predicate, Types visible

schema:

curl -X POST localhost:8080/alter -d '
type Customer {
  id
  name
  email
  purchase_history
}
'

Logs:

Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.043551 2569588 http.go:614] Got alter request via HTTP from 127.0.0.1:22784
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.044506 2569588 server.go:377] Received ALTER op: schema:"\nid: string @index(exact) @upsert .\nname: string @index(term) .\nemail: string @index(exact) .\npurchase_history: [uid] .\n"
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.044547 2569588 server.go:1686] Got Alter request from: "127.0.0.1:22784"
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.046324 2569588 server.go:526] Got schema: &{Preds:[predicate:"0-id" value_type:STRING directive:INDEX tokenizer:"exact" upsert:true  predicate:"0-name" value_type:STRING directive:INDEX tokenizer:"term"  predicate:"0-email" value_type:STRING directive:INDEX tokenizer:"exact"  predicate:"0-purchase_history" value_type:UID list:true ] Types:[]}
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.047724 2569588 mutation.go:202] Max open files limit: 524288
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.048770 2569588 index.go:780] Deleting indexes for 0-id
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.049084 2569588 index.go:780] Deleting indexes for 0-name
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.050666 2569588 server.go:540] ALTER op: schema:"\nid: string @index(exact) @upsert .\nname: string @index(term) .\nemail: string @index(exact) .\npurchase_history: [uid] .\n"  done
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.063793 2569588 http.go:614] Got alter request via HTTP from 127.0.0.1:22786
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.064048 2569588 server.go:377] Received ALTER op: schema:"\ntype Customer {\n  id\n  name\n  email\n  purchase_history\n}\n"
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.064088 2569588 server.go:1686] Got Alter request from: "127.0.0.1:22786"
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.065496 2569588 server.go:526] Got schema: &{Preds:[] Types:[type_name:"0-Customer" fields:<predicate:"0-id" > fields:<predicate:"0-name" > fields:<predicate:"0-email" > fields:<predicate:"0-purchase_history" > ]}
Jul 02 13:14:17 stg-ashwani005 dgraph[2569560]: I0702 13:14:17.067948 2569588 server.go:540] ALTER op: schema:"\ntype Customer {\n  id\n  name\n  email\n  purchase_history\n}\n"  done

Insertion of data:

curl -X POST localhost:8080/mutate -H "Content-Type: application/json" -d '{
  "set": [
    {
      "uid": "_:customer1",
      "dgraph.type": "Customer",
      "id": "1",
      "name": "Alice Johnson",
      "email": "alice@example.com"
    },
    {
      "uid": "_:customer2",
      "dgraph.type": "Customer",
      "id": "2",
      "name": "Bob Smith",
      "email": "bob@example.com"
    }
  ]
}'

Response I get:

{"data":{"code":"Success","message":"Done","queries":null,"uids":{"dg.960315563.1":"0x2720","dg.960315563.2":"0x2723","purchase1":"0x2721","purchase2":"0x2722","purchase3":"0x2724","purchase4":"0x2725"}},"extensions":{"server_latency":{"parsing_ns":191650,"processing_ns":3704405,"assign_timestamp_ns":1295739,"total_ns":5490665},"txn":{"start_ts":10348,"keys":["11h35u3v567up","1ddilwjdppv2j","1gmlrx2gms5t0","1gmlrx2gms5t1","1olx0ehdj620m","1zwvmp6gd98tv","28c6ermowwj5r","2przdhzp04s6w","2q5p2hgu1umdc","2qgxm4hdfytlh","2r56n110w1fjv","2u3bihi2lt2vy","2uaugmpvcheqj","2vlq4maf743ss","32zg2v1id4btk","33g4qzj0afh38","33g4qzj0afh3b","3k4e946smtzr8","8p8gv9lzzj9y","9726oyo3iqva","faz4bt8juuyt","faz4bt8juuyu"],"preds":["1-0-dgraph.type","1-0-id","1-0-name","2-0-email","2-0-purchase_history"]}}}

Logs
Nothing got updated in the logs

Query I used to fetch the data:

curl -H "Content-Type: application/json" -X POST localhost:8080/query -d '{
  "query": "{ allCustomers(func: has(dgraph.type)) { uid dgraph.type id name email } }"
}'

Response:

{"data":{"allCustomers":[{"uid":"0x1","dgraph.type":["dgraph.graphql"]}]},"extensions":{"server_latency":{"parsing_ns":58848,"processing_ns":2382858,"encoding_ns":108988,"assign_timestamp_ns":1150921,"total_ns":3813301},"txn":{"start_ts":10360},"metrics":{"num_uids":{"_total":5,"dgraph.type":1,"email":1,"id":1,"name":1,"uid":1}}}}

Logs:
Nothing got updated in the logs

RatelUI Query:

{
  allCustomers(func: has(dgraph.type)) {
    uid
    dgraph.type
    id
    name
    email
  }
}

Response:

{
  "data": {
    "allCustomers": [
      {
        "uid": "0x1",
        "dgraph.type": [
          "dgraph.graphql"
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 85408,
      "processing_ns": 1532104,
      "encoding_ns": 57038,
      "assign_timestamp_ns": 1324574,
      "total_ns": 3156200
    },
    "txn": {
      "start_ts": 10378
    },
    "metrics": {
      "num_uids": {
        "_total": 5,
        "dgraph.type": 1,
        "email": 1,
        "id": 1,
        "name": 1,
        "uid": 1
      }
    }
  }
}

try this query

  allCustomers(func: type(Customer)) {
    uid
    dgraph.type
    id
    name
    email
  }
}

able to setup the cluster properly it seems: Cluster Types - Deploy

updated the configuration above for Alpha, we have to make Zero as per my first thread, but in Alpha we don’t have to give any raft_id to create the group.

But still I am some queries in regard to Snapshot and Backup. How to achieve this as the Docs does not specify anything in brief for manual cluster management.