dgraph-io / ristretto

A high performance memory-bound Go cache

Home Page:https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race in cache.clear

jarifibrahim opened this issue · comments

The following race condition was seen in badger on PR dgraph-io/badger#1066

------- Stdout: -------
=== RUN   TestDropAllWithPendingTxn
badger 2019/10/21 08:34:34 INFO: All 0 tables opened in 0s
badger 2019/10/21 08:34:35 DEBUG: Flushing memtable, mt.size=34867 size of flushChan: 0
badger 2019/10/21 08:34:35 DEBUG: Storing value log head: {Fid:0 Len:30 Offset:4831937}
badger 2019/10/21 08:34:35 DEBUG: Storing value log head: {Fid:1 Len:30 Offset:4026620}
badger 2019/10/21 08:34:35 DEBUG: Flushing memtable, mt.size=34837 size of flushChan: 0
badger 2019/10/21 08:34:35 DEBUG: Storing value log head: {Fid:2 Len:30 Offset:3221294}
badger 2019/10/21 08:34:35 DEBUG: Flushing memtable, mt.size=34825 size of flushChan: 0
badger 2019/10/21 08:34:36 DEBUG: Storing value log head: {Fid:3 Len:30 Offset:2415968}
badger 2019/10/21 08:34:36 DEBUG: Flushing memtable, mt.size=34777 size of flushChan: 0
badger 2019/10/21 08:34:36 DEBUG: Storing value log head: {Fid:4 Len:30 Offset:1610642}
badger 2019/10/21 08:34:36 DEBUG: Flushing memtable, mt.size=34757 size of flushChan: 0
badger 2019/10/21 08:34:36 DEBUG: Storing value log head: {Fid:5 Len:30 Offset:805316}
badger 2019/10/21 08:34:36 DEBUG: Flushing memtable, mt.size=34753 size of flushChan: 0
badger 2019/10/21 08:34:36 INFO: Got compaction priority: {level:0 score:1.2 dropPrefix:[]}
badger 2019/10/21 08:34:36 INFO: Running for level: 0
badger 2019/10/21 08:34:36 DEBUG: LOG Compact. Added 3534 keys. Skipped 0 keys. Iteration took: 47.099272ms
badger 2019/10/21 08:34:36 DEBUG: Discard stats: map[]
badger 2019/10/21 08:34:36 INFO: LOG Compact 0->1, del 6 tables, add 1 tables, took 64.409113ms
badger 2019/10/21 08:34:36 INFO: Compaction for level: 0 DONE
badger 2019/10/21 08:34:37 DEBUG: Flushing memtable, mt.size=34895 size of flushChan: 0
badger 2019/10/21 08:34:37 DEBUG: Storing value log head: {Fid:5 Len:30 Offset:5637272}
badger 2019/10/21 08:34:37 DEBUG: Flushing memtable, mt.size=34775 size of flushChan: 0
badger 2019/10/21 08:34:37 DEBUG: Storing value log head: {Fid:6 Len:30 Offset:4831946}
badger 2019/10/21 08:34:37 DEBUG: Storing value log head: {Fid:7 Len:31 Offset:4026628}
badger 2019/10/21 08:34:37 DEBUG: Flushing memtable, mt.size=34753 size of flushChan: 0
badger 2019/10/21 08:34:38 DEBUG: Flushing memtable, mt.size=29077 size of flushChan: 0
badger 2019/10/21 08:34:38 DEBUG: Storing value log head: {Fid:8 Len:31 Offset:2415973}
badger 2019/10/21 08:34:38 DEBUG: Storing value log head: {Fid:9 Len:31 Offset:1610645}
badger 2019/10/21 08:34:38 DEBUG: Flushing memtable, mt.size=34745 size of flushChan: 0
badger 2019/10/21 08:34:38 DEBUG: Storing value log head: {Fid:10 Len:31 Offset:805317}
badger 2019/10/21 08:34:38 DEBUG: Flushing memtable, mt.size=34945 size of flushChan: 0
badger 2019/10/21 08:34:38 INFO: Got compaction priority: {level:0 score:1.2 dropPrefix:[]}
badger 2019/10/21 08:34:38 INFO: Running for level: 0
badger 2019/10/21 08:34:38 DEBUG: LOG Compact. Added 3603 keys. Skipped 0 keys. Iteration took: 40.49591ms
badger 2019/10/21 08:34:38 DEBUG: LOG Compact. Added 3367 keys. Skipped 0 keys. Iteration took: 29.324284ms
badger 2019/10/21 08:34:38 DEBUG: Discard stats: map[]
badger 2019/10/21 08:34:38 INFO: LOG Compact 0->1, del 7 tables, add 2 tables, took 84.556191ms
badger 2019/10/21 08:34:38 INFO: Compaction for level: 0 DONE
badger 2019/10/21 08:34:39 DEBUG: Flushing memtable, mt.size=34643 size of flushChan: 0
badger 2019/10/21 08:34:39 DEBUG: Storing value log head: {Fid:10 Len:31 Offset:5637285}
badger 2019/10/21 08:34:39 DEBUG: Flushing memtable, mt.size=34795 size of flushChan: 0
badger 2019/10/21 08:34:39 DEBUG: Storing value log head: {Fid:11 Len:31 Offset:4831957}
badger 2019/10/21 08:34:39 DEBUG: Flushing memtable, mt.size=34803 size of flushChan: 0
badger 2019/10/21 08:34:39 DEBUG: Storing value log head: {Fid:12 Len:31 Offset:4026629}
badger 2019/10/21 08:34:40 DEBUG: Storing value log head: {Fid:13 Len:31 Offset:3221301}
badger 2019/10/21 08:34:40 DEBUG: Flushing memtable, mt.size=34793 size of flushChan: 0
badger 2019/10/21 08:34:40 DEBUG: Storing value log head: {Fid:14 Len:31 Offset:2415973}
badger 2019/10/21 08:34:40 DEBUG: Flushing memtable, mt.size=34805 size of flushChan: 0
badger 2019/10/21 08:34:40 INFO: Got compaction priority: {level:0 score:1 dropPrefix:[]}
badger 2019/10/21 08:34:40 INFO: Running for level: 0
badger 2019/10/21 08:34:40 DEBUG: LOG Compact. Added 3603 keys. Skipped 0 keys. Iteration took: 44.412168ms
badger 2019/10/21 08:34:40 DEBUG: LOG Compact. Added 3607 keys. Skipped 0 keys. Iteration took: 39.613965ms
badger 2019/10/21 08:34:40 DEBUG: LOG Compact. Added 2705 keys. Skipped 0 keys. Iteration took: 28.006555ms
badger 2019/10/21 08:34:40 DEBUG: Discard stats: map[]
badger 2019/10/21 08:34:40 INFO: LOG Compact 0->1, del 7 tables, add 3 tables, took 127.699034ms
badger 2019/10/21 08:34:40 INFO: Compaction for level: 0 DONE
badger 2019/10/21 08:34:43 INFO: DropAll called. Blocking writes...
badger 2019/10/21 08:34:43 INFO: Writes flushed. Stopping compactions now...
badger 2019/10/21 08:34:43 INFO: Deleted 3 SSTables. Now deleting value logs...
badger 2019/10/21 08:34:43 INFO: Value logs deleted. Creating value log file: 0
badger 2019/10/21 08:34:43 INFO: Deleted 15 value log files. DropAll done.
==================
WARNING: DATA RACE
Write at 0x00c174a2fc50 by goroutine 40:
  github.com/dgraph-io/ristretto.(*Cache).collectMetrics()
      /home/pawan0201/go/src/github.com/dgraph-io/ristretto/cache.go:287 +0x55
  github.com/dgraph-io/ristretto.(*Cache).Clear()
      /home/pawan0201/go/src/github.com/dgraph-io/ristretto/cache.go:241 +0x14e
  github.com/dgraph-io/badger.(*DB).dropAll()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/db.go:1472 +0x556
  github.com/dgraph-io/badger.(*DB).DropAll()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/db.go:1428 +0x44
  github.com/dgraph-io/badger.TestDropAllWithPendingTxn.func4()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/managed_db_test.go:236 +0x6f

Previous read at 0x00c174a2fc50 by goroutine 253:
  github.com/dgraph-io/ristretto.(*Cache).Get()
      /home/pawan0201/go/src/github.com/dgraph-io/ristretto/cache.go:167 +0x103
  github.com/dgraph-io/badger/table.(*Table).block()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/table/table.go:364 +0x164c
  github.com/dgraph-io/badger/table.(*Iterator).next()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/table/iterator.go:296 +0x216
  github.com/dgraph-io/badger/table.(*Iterator).next()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/table/iterator.go:311 +0x6a6
  github.com/dgraph-io/badger/table.(*Iterator).Next()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/table/iterator.go:367 +0x70
  github.com/dgraph-io/badger/table.(*ConcatIterator).Next()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/table/iterator.go:485 +0x59
  github.com/dgraph-io/badger/y.(*MergeIterator).Next()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/y/iterator.go:216 +0xca
  github.com/dgraph-io/badger.(*Iterator).parseItem()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/iterator.go:647 +0x98e
  github.com/dgraph-io/badger.(*Iterator).Next()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/iterator.go:560 +0x20c
  github.com/dgraph-io/badger.TestDropAllWithPendingTxn.func3()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/managed_db_test.go:206 +0x157

Goroutine 40 (running) created at:
  github.com/dgraph-io/badger.TestDropAllWithPendingTxn()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/managed_db_test.go:233 +0x428
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:865 +0x163

Goroutine 253 (running) created at:
  github.com/dgraph-io/badger.TestDropAllWithPendingTxn()
      /home/pawan0201/go/src/github.com/dgraph-io/badger/managed_db_test.go:198 +0x3cf
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:865 +0x163
==================
badger 2019/10/21 08:34:43 INFO: Resuming writes
badger 2019/10/21 08:34:44 INFO: Got compaction priority: {level:0 score:1.73 dropPrefix:[]}
--- FAIL: TestDropAllWithPendingTxn (9.40s)
    managed_db_test.go:216: Got number of keys: 10000
    managed_db_test.go:216: Got number of keys: 10000
    managed_db_test.go:220: Got error during key lookup: Key not found
    testing.go:809: race detected during execution of test

https://teamcity.dgraph.io/viewLog.html?buildId=29213&buildTypeId=Badger_UnitTests&tab=buildResultsDiv