Skip to content

Commit 2c1e40a

Browse files
Harshil Goelharshil-goel
Harshil Goel
authored andcommitted
Use get batch api badger
1 parent 15ba2a3 commit 2c1e40a

File tree

5 files changed

+141
-45
lines changed

5 files changed

+141
-45
lines changed

go.mod

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/hypermodeinc/dgraph/v24
22

3-
go 1.22.11
3+
go 1.22.12
44

55
require (
66
contrib.go.opencensus.io/exporter/jaeger v0.2.1
@@ -10,7 +10,7 @@ require (
1010
github.com/IBM/sarama v1.45.0
1111
github.com/Masterminds/semver/v3 v3.3.1
1212
github.com/blevesearch/bleve/v2 v2.4.4
13-
github.com/dgraph-io/badger/v4 v4.5.1
13+
github.com/dgraph-io/badger/v4 v4.5.2-0.20250218121059-0faedd88140e
1414
github.com/dgraph-io/dgo/v240 v240.1.0
1515
github.com/dgraph-io/gqlgen v0.13.2
1616
github.com/dgraph-io/gqlparser/v2 v2.2.2
@@ -53,17 +53,17 @@ require (
5353
go.etcd.io/etcd/raft/v3 v3.5.18
5454
go.opencensus.io v0.24.0
5555
go.uber.org/zap v1.27.0
56-
golang.org/x/crypto v0.32.0
56+
golang.org/x/crypto v0.33.0
5757
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c
5858
golang.org/x/mod v0.22.0
59-
golang.org/x/net v0.34.0
59+
golang.org/x/net v0.35.0
6060
golang.org/x/sync v0.11.0
6161
golang.org/x/sys v0.30.0
62-
golang.org/x/term v0.28.0
63-
golang.org/x/text v0.21.0
62+
golang.org/x/term v0.29.0
63+
golang.org/x/text v0.22.0
6464
golang.org/x/tools v0.29.0
6565
google.golang.org/grpc v1.70.0
66-
google.golang.org/protobuf v1.36.4
66+
google.golang.org/protobuf v1.36.5
6767
gopkg.in/yaml.v3 v3.0.1
6868
)
6969

@@ -98,7 +98,7 @@ require (
9898
github.com/gogo/protobuf v1.3.2 // indirect
9999
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
100100
github.com/golang/protobuf v1.5.4 // indirect
101-
github.com/google/flatbuffers v25.1.24+incompatible // indirect
101+
github.com/google/flatbuffers v25.2.10+incompatible // indirect
102102
github.com/google/pprof v0.0.0-20250128161936-077ca0a936bf // indirect
103103
github.com/hashicorp/errwrap v1.1.0 // indirect
104104
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -156,7 +156,6 @@ require (
156156
go.opentelemetry.io/otel v1.34.0 // indirect
157157
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.34.0 // indirect
158158
go.opentelemetry.io/otel/metric v1.34.0 // indirect
159-
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
160159
go.opentelemetry.io/otel/trace v1.34.0 // indirect
161160
go.uber.org/multierr v1.11.0 // indirect
162161
golang.org/x/time v0.9.0 // indirect

go.sum

+14-14
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
127127
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
128128
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
129129
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
130-
github.com/dgraph-io/badger/v4 v4.5.1 h1:7DCIXrQjo1LKmM96YD+hLVJ2EEsyyoWxJfpdd56HLps=
131-
github.com/dgraph-io/badger/v4 v4.5.1/go.mod h1:qn3Be0j3TfV4kPbVoK0arXCD1/nr1ftth6sbL5jxdoA=
130+
github.com/dgraph-io/badger/v4 v4.5.2-0.20250218121059-0faedd88140e h1:sZmnvDqloFjehWjr6f/G5O8ANbhenwSYdkGxkTR2Bww=
131+
github.com/dgraph-io/badger/v4 v4.5.2-0.20250218121059-0faedd88140e/go.mod h1:aSwx/bXKT3/WRl9rn2BrTU+tfRQlFPKlOsqRTdcpHB8=
132132
github.com/dgraph-io/dgo/v240 v240.1.0 h1:xd8z9kEXDWOAblaLJ2HLg2tXD6ngMQwq3ehLUS7GKNg=
133133
github.com/dgraph-io/dgo/v240 v240.1.0/go.mod h1:r8WASETKfodzKqThSAhhTNIzcEMychArKKlZXQufWuA=
134134
github.com/dgraph-io/gqlgen v0.13.2 h1:TNhndk+eHKj5qE7BenKKSYdSIdOGhLqxR1rCiMso9KM=
@@ -267,8 +267,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
267267
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
268268
github.com/google/codesearch v1.2.0 h1:VlyAH+AntnIbGGArOUs6sEBdPVwYvf1e8Uw3/TC77cA=
269269
github.com/google/codesearch v1.2.0/go.mod h1:9wQjQDVAP7Mvt96tw1KqVeXncdBLOWUYdxRiHlsG6Xc=
270-
github.com/google/flatbuffers v25.1.24+incompatible h1:4wPqL3K7GzBd1CwyhSd3usxLKOaJN/AC6puCca6Jm7o=
271-
github.com/google/flatbuffers v25.1.24+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
270+
github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q=
271+
github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
272272
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
273273
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
274274
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
@@ -647,8 +647,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
647647
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
648648
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
649649
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
650-
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
651-
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
650+
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
651+
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
652652
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
653653
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
654654
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -728,8 +728,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
728728
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
729729
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
730730
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
731-
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
732-
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
731+
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
732+
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
733733
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
734734
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
735735
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -804,8 +804,8 @@ golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
804804
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
805805
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
806806
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
807-
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
808-
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
807+
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
808+
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
809809
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
810810
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
811811
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -814,8 +814,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
814814
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
815815
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
816816
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
817-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
818-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
817+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
818+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
819819
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
820820
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
821821
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -969,8 +969,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
969969
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
970970
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
971971
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
972-
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
973-
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
972+
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
973+
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
974974
gopkg.in/DataDog/dd-trace-go.v1 v1.22.0/go.mod h1:DVp8HmDh8PuTu2Z0fVVlBsyWaC++fzwVCaGWylTe3tg=
975975
gopkg.in/DataDog/dd-trace-go.v1 v1.71.0 h1:+Lr4YwJQGZuIOoIFNjMY5l7bGZblbKrwMtmbIiWFmjI=
976976
gopkg.in/DataDog/dd-trace-go.v1 v1.71.0/go.mod h1:0M7D+g0aTIlQgxqTSWrmTjssl+POsL5TVDaX2QFKk4U=

posting/list_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ func TestAddMutation_mrjn1(t *testing.T) {
493493
func TestReadSingleValue(t *testing.T) {
494494
defer setMaxListSize(maxListSize)
495495
maxListSize = math.MaxInt32
496+
<<<<<<< HEAD
496497
require.Equal(t, nil, pstore.DropAll())
498+
=======
499+
>>>>>>> 6fbd525d2 (Use get batch api badger)
497500

498501
// We call pl.Iterate and then stop iterating in the first loop when we are reading
499502
// single values. This test confirms that the two functions, getFirst from this file
@@ -502,6 +505,7 @@ func TestReadSingleValue(t *testing.T) {
502505
key := x.DataKey(x.GalaxyAttr("value"), 1240)
503506
ol, err := getNew(key, ps, math.MaxUint64)
504507
require.NoError(t, err)
508+
<<<<<<< HEAD
505509
N := uint64(10000)
506510
for i := uint64(2); i <= N; i += 2 {
507511
edge := &pb.DirectedEdge{
@@ -514,6 +518,19 @@ func TestReadSingleValue(t *testing.T) {
514518
kData := ol.getMutation(i + 1)
515519
writer := NewTxnWriter(pstore)
516520
if err := writer.SetAt(key, kData, BitDeltaPosting, i+1); err != nil {
521+
=======
522+
N := int(10000)
523+
for i := 2; i <= N; i += 2 {
524+
edge := &pb.DirectedEdge{
525+
Value: []byte("ho hey there" + strconv.Itoa(i)),
526+
}
527+
txn := Txn{StartTs: uint64(i)}
528+
addMutationHelper(t, ol, edge, Set, &txn)
529+
require.NoError(t, ol.commitMutation(uint64(i), uint64(i)+1))
530+
kData := ol.getMutation(uint64(i))
531+
writer := NewTxnWriter(pstore)
532+
if err := writer.SetAt(key, kData, BitDeltaPosting, uint64(i)); err != nil {
533+
>>>>>>> 6fbd525d2 (Use get batch api badger)
517534
require.NoError(t, err)
518535
}
519536
writer.Flush()
@@ -523,12 +540,16 @@ func TestReadSingleValue(t *testing.T) {
523540
kvs, err := ol.Rollup(nil, txn.StartTs-3)
524541
require.NoError(t, err)
525542
require.NoError(t, writePostingListToDisk(kvs))
543+
<<<<<<< HEAD
526544
// Delete item from global cache before reading, as we are not updating the cache in the test
527545
memoryLayer.del(key)
546+
=======
547+
>>>>>>> 6fbd525d2 (Use get batch api badger)
528548
ol, err = getNew(key, ps, math.MaxUint64)
529549
require.NoError(t, err)
530550
}
531551

552+
<<<<<<< HEAD
532553
j := uint64(3)
533554
if j < ol.minTs {
534555
j = ol.minTs
@@ -538,6 +559,17 @@ func TestReadSingleValue(t *testing.T) {
538559
k, err := tx.cache.GetSinglePosting(key)
539560
require.NoError(t, err)
540561
checkValue(t, ol, string(k.Postings[0].Value), j)
562+
=======
563+
j := 2
564+
if j < int(ol.minTs) {
565+
j = int(ol.minTs)
566+
}
567+
for ; j < i+6; j++ {
568+
tx := NewTxn(uint64(j))
569+
k, err := tx.cache.GetSinglePosting(key)
570+
require.NoError(t, err)
571+
checkValue(t, ol, string(k.Postings[0].Value), uint64(j))
572+
>>>>>>> 6fbd525d2 (Use get batch api badger)
541573
}
542574
}
543575
}

posting/lists.go

+72-19
Original file line numberDiff line numberDiff line change
@@ -320,32 +320,32 @@ func (lc *LocalCache) readPostingListAt(key []byte) (*pb.PostingList, error) {
320320
return pl, err
321321
}
322322

323-
// GetSinglePosting retrieves the cached version of the first item in the list associated with the
324-
// given key. This is used for retrieving the value of a scalar predicats.
325-
func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
326-
// This would return an error if there is some data in the local cache, but we couldn't read it.
327-
getListFromLocalCache := func() (*pb.PostingList, error) {
328-
lc.RLock()
329-
330-
pl := &pb.PostingList{}
331-
if delta, ok := lc.deltas[string(key)]; ok && len(delta) > 0 {
332-
err := proto.Unmarshal(delta, pl)
333-
lc.RUnlock()
334-
return pl, err
335-
}
323+
func (lc *LocalCache) GetSinglePostingFromLocalCache(key []byte) (*pb.PostingList, error) {
324+
lc.RLock()
336325

337-
l := lc.plists[string(key)]
326+
pl := &pb.PostingList{}
327+
if delta, ok := lc.deltas[string(key)]; ok && len(delta) > 0 {
328+
err := proto.Unmarshal(delta, pl)
338329
lc.RUnlock()
330+
return pl, err
331+
}
339332

340-
if l != nil {
341-
return l.StaticValue(lc.startTs)
342-
}
333+
l := lc.plists[string(key)]
334+
lc.RUnlock()
343335

344-
return nil, nil
336+
if l != nil {
337+
return l.StaticValue(lc.startTs)
345338
}
346339

340+
return nil, nil
341+
}
342+
343+
// GetSinglePosting retrieves the cached version of the first item in the list associated with the
344+
// given key. This is used for retrieving the value of a scalar predicats.
345+
func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
346+
// This would return an error if there is some data in the local cache, but we couldn't read it.
347347
getPostings := func() (*pb.PostingList, error) {
348-
pl, err := getListFromLocalCache()
348+
pl, err := lc.GetSinglePostingFromLocalCache(key)
349349
// If both pl and err are empty, that means that there was no data in local cache, hence we should
350350
// read the data from badger.
351351
if pl != nil || err != nil {
@@ -378,6 +378,59 @@ func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
378378
return pl, nil
379379
}
380380

381+
func (lc *LocalCache) GetBatchSinglePosting(keys [][]byte) ([]*pb.PostingList, error) {
382+
results := make([]*pb.PostingList, len(keys))
383+
remaining_keys := make([][]byte, 0)
384+
for i, key := range keys {
385+
if pl, err := lc.GetSinglePostingFromLocalCache(key); pl != nil && err != nil {
386+
results[i] = pl
387+
} else {
388+
remaining_keys = append(remaining_keys, key)
389+
}
390+
}
391+
392+
txn := pstore.NewTransactionAt(lc.startTs, false)
393+
items, err := txn.GetBatch(remaining_keys)
394+
if err != nil {
395+
fmt.Println(err, keys)
396+
return nil, err
397+
}
398+
idx := 0
399+
400+
for i := 0; i < len(results); i++ {
401+
if results[i] != nil {
402+
continue
403+
}
404+
pl := &pb.PostingList{}
405+
err = items[idx].Value(func(val []byte) error {
406+
if err := proto.Unmarshal(val, pl); err != nil {
407+
return err
408+
}
409+
return nil
410+
})
411+
idx += 1
412+
results[i] = pl
413+
}
414+
415+
for i := 0; i < len(results); i++ {
416+
pl := results[i]
417+
idx := 0
418+
for _, postings := range pl.Postings {
419+
if hasDeleteAll(postings) {
420+
return nil, nil
421+
}
422+
if postings.Op != Del {
423+
pl.Postings[idx] = postings
424+
idx++
425+
}
426+
}
427+
pl.Postings = pl.Postings[:idx]
428+
results[i] = pl
429+
}
430+
431+
return results, err
432+
}
433+
381434
// Get retrieves the cached version of the list associated with the given key.
382435
func (lc *LocalCache) Get(key []byte) (*List, error) {
383436
return lc.getInternal(key, true)

worker/task.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
423423
out := &pb.Result{}
424424
outputs[start/width] = out
425425

426+
cache := make([]*pb.PostingList, 0)
426427
for i := start; i < end; i++ {
427428
select {
428429
case <-ctx.Done():
@@ -437,9 +438,20 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
437438
fcs := &pb.FacetsList{FacetsList: make([]*pb.Facets, 0)} // TODO Figure out how it is stored
438439

439440
if !getMultiplePosting {
440-
pl, err := qs.cache.GetSinglePosting(key)
441-
if err != nil {
442-
return err
441+
if len(cache) == 0 {
442+
keys := make([][]byte, 10)
443+
keys[0] = key
444+
for j := i + 1; j < i+10 && j < end; j++ {
445+
keys[j-i] = x.DataKey(q.Attr, q.UidList.Uids[j])
446+
}
447+
cache, err = qs.cache.GetBatchSinglePosting(keys)
448+
if err != nil {
449+
return err
450+
}
451+
}
452+
pl := cache[0]
453+
if len(cache) > 1 {
454+
cache = cache[1:]
443455
}
444456
if pl == nil || len(pl.Postings) == 0 {
445457
out.UidMatrix = append(out.UidMatrix, &pb.List{})

0 commit comments

Comments
 (0)