Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename intern pkg to pb #2608

Merged
merged 4 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions algo/uidlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"sort"

"github.com/dgraph-io/dgraph/bp128"
"github.com/dgraph-io/dgraph/protos/intern"
"github.com/dgraph-io/dgraph/protos/pb"
)

const jump = 32 // Jump size in InsersectWithJump.

// ApplyFilter applies a filter to our UIDList.
func ApplyFilter(u *intern.List, f func(uint64, int) bool) {
func ApplyFilter(u *pb.List, f func(uint64, int) bool) {
out := u.Uids[:0]
for i, uid := range u.Uids {
if f(uid, i) {
Expand All @@ -28,7 +28,7 @@ func ApplyFilter(u *intern.List, f func(uint64, int) bool) {
u.Uids = out
}

func IntersectCompressedWith(u []byte, afterUID uint64, v, o *intern.List) {
func IntersectCompressedWith(u []byte, afterUID uint64, v, o *pb.List) {
var bi bp128.BPackIterator
bi.Init(u, afterUID)
n := bi.Length() - bi.StartIdx()
Expand Down Expand Up @@ -120,7 +120,7 @@ func IntersectCompressedWithBin(bi *bp128.BPackIterator, q []uint64, o *[]uint64

// IntersectWith intersects u with v. The update is made to o.
// u, v should be sorted.
func IntersectWith(u, v, o *intern.List) {
func IntersectWith(u, v, o *pb.List) {
n := len(u.Uids)
m := len(v.Uids)

Expand Down Expand Up @@ -261,13 +261,13 @@ func binIntersect(d, q []uint64, final *[]uint64) {
}

type listInfo struct {
l *intern.List
l *pb.List
length int
}

func IntersectSorted(lists []*intern.List) *intern.List {
func IntersectSorted(lists []*pb.List) *pb.List {
if len(lists) == 0 {
return &intern.List{}
return &pb.List{}
}
ls := make([]listInfo, 0, len(lists))
for _, list := range lists {
Expand All @@ -280,7 +280,7 @@ func IntersectSorted(lists []*intern.List) *intern.List {
sort.Slice(ls, func(i, j int) bool {
return ls[i].length < ls[j].length
})
out := &intern.List{Uids: make([]uint64, ls[0].length)}
out := &pb.List{Uids: make([]uint64, ls[0].length)}
if len(ls) == 1 {
copy(out.Uids, ls[0].l.Uids)
return out
Expand All @@ -299,9 +299,9 @@ func IntersectSorted(lists []*intern.List) *intern.List {
return out
}

func Difference(u, v *intern.List) *intern.List {
func Difference(u, v *pb.List) *pb.List {
if u == nil || v == nil {
return &intern.List{Uids: make([]uint64, 0)}
return &pb.List{Uids: make([]uint64, 0)}
}
n := len(u.Uids)
m := len(v.Uids)
Expand All @@ -327,13 +327,13 @@ func Difference(u, v *intern.List) *intern.List {
out = append(out, u.Uids[i])
i++
}
return &intern.List{Uids: out}
return &pb.List{Uids: out}
}

// MergeSorted merges sorted lists.
func MergeSorted(lists []*intern.List) *intern.List {
func MergeSorted(lists []*pb.List) *pb.List {
if len(lists) == 0 {
return new(intern.List)
return new(pb.List)
}

h := &uint64Heap{}
Expand Down Expand Up @@ -377,12 +377,12 @@ func MergeSorted(lists []*intern.List) *intern.List {
heap.Fix(h, 0) // Faster than Pop() followed by Push().
}
}
return &intern.List{Uids: output}
return &pb.List{Uids: output}
}

// IndexOf performs a binary search on the uids slice and returns the index at
// which it finds the uid, else returns -1
func IndexOf(u *intern.List, uid uint64) int {
func IndexOf(u *pb.List, uid uint64) int {
i := sort.Search(len(u.Uids), func(i int) bool { return u.Uids[i] >= uid })
if i < len(u.Uids) && u.Uids[i] == uid {
return i
Expand All @@ -391,7 +391,7 @@ func IndexOf(u *intern.List, uid uint64) int {
}

// ToUintsListForTest converts to list of uints for testing purpose only.
func ToUintsListForTest(ul []*intern.List) [][]uint64 {
func ToUintsListForTest(ul []*pb.List) [][]uint64 {
out := make([][]uint64, 0, len(ul))
for _, u := range ul {
out = append(out, u.Uids)
Expand Down
64 changes: 32 additions & 32 deletions algo/uidlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import (
"testing"

"github.com/dgraph-io/dgraph/bp128"
"github.com/dgraph-io/dgraph/protos/intern"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/stretchr/testify/require"
)

func newList(data []uint64) *intern.List {
return &intern.List{data}
func newList(data []uint64) *pb.List {
return &pb.List{data}
}

func TestMergeSorted1(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{55}),
}
require.Equal(t, MergeSorted(input).Uids, []uint64{55})
}

func TestMergeSorted2(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 3, 6, 8, 10}),
newList([]uint64{2, 4, 5, 7, 15}),
}
Expand All @@ -39,31 +39,31 @@ func TestMergeSorted2(t *testing.T) {
}

func TestMergeSorted3(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 3, 6, 8, 10}),
newList([]uint64{}),
}
require.Equal(t, MergeSorted(input).Uids, []uint64{1, 3, 6, 8, 10})
}

func TestMergeSorted4(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{}),
newList([]uint64{1, 3, 6, 8, 10}),
}
require.Equal(t, MergeSorted(input).Uids, []uint64{1, 3, 6, 8, 10})
}

func TestMergeSorted5(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{}),
newList([]uint64{}),
}
require.Empty(t, MergeSorted(input).Uids)
}

func TestMergeSorted6(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{11, 13, 16, 18, 20}),
newList([]uint64{12, 14, 15, 15, 16, 16, 17, 25}),
newList([]uint64{1, 2}),
Expand All @@ -73,7 +73,7 @@ func TestMergeSorted6(t *testing.T) {
}

func TestMergeSorted7(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{5, 6, 7}),
newList([]uint64{3, 4}),
newList([]uint64{1, 2}),
Expand All @@ -83,54 +83,54 @@ func TestMergeSorted7(t *testing.T) {
}

func TestMergeSorted8(t *testing.T) {
input := []*intern.List{}
input := []*pb.List{}
require.Empty(t, MergeSorted(input).Uids)
}

func TestMergeSorted9(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 1, 1}),
}
require.Equal(t, MergeSorted(input).Uids, []uint64{1})
}

func TestMergeSorted10(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3, 3, 6}),
newList([]uint64{4, 8, 9}),
}
require.Equal(t, MergeSorted(input).Uids, []uint64{1, 2, 3, 4, 6, 8, 9})
}

func TestIntersectSorted1(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{2, 3, 4, 5}),
}
require.Equal(t, []uint64{2, 3}, IntersectSorted(input).Uids)
}

func TestIntersectSorted2(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
}
require.Equal(t, IntersectSorted(input).Uids, []uint64{1, 2, 3})
}

func TestIntersectSorted3(t *testing.T) {
input := []*intern.List{}
input := []*pb.List{}
require.Empty(t, IntersectSorted(input).Uids)
}

func TestIntersectSorted4(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{100, 101}),
}
require.Equal(t, IntersectSorted(input).Uids, []uint64{100, 101})
}

func TestIntersectSorted5(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{2, 3, 4, 5}),
newList([]uint64{4, 5, 6}),
Expand All @@ -139,7 +139,7 @@ func TestIntersectSorted5(t *testing.T) {
}

func TestIntersectSorted6(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{10, 12, 13}),
newList([]uint64{2, 3, 4, 13}),
newList([]uint64{4, 5, 6}),
Expand All @@ -148,7 +148,7 @@ func TestIntersectSorted6(t *testing.T) {
}

func TestDiffSorted1(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{1}),
}
Expand All @@ -157,7 +157,7 @@ func TestDiffSorted1(t *testing.T) {
}

func TestDiffSorted2(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{2}),
}
Expand All @@ -166,7 +166,7 @@ func TestDiffSorted2(t *testing.T) {
}

func TestDiffSorted3(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{3}),
}
Expand All @@ -175,7 +175,7 @@ func TestDiffSorted3(t *testing.T) {
}

func TestDiffSorted4(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{}),
}
Expand All @@ -184,7 +184,7 @@ func TestDiffSorted4(t *testing.T) {
}

func TestDiffSorted5(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{}),
newList([]uint64{1, 2}),
}
Expand All @@ -193,7 +193,7 @@ func TestDiffSorted5(t *testing.T) {
}

func TestSubSorted1(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{1, 2, 3}),
newList([]uint64{2, 3, 4, 5}),
}
Expand All @@ -202,7 +202,7 @@ func TestSubSorted1(t *testing.T) {
}

func TestSubSorted6(t *testing.T) {
input := []*intern.List{
input := []*pb.List{
newList([]uint64{10, 12, 13}),
newList([]uint64{2, 3, 4, 13}),
}
Expand Down Expand Up @@ -290,8 +290,8 @@ func BenchmarkListIntersectRandom(b *testing.B) {

u := newList(u1)
v := newList(v1)
dst1 := &intern.List{}
dst2 := &intern.List{}
dst1 := &pb.List{}
dst2 := &pb.List{}
compressedUids := bp128.DeltaPack(u1)

b.Run(fmt.Sprintf(":size=%d:overlap=%.2f:", arrSz, overlap),
Expand Down Expand Up @@ -353,10 +353,10 @@ func BenchmarkListIntersectRatio(b *testing.B) {
sort.Slice(u1, func(i, j int) bool { return u1[i] < u1[j] })
sort.Slice(v1, func(i, j int) bool { return v1[i] < v1[j] })

u := &intern.List{u1}
v := &intern.List{v1}
dst1 := &intern.List{}
dst2 := &intern.List{}
u := &pb.List{u1}
v := &pb.List{v1}
dst1 := &pb.List{}
dst2 := &pb.List{}
compressedUids := bp128.DeltaPack(v1)

fmt.Printf("len: %d, compressed: %d, bytes/int: %f\n",
Expand Down
12 changes: 6 additions & 6 deletions conn/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/coreos/etcd/raft/raftpb"
"github.com/dgraph-io/badger/y"
"github.com/dgraph-io/dgo/protos/api"
"github.com/dgraph-io/dgraph/protos/intern"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/raftwal"
"github.com/dgraph-io/dgraph/x"
"github.com/golang/glog"
Expand Down Expand Up @@ -51,7 +51,7 @@ type Node struct {
peers map[uint64]string
confChanges map[uint64]chan error
messages chan sendmsg
RaftContext *intern.RaftContext
RaftContext *pb.RaftContext
Store *raftwal.DiskStorage
Rand *rand.Rand

Expand All @@ -62,7 +62,7 @@ type Node struct {
Applied x.WaterMark
}

func NewNode(rc *intern.RaftContext, store *raftwal.DiskStorage) *Node {
func NewNode(rc *pb.RaftContext, store *raftwal.DiskStorage) *Node {
snap, err := store.Snapshot()
x.Check(err)

Expand Down Expand Up @@ -332,9 +332,9 @@ func (n *Node) doSendMessage(pool *Pool, data []byte) {

client := pool.Get()

c := intern.NewRaftClient(client)
c := pb.NewRaftClient(client)
p := &api.Payload{Data: data}
batch := &intern.RaftBatch{
batch := &pb.RaftBatch{
Context: n.RaftContext,
Payload: p,
}
Expand Down Expand Up @@ -415,7 +415,7 @@ func (n *Node) proposeConfChange(ctx context.Context, pb raftpb.ConfChange) erro
func (n *Node) AddToCluster(ctx context.Context, pid uint64) error {
addr, ok := n.Peer(pid)
x.AssertTruef(ok, "Unable to find conn pool for peer: %d", pid)
rc := &intern.RaftContext{
rc := &pb.RaftContext{
Addr: addr,
Group: n.RaftContext.Group,
Id: pid,
Expand Down
Loading