@@ -11,18 +11,20 @@ To debug a running Dgraph cluster, first copy the postings ("p") directory to
11
11
another location. If the Dgraph cluster is not running, then you can use the
12
12
same postings directory with the debug tool.
13
13
14
- If the “p” directory has been encrypted, then the debug tool will need to use the --keyfile <path-to-keyfile > option. This file must contain the same key that was used to encrypt the “p” directory.
14
+ If the “p” directory has been encrypted, then the debug tool will need to use the
15
+ --keyfile <path-to-keyfile > option. This file must contain the same key that was
16
+ used to encrypt the “p” directory.
15
17
{{% /notice %}}
16
18
17
19
The ` dgraph debug ` tool can be used to inspect Dgraph's posting list structure.
18
- You can use the debug tool to inspect the data, schema, and indices of your
19
- Dgraph cluster.
20
+ You can use the debug tool to inspect the data, schema, and indices of your Dgraph cluster.
20
21
21
22
Some scenarios where the debug tool is useful:
22
23
23
24
- Verify that mutations committed to Dgraph have been persisted to disk.
24
25
- Verify that indices are created.
25
26
- Inspect the history of a posting list.
27
+ - Parse a badger key into meaningful struct
26
28
27
29
## Example Usage
28
30
@@ -32,48 +34,53 @@ Debug the p directory.
32
34
$ dgraph debug --postings ./p
33
35
```
34
36
35
- Debug the p directory, not opening in read-only mode. This is typically necessary when the database was not closed properly.
37
+ Debug the p directory, not opening in read-only mode.
38
+ This is typically necessary when the database was not closed properly.
36
39
37
40
``` sh
38
41
$ dgraph debug --postings ./p --readonly=false
39
42
```
40
43
41
- Debug the p directory, only outputting the keys for the predicate ` name ` .
44
+ Debug the p directory, only outputting the keys for the predicate ` 0-name ` .
45
+ Note that 0 is the namespace and name is the predicate.
42
46
43
47
``` sh
44
- $ dgraph debug --postings ./p --readonly=false --pred=name
48
+ $ dgraph debug --postings ./p --readonly=false --pred=0- name
45
49
```
46
50
47
51
Debug the p directory, looking up a particular key:
48
52
49
53
``` sh
50
- $ dgraph debug --postings ./p --lookup 00000b6465736372697074696f6e020866617374
54
+ $ dgraph debug --postings ./p --lookup 01000000000000000000046e616d65
51
55
```
52
56
53
57
Debug the p directory, inspecting the history of a particular key:
54
58
55
59
``` sh
56
- $ dgraph debug --postings ./p --lookup 00000b6465736372697074696f6e020866617374 --history
60
+ $ dgraph debug --postings ./p --lookup 01000000000000000000046e616d65 --history
57
61
```
58
62
59
63
Debug an encrypted p directory with the key in a local file at the path ./key_file:
60
64
61
65
``` sh
62
- $ dgraph debug --postings ./p --keyfile ./key_file
66
+ $ dgraph debug --postings ./p --encryption=key-file= ./key_file
63
67
```
64
68
65
69
66
70
{{% notice "note" %}}
67
- The key file contains the key used to decrypt/encrypt the db. This key should be kept secret. As a best practice,
71
+ The key file contains the key used to decrypt/encrypt the db. This key should be kept secret. As a best practice,
68
72
69
- - Do not store the key file on the disk permanently. Back it up in a safe place and delete it after using it with the debug tool.
73
+ - Do not store the key file on the disk permanently. Back it up in a safe place and delete it
74
+ after using it with the debug tool.
70
75
71
- - If the above is not possible, make sure correct privileges are set on the keyfile. Only the user who owns the dgraph process should be able to read / write the key file: ` chmod 600 `
76
+ - If the above is not possible, make sure correct privileges are set on the keyfile. Only the
77
+ user who owns the dgraph process should be able to read / write the key file: ` chmod 600 `
72
78
{{% /notice %}}
73
79
74
80
## Debug Tool Output
75
81
76
- Let's go over an example with a Dgraph cluster with the following schema with a term index, full-text index, and two separately committed mutations:
82
+ Let's go over an example with a Dgraph cluster with the following schema with a term index,
83
+ full-text index, and two separately committed mutations:
77
84
78
85
``` sh
79
86
$ curl localhost:8080/alter -d '
@@ -84,7 +91,7 @@ $ curl localhost:8080/alter -d '
84
91
```
85
92
86
93
``` sh
87
- $ curl -H " Content-Type: application/rdf" localhost:8080/mutate? commitNow=true -d ' {
94
+ $ curl -H " Content-Type: application/rdf" " localhost:8080/mutate?commitNow=true" -d ' {
88
95
set {
89
96
_:dgraph <name> "Dgraph" .
90
97
_:dgraph <dgraph.type> "Software" .
@@ -95,7 +102,7 @@ $ curl -H "Content-Type: application/rdf" localhost:8080/mutate?commitNow=true -
95
102
```
96
103
97
104
``` sh
98
- $ curl -H " Content-Type: application/rdf" localhost:8080/mutate? commitNow=true -d ' {
105
+ $ curl -H " Content-Type: application/rdf" " localhost:8080/mutate?commitNow=true" -d ' {
99
106
set {
100
107
_:badger <name> "Badger" .
101
108
_:badger <dgraph.type> "Software" .
@@ -108,7 +115,8 @@ $ curl -H "Content-Type: application/rdf" localhost:8080/mutate?commitNow=true -
108
115
After stopping Dgraph, you can run the debug tool to inspect the postings directory:
109
116
110
117
{{% notice "note" %}}
111
- The debug output can be very large. Typically you would redirect the debug tool to a file first for easier analysis.
118
+ The debug output can be very large. Typically you would redirect the debug tool to a file first for
119
+ easier analysis.
112
120
{{% /notice %}}
113
121
114
122
``` sh
@@ -117,42 +125,53 @@ $ dgraph debug --postings ./p
117
125
118
126
``` text
119
127
Opening DB: ./p
120
- Min commit: 1. Max commit: 5, w.r.t 18446744073709551615
128
+
121
129
prefix =
122
- {d} {v.ok} attr: url uid: 1 key: 00000375726c000000000000000001 item: [71, b0100] ts: 3
123
- {d} {v.ok} attr: url uid: 2 key: 00000375726c000000000000000002 item: [71, b0100] ts: 5
124
- {d} {v.ok} attr: name uid: 1 key: 0000046e616d65000000000000000001 item: [43, b0100] ts: 3
125
- {d} {v.ok} attr: name uid: 2 key: 0000046e616d65000000000000000002 item: [43, b0100] ts: 5
126
- {i} {v.ok} attr: name term: [1] badger key: 0000046e616d650201626164676572 item: [30, b0100] ts: 5
127
- {i} {v.ok} attr: name term: [1] dgraph key: 0000046e616d650201646772617068 item: [30, b0100] ts: 3
128
- {d} {v.ok} attr: _predicate_ uid: 1 key: 00000b5f7072656469636174655f000000000000000001 item: [104, b0100] ts: 3
129
- {d} {v.ok} attr: _predicate_ uid: 2 key: 00000b5f7072656469636174655f000000000000000002 item: [104, b0100] ts: 5
130
- {d} {v.ok} attr: description uid: 1 key: 00000b6465736372697074696f6e000000000000000001 item: [92, b0100] ts: 3
131
- {d} {v.ok} attr: description uid: 2 key: 00000b6465736372697074696f6e000000000000000002 item: [119, b0100] ts: 5
132
- {i} {v.ok} attr: description term: [8] databas key: 00000b6465736372697074696f6e020864617461626173 item: [38, b0100] ts: 5
133
- {i} {v.ok} attr: description term: [8] distribut key: 00000b6465736372697074696f6e0208646973747269627574 item: [40, b0100] ts: 3
134
- {i} {v.ok} attr: description term: [8] embedd key: 00000b6465736372697074696f6e0208656d62656464 item: [37, b0100] ts: 5
135
- {i} {v.ok} attr: description term: [8] fast key: 00000b6465736372697074696f6e020866617374 item: [35, b0100] ts: 5
136
- {i} {v.ok} attr: description term: [8] go key: 00000b6465736372697074696f6e0208676f item: [33, b0100] ts: 5
137
- {i} {v.ok} attr: description term: [8] graph key: 00000b6465736372697074696f6e02086772617068 item: [36, b0100] ts: 3
138
- {i} {v.ok} attr: description term: [8] kei key: 00000b6465736372697074696f6e02086b6569 item: [34, b0100] ts: 5
139
- {i} {v.ok} attr: description term: [8] kv key: 00000b6465736372697074696f6e02086b76 item: [33, b0100] ts: 5
140
- {i} {v.ok} attr: description term: [8] persist key: 00000b6465736372697074696f6e020870657273697374 item: [38, b0100] ts: 5
141
- {i} {v.ok} attr: description term: [8] pure key: 00000b6465736372697074696f6e020870757265 item: [35, b0100] ts: 5
142
- {i} {v.ok} attr: description term: [8] transact key: 00000b6465736372697074696f6e02087472616e73616374 item: [39, b0100] ts: 3
143
- {i} {v.ok} attr: description term: [8] valu key: 00000b6465736372697074696f6e020876616c75 item: [35, b0100] ts: 5
144
- {i} {v.ok} attr: description term: [8] written key: 00000b6465736372697074696f6e02087772697474656e item: [38, b0100] ts: 5
145
- {s} {v.ok} attr: url key: 01000375726c item: [13, b0001] ts: 1
146
- {s} {v.ok} attr: name key: 0100046e616d65 item: [23, b0001] ts: 1
147
- {s} {v.ok} attr: _predicate_ key: 01000b5f7072656469636174655f item: [31, b0001] ts: 1
148
- {s} {v.ok} attr: description key: 01000b6465736372697074696f6e item: [41, b0001] ts: 1
149
- {s} {v.ok} attr: dgraph.type key: 01000b6467726170682e74797065 item: [40, b0001] ts: 1
150
- Found 28 keys
151
- ```
152
-
153
- Each line in the debug output contains a prefix indicating the type of the key: ` {d} ` : Data key; ` {i} ` : Index key; ` {c} ` : Count key; ` {r} ` : Reverse key; ` {s} ` : Schema key. In the debug output above, we see data keys, index keys, and schema keys.
154
-
155
- Each index key has a corresponding index type. For example, in ` attr: name term: [1] dgraph ` the ` [1] ` shows that this is the term index ([ 0x1] [ tok_term ] ); in ` attr: description term: [8] fast ` , the ` [8] ` shows that this is the full-text index ([ 0x8] [ tok_fulltext ] ). These IDs match the index IDs in [ tok.go] [ tok ] .
130
+ {d} ns: 0x0 attr: url uid: 1 ts: 5 item: [79, b0100] sz: 79 dcnt: 1 key: 000000000000000000000375726c000000000000000001
131
+ {d} ns: 0x0 attr: url uid: 2 ts: 8 item: [108, b1000] sz: 108 dcnt: 0 isz: 187 icount: 2 key: 000000000000000000000375726c000000000000000002
132
+ {d} ns: 0x0 attr: name uid: 1 ts: 5 item: [51, b0100] sz: 51 dcnt: 1 key: 00000000000000000000046e616d65000000000000000001
133
+ {d} ns: 0x0 attr: name uid: 2 ts: 8 item: [80, b1000] sz: 80 dcnt: 0 isz: 131 icount: 2 key: 00000000000000000000046e616d65000000000000000002
134
+ {i} ns: 0x0 attr: name term: [1] [badger] ts: 8 item: [41, b1000] sz: 41 dcnt: 0 isz: 79 icount: 2 key: 00000000000000000000046e616d650201626164676572
135
+ {i} ns: 0x0 attr: name term: [1] [dgraph] ts: 5 item: [38, b0100] sz: 38 dcnt: 1 key: 00000000000000000000046e616d650201646772617068
136
+ {d} ns: 0x0 attr: description uid: 1 ts: 5 item: [100, b0100] sz: 100 dcnt: 1 key: 000000000000000000000b6465736372697074696f6e000000000000000001
137
+ {d} ns: 0x0 attr: description uid: 2 ts: 8 item: [156, b1000] sz: 156 dcnt: 0 isz: 283 icount: 2 key: 000000000000000000000b6465736372697074696f6e000000000000000002
138
+ {i} ns: 0x0 attr: description term: [8] [databas] ts: 8 item: [49, b1000] sz: 49 dcnt: 0 isz: 141 icount: 3 key: 000000000000000000000b6465736372697074696f6e020864617461626173
139
+ {i} ns: 0x0 attr: description term: [8] [distribut] ts: 5 item: [48, b0100] sz: 48 dcnt: 1 key: 000000000000000000000b6465736372697074696f6e0208646973747269627574
140
+ {i} ns: 0x0 attr: description term: [8] [embedd] ts: 8 item: [48, b1000] sz: 48 dcnt: 0 isz: 93 icount: 2 key: 000000000000000000000b6465736372697074696f6e0208656d62656464
141
+ {i} ns: 0x0 attr: description term: [8] [fast] ts: 8 item: [46, b1000] sz: 46 dcnt: 0 isz: 132 icount: 3 key: 000000000000000000000b6465736372697074696f6e020866617374
142
+ {i} ns: 0x0 attr: description term: [8] [go] ts: 8 item: [44, b1000] sz: 44 dcnt: 0 isz: 85 icount: 2 key: 000000000000000000000b6465736372697074696f6e0208676f
143
+ {i} ns: 0x0 attr: description term: [8] [graph] ts: 5 item: [44, b0100] sz: 44 dcnt: 1 key: 000000000000000000000b6465736372697074696f6e02086772617068
144
+ {i} ns: 0x0 attr: description term: [8] [kei] ts: 8 item: [45, b1000] sz: 45 dcnt: 0 isz: 87 icount: 2 key: 000000000000000000000b6465736372697074696f6e02086b6569
145
+ {i} ns: 0x0 attr: description term: [8] [kv] ts: 8 item: [44, b1000] sz: 44 dcnt: 0 isz: 85 icount: 2 key: 000000000000000000000b6465736372697074696f6e02086b76
146
+ {i} ns: 0x0 attr: description term: [8] [persist] ts: 8 item: [49, b1000] sz: 49 dcnt: 0 isz: 95 icount: 2 key: 000000000000000000000b6465736372697074696f6e020870657273697374
147
+ {i} ns: 0x0 attr: description term: [8] [pure] ts: 8 item: [46, b1000] sz: 46 dcnt: 0 isz: 89 icount: 2 key: 000000000000000000000b6465736372697074696f6e020870757265
148
+ {i} ns: 0x0 attr: description term: [8] [transact] ts: 5 item: [47, b0100] sz: 47 dcnt: 1 key: 000000000000000000000b6465736372697074696f6e02087472616e73616374
149
+ {i} ns: 0x0 attr: description term: [8] [valu] ts: 8 item: [46, b1000] sz: 46 dcnt: 0 isz: 89 icount: 2 key: 000000000000000000000b6465736372697074696f6e020876616c75
150
+ {i} ns: 0x0 attr: description term: [8] [written] ts: 8 item: [49, b1000] sz: 49 dcnt: 0 isz: 95 icount: 2 key: 000000000000000000000b6465736372697074696f6e02087772697474656e
151
+ {d} ns: 0x0 attr: dgraph.type uid: 1 ts: 5 item: [60, b0100] sz: 60 dcnt: 1 key: 000000000000000000000b6467726170682e74797065000000000000000001
152
+ {d} ns: 0x0 attr: dgraph.type uid: 2 ts: 8 item: [88, b1000] sz: 88 dcnt: 0 isz: 148 icount: 2 key: 000000000000000000000b6467726170682e74797065000000000000000002
153
+ {i} ns: 0x0 attr: dgraph.type term: [2] [Software] ts: 8 item: [50, b1000] sz: 50 dcnt: 0 isz: 144 icount: 3 key: 000000000000000000000b6467726170682e747970650202536f667477617265
154
+ {s} ns: 0x0 attr: url ts: 3 item: [23, b0001] sz: 23 dcnt: 0 isz: 23 icount: 1 key: 010000000000000000000375726c
155
+ {s} ns: 0x0 attr: name ts: 3 item: [33, b0001] sz: 33 dcnt: 0 isz: 33 icount: 1 key: 01000000000000000000046e616d65
156
+ {s} ns: 0x0 attr: description ts: 3 item: [51, b0001] sz: 51 dcnt: 0 isz: 51 icount: 1 key: 010000000000000000000b6465736372697074696f6e
157
+ {s} ns: 0x0 attr: dgraph.type ts: 1 item: [50, b0001] sz: 50 dcnt: 0 isz: 50 icount: 1 key: 010000000000000000000b6467726170682e74797065
158
+ {s} ns: 0x0 attr: dgraph.drop.op ts: 1 item: [45, b0001] sz: 45 dcnt: 0 isz: 45 icount: 1 key: 010000000000000000000e6467726170682e64726f702e6f70
159
+ {s} ns: 0x0 attr: dgraph.graphql.xid ts: 1 item: [64, b0001] sz: 64 dcnt: 0 isz: 64 icount: 1 key: 01000000000000000000126467726170682e6772617068716c2e786964
160
+ {s} ns: 0x0 attr: dgraph.graphql.schema ts: 1 item: [59, b0001] sz: 59 dcnt: 0 isz: 59 icount: 1 key: 01000000000000000000156467726170682e6772617068716c2e736368656d61
161
+ {s} ns: 0x0 attr: dgraph.graphql.p_query ts: 1 item: [71, b0001] sz: 71 dcnt: 0 isz: 71 icount: 1 key: 01000000000000000000166467726170682e6772617068716c2e705f7175657279
162
+ ns: 0x0 attr: dgraph.graphql ts: 1 item: [98, b0001] sz: 98 dcnt: 0 isz: 98 icount: 1 key: 020000000000000000000e6467726170682e6772617068716c
163
+ ns: 0x0 attr: dgraph.graphql.persisted_query ts: 1 item: [105, b0001] sz: 105 dcnt: 0 isz: 105 icount: 1 key: 020000000000000000001e6467726170682e6772617068716c2e7065727369737465645f7175657279
164
+
165
+ Found 34 keys
166
+ ```
167
+
168
+ Each line in the debug output contains a prefix indicating the type of the key: ` {d} ` : Data key; ` {i} ` : Index key;
169
+ ` {c} ` : Count key; ` {r} ` : Reverse key; ` {s} ` : Schema key. In the debug output above, we see data keys, index keys,
170
+ and schema keys.
171
+
172
+ Each index key has a corresponding index type. For example, in ` attr: name term: [1] [dgraph] ` the ` [1] ` shows that
173
+ this is the term index ([ 0x1] [ tok_term ] ); in ` attr: description term: [8] [fast] ` , the ` [8] ` shows that this is the
174
+ full-text index ([ 0x8] [ tok_fulltext ] ). These IDs match the index IDs in [ tok.go] [ tok ] .
156
175
157
176
[ tok_term ] : https://github.com/dgraph-io/dgraph/blob/ce82aaafba3d9e57cf5ea1aeb9b637193441e1e2/tok/tok.go#L39
158
177
[ tok_fulltext ] : https://github.com/dgraph-io/dgraph/blob/ce82aaafba3d9e57cf5ea1aeb9b637193441e1e2/tok/tok.go#L48
@@ -163,63 +182,65 @@ Each index key has a corresponding index type. For example, in `attr: name term:
163
182
Every key can be inspected further with the ` --lookup ` flag for the specific key.
164
183
165
184
``` sh
166
- $ dgraph debug --postings ./p --lookup 00000b6465736372697074696f6e020866617374
185
+ $ dgraph debug --postings ./p --lookup 000000000000000000000b6465736372697074696f6e020866617374
167
186
```
168
187
169
188
``` text
170
189
Opening DB: ./p
171
- Min commit: 1. Max commit: 5, w.r.t 18446744073709551615
172
- Key: 00000b6465736372697074696f6e0208676f Length: 2
173
- Uid: 1 Op: 1
174
- Uid: 2 Op: 1
190
+
191
+ Key: 000000000000000000000b6465736372697074696f6e020866617374 Length: 2 Is multi-part list? false Uid: 1 Op: 0
192
+ Uid: 2 Op: 0
175
193
```
176
194
177
195
For data keys, a lookup shows its type and value. Below, we see that the key for ` attr: url uid: 1 ` is a string value.
178
196
179
197
``` sh
180
- $ dgraph debug --postings ./p --lookup 00000375726c000000000000000001
198
+ $ dgraph debug --postings ./p --lookup 000000000000000000000375726c000000000000000001
181
199
```
182
200
183
201
``` text
184
202
Opening DB: ./p
185
- Min commit: 1. Max commit: 5, w.r.t 18446744073709551615
186
- Key: 0000046e616d65000000000000000001 Length: 1
187
- Uid: 18446744073709551615 Op: 1 Type: STRING. String Value: "https://github.com/dgraph-io/dgraph"
203
+
204
+ Key: 000000000000000000000375726c000000000000000001 Length: 1 Is multi-part list? false Uid: 18446744073709551615 Op: 1 Type: STRING. String Value: "https://github.com/dgraph-io/dgraph
188
205
```
189
206
190
- For index keys, a lookup shows the UIDs that are part of this index. Below, we see that the ` fast ` index for the ` <description> ` predicate has UIDs 0x1 and 0x2.
207
+ For index keys, a lookup shows the UIDs that are part of this index.
208
+ Below, we see that the ` fast ` index for the ` <description> ` predicate has UIDs 0x1 and 0x2.
191
209
192
210
``` sh
193
- $ dgraph debug --postings ./p --lookup 00000b6465736372697074696f6e020866617374
211
+ $ dgraph debug --postings ./p --lookup 000000000000000000000b6465736372697074696f6e020866617374
194
212
```
195
213
196
214
``` text
197
215
Opening DB: ./p
198
- Min commit: 1. Max commit: 5, w.r.t 18446744073709551615
199
- Key: 00000b6465736372697074696f6e0208676f Length: 2
200
- Uid: 1 Op: 1
201
- Uid: 2 Op: 1
216
+ Key: 000000000000000000000b6465736372697074696f6e020866617374 Length: 2 Is multi-part list? false Uid: 1 Op: 0
217
+ Uid: 2 Op: 0
202
218
```
203
219
204
220
## Key History
205
221
206
222
You can also look up the history of values for a key using the ` --history ` option.
207
223
208
224
``` sh
209
- $ dgraph debug --postings ./p --lookup 00000b6465736372697074696f6e020866617374 --history
225
+ $ dgraph debug --postings ./p --lookup 000000000000000000000b6465736372697074696f6e020866617374 --history
210
226
```
211
227
``` text
212
228
Opening DB: ./p
213
- Min commit: 1. Max commit: 5, w.r.t 18446744073709551615
214
- ==> key: 00000b6465736372697074696f6e020866617374. PK: &{byteType:2 Attr:description Uid:0 Termfast Count:0 bytePrefix:0}
215
- ts: 5 {item}{delta}
229
+
230
+ ==> key: 000000000000000000000b6465736372697074696f6e020866617374. PK: UID: 0, Attr: 0-description, IsIndex: true, Term: 0
231
+ ts: 8 {item}{discard}{complete}
232
+ Num uids = 2. Size = 16
233
+ Uid = 1
234
+ Uid = 2
235
+
236
+ ts: 7 {item}{delta}
216
237
Uid: 2 Op: 1
217
238
218
- ts: 3 {item}{delta}
239
+ ts: 5 {item}{delta}
219
240
Uid: 1 Op: 1
220
241
```
221
242
222
- Above, we see that UID 0x1 was committed to this index at ts 3 , and UID 0x2 was committed to this index at ts 5 .
243
+ Above, we see that UID 0x1 was committed to this index at ts 5 , and UID 0x2 was committed to this index at ts 7 .
223
244
224
245
The debug output also shows UserMeta information:
225
246
@@ -228,4 +249,16 @@ The debug output also shows UserMeta information:
228
249
- ` {delta} ` : Delta posting list
229
250
- ` {empty} ` : Empty posting list
230
251
- ` {item} ` : Item posting list
231
- - ` {deleted} ` : Delete marker
252
+ - ` {deleted} ` : Delete marker
253
+
254
+ ## Parse Key
255
+
256
+ You can parse a key into its constituent components using ` --parse_key ` . This does not require a p directory.
257
+
258
+
259
+ ``` sh
260
+ $ dgraph debug --parse_key 000000000000000000000b6467726170682e74797065000000000000000001
261
+ ```
262
+ ``` text
263
+ {d} Key: UID: 1, Attr: 0-dgraph.type, Data key
264
+ ```
0 commit comments