Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
dgraph
Commits
c6c8c452
Commit
c6c8c452
authored
9 years ago
by
Manish R Jain
Browse files
Options
Downloads
Patches
Plain Diff
Tool to debug posting lists in RocksDB
parent
9c19a235
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tools/dlist/.gitignore
+1
-0
1 addition, 0 deletions
tools/dlist/.gitignore
tools/dlist/main.go
+82
-11
82 additions, 11 deletions
tools/dlist/main.go
uid/assigner.go
+3
-3
3 additions, 3 deletions
uid/assigner.go
with
86 additions
and
14 deletions
tools/dlist/.gitignore
0 → 100644
+
1
−
0
View file @
c6c8c452
/dlist
This diff is collapsed.
Click to expand it.
tools/dlist/main.go
+
82
−
11
View file @
c6c8c452
package
dlist
package
main
import
(
"bytes"
"flag"
"fmt"
"strconv"
"github.com/Sirupsen/logrus"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/store"
"github.com/dgraph-io/dgraph/posting/types"
"github.com/dgraph-io/dgraph/store/rocksdb"
"github.com/dgraph-io/dgraph/uid"
"github.com/dgraph-io/dgraph/x"
)
...
...
@@ -12,23 +18,88 @@ var glog = x.Log("dlist")
var
dir
=
flag
.
String
(
"dir"
,
""
,
"Directory containing "
)
var
xid
=
flag
.
String
(
"xid"
,
""
,
"Get posting list for xid"
)
var
uid
=
flag
.
String
(
"uid"
,
""
,
"Get posting list for uid"
)
var
s
uid
=
flag
.
String
(
"uid"
,
""
,
"Get posting list for uid"
)
var
attr
=
flag
.
String
(
"attr"
,
""
,
"Get posting list for attribute"
)
var
count
=
flag
.
Bool
(
"count"
,
false
,
"Only output number of results."
+
" Useful for range scanning with attribute."
)
func
output
(
val
[]
byte
)
{
pl
:=
types
.
GetRootAsPostingList
(
val
,
0
)
fmt
.
Printf
(
"Found posting list of length: %v
\n
"
,
pl
.
PostingsLength
())
var
p
types
.
Posting
for
i
:=
0
;
i
<
pl
.
PostingsLength
();
i
++
{
if
!
pl
.
Postings
(
&
p
,
i
)
{
glog
.
WithField
(
"i"
,
i
)
.
Fatal
(
"Unable to get posting"
)
}
fmt
.
Printf
(
"[%v] Uid: [%#x] Value: [%s]
\n
"
,
i
,
p
.
Uid
(),
string
(
p
.
ValueBytes
()))
}
}
func
scanOverAttr
(
db
*
rocksdb
.
DB
)
{
ro
:=
rocksdb
.
NewReadOptions
()
ro
.
SetFillCache
(
false
)
prefix
:=
[]
byte
(
*
attr
)
itr
:=
db
.
NewIterator
(
ro
)
itr
.
Seek
(
prefix
)
num
:=
0
for
itr
=
itr
;
itr
.
Valid
();
itr
.
Next
()
{
if
!
bytes
.
HasPrefix
(
itr
.
Key
(),
prefix
)
{
break
}
if
!*
count
{
fmt
.
Printf
(
"
\n
key: %#x
\n
"
,
itr
.
Key
())
output
(
itr
.
Value
())
}
num
+=
1
}
if
err
:=
itr
.
GetError
();
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"While iterating"
)
}
fmt
.
Printf
(
"Number of keys found: %v
\n
"
,
num
)
}
func
main
()
{
logrus
.
SetLevel
(
logrus
.
ErrorLevel
)
flag
.
Parse
()
var
s
store
.
Store
s
.
Init
(
*
dir
)
defer
s
.
Close
()
opt
:=
rocksdb
.
NewOptions
()
db
,
err
:=
rocksdb
.
Open
(
*
dir
,
opt
)
defer
db
.
Close
()
var
key
[]
byte
if
len
(
*
uid
)
>
0
&&
len
(
*
attr
)
>
0
{
key
=
posting
.
Key
(
*
uid
,
*
attr
)
if
len
(
*
suid
)
>
0
&&
len
(
*
attr
)
>
0
{
u
,
rerr
:=
strconv
.
ParseUint
(
*
suid
,
0
,
64
)
if
rerr
!=
nil
{
glog
.
WithError
(
rerr
)
.
Fatal
(
"While parsing uid"
)
}
key
=
posting
.
Key
(
u
,
*
attr
)
}
else
if
len
(
*
attr
)
>
0
{
glog
.
Fatal
(
"Not handling this yet."
)
scanOverAttr
(
db
)
return
}
else
if
len
(
*
suid
)
>
0
{
u
,
rerr
:=
strconv
.
ParseUint
(
*
suid
,
0
,
64
)
if
rerr
!=
nil
{
glog
.
WithError
(
rerr
)
.
Fatal
(
"While parsing uid"
)
}
key
=
posting
.
Key
(
u
,
"_xid_"
)
}
else
if
len
(
*
xid
)
>
0
{
key
=
uid
.
StringKey
(
*
xid
)
}
else
{
glog
.
Fatal
(
"Invalid request."
)
}
fmt
.
Printf
(
"key: %#x
\n
"
,
key
)
}
else
if
len
(
*
uid
)
>
0
{
key
=
posting
.
Key
(
*
uid
,
"_xid_"
)
ropt
:=
rocksdb
.
NewReadOptions
()
val
,
err
:=
db
.
Get
(
ropt
,
key
)
if
err
!=
nil
{
glog
.
WithError
(
err
)
.
Fatal
(
"Unable to get key"
)
}
output
(
val
)
}
This diff is collapsed.
Click to expand it.
uid/assigner.go
+
3
−
3
View file @
c6c8c452
...
...
@@ -187,12 +187,12 @@ func assignNew(pl *posting.List, xid string, instanceIdx uint64,
return
uid
,
rerr
}
func
s
tringKey
(
xid
string
)
[]
byte
{
func
S
tringKey
(
xid
string
)
[]
byte
{
return
[]
byte
(
"_uid_|"
+
xid
)
}
func
Get
(
xid
string
)
(
uid
uint64
,
rerr
error
)
{
key
:=
s
tringKey
(
xid
)
key
:=
S
tringKey
(
xid
)
pl
:=
posting
.
GetOrCreate
(
key
,
uidStore
)
if
pl
.
Length
()
==
0
{
return
0
,
fmt
.
Errorf
(
"xid: %v doesn't have any uid assigned."
,
xid
)
...
...
@@ -210,7 +210,7 @@ func Get(xid string) (uid uint64, rerr error) {
func
GetOrAssign
(
xid
string
,
instanceIdx
uint64
,
numInstances
uint64
)
(
uid
uint64
,
rerr
error
)
{
key
:=
s
tringKey
(
xid
)
key
:=
S
tringKey
(
xid
)
pl
:=
posting
.
GetOrCreate
(
key
,
uidStore
)
if
pl
.
Length
()
==
0
{
return
assignNew
(
pl
,
xid
,
instanceIdx
,
numInstances
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment