Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dgraph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
7fff2de4
Commit
7fff2de4
authored
9 years ago
by
Manish R Jain
Browse files
Options
Downloads
Patches
Plain Diff
Expose GetOrAssign as a network call
parent
da0e9e19
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
worker/assign.go
+71
-0
71 additions, 0 deletions
worker/assign.go
worker/assign_test.go
+36
-0
36 additions, 0 deletions
worker/assign_test.go
worker/worker.go
+16
-0
16 additions, 0 deletions
worker/worker.go
worker/worker_test.go
+1
-1
1 addition, 1 deletion
worker/worker_test.go
with
124 additions
and
1 deletion
worker/assign.go
0 → 100644
+
71
−
0
View file @
7fff2de4
package
worker
import
(
"sync"
"github.com/dgraph-io/dgraph/task"
"github.com/dgraph-io/dgraph/uid"
"github.com/google/flatbuffers/go"
)
func
createXidListBuffer
(
xids
map
[
string
]
bool
)
[]
byte
{
b
:=
flatbuffers
.
NewBuilder
(
0
)
var
offsets
[]
flatbuffers
.
UOffsetT
for
xid
:=
range
xids
{
uo
:=
b
.
CreateString
(
xid
)
offsets
=
append
(
offsets
,
uo
)
}
task
.
XidListStartXidsVector
(
b
,
len
(
offsets
))
for
_
,
uo
:=
range
offsets
{
b
.
PrependUOffsetT
(
uo
)
}
ve
:=
b
.
EndVector
(
len
(
offsets
))
task
.
XidListStart
(
b
)
task
.
XidListAddXids
(
b
,
ve
)
lo
:=
task
.
XidListEnd
(
b
)
b
.
Finish
(
lo
)
return
b
.
Bytes
[
b
.
Head
()
:
]
}
func
getOrAssignUids
(
xidList
*
task
.
XidList
)
(
uidList
[]
byte
,
rerr
error
)
{
wg
:=
new
(
sync
.
WaitGroup
)
uids
:=
make
([]
uint64
,
xidList
.
XidsLength
())
che
:=
make
(
chan
error
,
xidList
.
XidsLength
())
for
i
:=
0
;
i
<
xidList
.
XidsLength
();
i
++
{
wg
.
Add
(
1
)
xid
:=
string
(
xidList
.
Xids
(
i
))
go
func
()
{
defer
wg
.
Done
()
u
,
err
:=
uid
.
GetOrAssign
(
xid
,
0
,
1
)
if
err
!=
nil
{
che
<-
err
return
}
uids
[
i
]
=
u
}()
}
wg
.
Wait
()
close
(
che
)
for
err
:=
range
che
{
glog
.
WithError
(
err
)
.
Error
(
"Encountered errors while getOrAssignUids"
)
return
uidList
,
err
}
b
:=
flatbuffers
.
NewBuilder
(
0
)
task
.
UidListStartUidsVector
(
b
,
xidList
.
XidsLength
())
for
i
:=
len
(
uids
)
-
1
;
i
>=
0
;
i
--
{
b
.
PrependUint64
(
uids
[
i
])
}
ve
:=
b
.
EndVector
(
xidList
.
XidsLength
())
task
.
UidListStart
(
b
)
task
.
UidListAddUids
(
b
,
ve
)
uend
:=
task
.
UidListEnd
(
b
)
b
.
Finish
(
uend
)
return
b
.
Bytes
[
b
.
Head
()
:
],
nil
}
This diff is collapsed.
Click to expand it.
worker/assign_test.go
0 → 100644
+
36
−
0
View file @
7fff2de4
package
worker
import
(
"testing"
"github.com/dgraph-io/dgraph/task"
"github.com/google/flatbuffers/go"
)
func
TestXidListBuffer
(
t
*
testing
.
T
)
{
xids
:=
map
[
string
]
bool
{
"b.0453"
:
true
,
"d.z1sz"
:
true
,
"e.abcd"
:
true
,
}
buf
:=
createXidListBuffer
(
xids
)
uo
:=
flatbuffers
.
GetUOffsetT
(
buf
)
xl
:=
new
(
task
.
XidList
)
xl
.
Init
(
buf
,
uo
)
if
xl
.
XidsLength
()
!=
len
(
xids
)
{
t
.
Errorf
(
"Expected: %v. Got: %v"
,
len
(
xids
),
xl
.
XidsLength
())
}
for
i
:=
0
;
i
<
xl
.
XidsLength
();
i
++
{
xid
:=
string
(
xl
.
Xids
(
i
))
t
.
Logf
(
"Found: %v"
,
xid
)
xids
[
xid
]
=
false
}
for
xid
,
untouched
:=
range
xids
{
if
untouched
{
t
.
Errorf
(
"Expected xid: %v to be part of the buffer."
,
xid
)
}
}
}
This diff is collapsed.
Click to expand it.
worker/worker.go
+
16
−
0
View file @
7fff2de4
...
...
@@ -91,6 +91,22 @@ func (w *Worker) Hello(query *conn.Query, reply *conn.Reply) error {
return
nil
}
func
(
w
*
Worker
)
GetOrAssign
(
query
*
conn
.
Query
,
reply
*
conn
.
Reply
)
(
rerr
error
)
{
uo
:=
flatbuffers
.
GetUOffsetT
(
query
.
Data
)
xids
:=
new
(
task
.
XidList
)
xids
.
Init
(
query
.
Data
,
uo
)
if
instanceIdx
!=
0
{
glog
.
WithField
(
"instanceIdx"
,
instanceIdx
)
.
WithField
(
"GetOrAssign"
,
true
)
.
Fatal
(
"We shouldn't be receiving this request."
)
}
reply
.
Data
,
rerr
=
getOrAssignUids
(
xids
)
return
}
func
(
w
*
Worker
)
Mutate
(
query
*
conn
.
Query
,
reply
*
conn
.
Reply
)
(
rerr
error
)
{
m
:=
new
(
Mutations
)
if
err
:=
m
.
Decode
(
query
.
Data
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
worker/worker_test.go
+
1
−
1
View file @
7fff2de4
...
...
@@ -83,7 +83,7 @@ func TestProcessTask(t *testing.T) {
addEdge
(
t
,
edge
,
posting
.
GetOrCreate
(
posting
.
Key
(
12
,
"friend"
),
ps
))
query
:=
NewQuery
(
"friend"
,
[]
uint64
{
10
,
11
,
12
})
result
,
err
:=
P
rocessTask
(
query
)
result
,
err
:=
p
rocessTask
(
query
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
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