Skip to content

Commit

Permalink
added async cache
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Dec 25, 2024
1 parent e8a0249 commit 3f371a2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/dgraph-io/gqlgen v0.13.2
github.com/dgraph-io/gqlparser/v2 v2.2.2
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15
github.com/dgraph-io/ristretto/v2 v2.0.1-0.20241207103255-02acef2e21af
github.com/dgraph-io/ristretto/v2 v2.0.1-0.20241225051636-a881a3ee595b
github.com/dgraph-io/simdjson-go v0.3.0
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da
github.com/dgryski/go-groupvarint v0.0.0-20230630160417-2bfb7969fb3c
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ github.com/dgraph-io/gqlparser/v2 v2.2.2 h1:CnxXOKL4EPguKqcGV/z4u4VoW5izUkOTIsNM
github.com/dgraph-io/gqlparser/v2 v2.2.2/go.mod h1:MYS4jppjyx8b9tuUtjV7jU1UFZK6P9fvO8TsIsQtRKU=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15 h1:X2NRsgAtVUAp2nmTPCq+x+wTcRRrj74CEpy7E0Unsl4=
github.com/dgraph-io/graphql-transport-ws v0.0.0-20210511143556-2cef522f1f15/go.mod h1:7z3c/5w0sMYYZF5bHsrh8IH4fKwG5O5Y70cPH1ZLLRQ=
github.com/dgraph-io/ristretto/v2 v2.0.1 h1:7W0LfEP+USCmtrUjJsk+Jv2jbhJmb72N4yRI7GrLdMI=
github.com/dgraph-io/ristretto/v2 v2.0.1/go.mod h1:K7caLeufSdxm+ITp1n/73U+VbFVAHrexfLbz4n14hpo=
github.com/dgraph-io/ristretto/v2 v2.0.1-0.20241207103255-02acef2e21af h1:oh/6dn0uitvGURnZ8CaRaEiIgvboLJv4N4PjYulkvis=
github.com/dgraph-io/ristretto/v2 v2.0.1-0.20241207103255-02acef2e21af/go.mod h1:K7caLeufSdxm+ITp1n/73U+VbFVAHrexfLbz4n14hpo=
github.com/dgraph-io/ristretto/v2 v2.0.1-0.20241225051636-a881a3ee595b h1:HFfYu0UFFwjUU2q63wTtNtc4vXQbw55m2WVoMcFXhzA=
github.com/dgraph-io/ristretto/v2 v2.0.1-0.20241225051636-a881a3ee595b/go.mod h1:K7caLeufSdxm+ITp1n/73U+VbFVAHrexfLbz4n14hpo=
github.com/dgraph-io/ristretto/v2 v2.0.1 h1:7W0LfEP+USCmtrUjJsk+Jv2jbhJmb72N4yRI7GrLdMI=
github.com/dgraph-io/ristretto/v2 v2.0.1/go.mod h1:K7caLeufSdxm+ITp1n/73U+VbFVAHrexfLbz4n14hpo=
github.com/dgraph-io/simdjson-go v0.3.0 h1:h71LO7vR4LHMPUhuoGN8bqGm1VNfGOlAG8BI6iDUKw0=
github.com/dgraph-io/simdjson-go v0.3.0/go.mod h1:Otpysdjaxj9OGaJusn4pgQV7OFh2bELuHANq0I78uvY=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down
2 changes: 2 additions & 0 deletions posting/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func addEdgeToUID(t *testing.T, attr string, src uint64,

func TestCountReverseIndexWithData(t *testing.T) {
require.NoError(t, pstore.DropAll())
memoryLayer.clear()
indexNameCountVal := "testcount: [uid] @count @reverse ."

attr := x.GalaxyAttr("testcount")
Expand Down Expand Up @@ -306,6 +307,7 @@ func TestCountReverseIndexWithData(t *testing.T) {

func TestCountReverseIndexEmptyPosting(t *testing.T) {
require.NoError(t, pstore.DropAll())
memoryLayer.clear()
indexNameCountVal := "testcount: [uid] @count @reverse ."

attr := x.GalaxyAttr("testcount")
Expand Down
3 changes: 3 additions & 0 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ func (l *List) setMutationAfterCommit(startTs, commitTs uint64, pl *pb.PostingLi
}

l.mutationMap.committedUids[mpost.Uid] = mpost
if l.mutationMap.length == math.MaxInt64 {
l.mutationMap.length = 0
}
l.mutationMap.length += getLengthDelta(mpost.Op)
}

Expand Down
2 changes: 1 addition & 1 deletion posting/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ func TestAddMutation_mrjn1(t *testing.T) {
func TestReadSingleValue(t *testing.T) {
defer setMaxListSize(maxListSize)
maxListSize = math.MaxInt32
pstore.DropAll()

Check failure on line 510 in posting/list_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `pstore.DropAll` is not checked (errcheck)

// We call pl.Iterate and then stop iterating in the first loop when we are reading
// single values. This test confirms that the two functions, getFirst from this file
Expand Down Expand Up @@ -546,7 +547,6 @@ func TestReadSingleValue(t *testing.T) {
j = ol.minTs
}
for ; j < i+6; j++ {
ResetCache()
tx := NewTxn(j)
k, err := tx.cache.GetSinglePosting(key)
require.NoError(t, err)
Expand Down
21 changes: 9 additions & 12 deletions posting/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (sm *MemoryLayer) get(key []byte) (*CachePL, bool) {
}

func (sm *MemoryLayer) set(key []byte, i *CachePL) {
sm.cache.Set(key, i, 1)
sm.cache.AsyncSet(key, i, 1)
}

func (sm *MemoryLayer) del(key []byte) {
Expand Down Expand Up @@ -459,7 +459,6 @@ func checkForRollup(key []byte, l *List) {
}

func (ml *MemoryLayer) wait() {
ml.cache.Wait()
}

func (ml *MemoryLayer) updateItemInCache(key string, pk x.ParsedKey, delta []byte, startTs, commitTs uint64) {
Expand All @@ -469,9 +468,10 @@ func (ml *MemoryLayer) updateItemInCache(key string, pk x.ParsedKey, delta []byt

updateItemAfterCommit := true

p := new(pb.PostingList)
x.Check(proto.Unmarshal(delta, p))
//fmt.Println("======COMMITTING", startTs, commitTs, pk, p)
if !updateItemAfterCommit {
ml.del([]byte(key))
return
}

val, ok := ml.get([]byte(key))
if !ok {
Expand All @@ -482,16 +482,13 @@ func (ml *MemoryLayer) updateItemInCache(key string, pk x.ParsedKey, delta []byt
val.count -= 1

if val.list != nil && updateItemAfterCommit {
p := new(pb.PostingList)
x.Check(proto.Unmarshal(delta, p))
//fmt.Println("======COMMITTING", startTs, commitTs, pk, p)

val.list.setMutationAfterCommit(startTs, commitTs, p, true)
checkForRollup([]byte(key), val.list)
}

if !updateItemAfterCommit {
if val.list != nil {
val.list.markDeleted()
}
ml.del([]byte(key))
}
}

// RemoveCachedKeys will delete the cached list by this txn.
Expand Down

0 comments on commit 3f371a2

Please sign in to comment.