MCPcopy
hub / github.com/dgraph-io/badger / TestWriteDeadlock

Function TestWriteDeadlock

db_test.go:1446–1497  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1444}
1445
1446func TestWriteDeadlock(t *testing.T) {
1447 dir, err := ioutil.TempDir("", "badger-test")
1448 require.NoError(t, err)
1449 defer removeDir(dir)
1450
1451 db, err := Open(DefaultOptions(dir).WithValueLogFileSize(10 << 20))
1452 require.NoError(t, err)
1453 defer db.Close()
1454 print := func(count *int) {
1455 *count++
1456 if *count%100 == 0 {
1457 fmt.Printf("%05d\r", *count)
1458 }
1459 }
1460
1461 var count int
1462 val := make([]byte, 10000)
1463 require.NoError(t, db.Update(func(txn *Txn) error {
1464 for i := 0; i < 1500; i++ {
1465 key := fmt.Sprintf("%d", i)
1466 rand.Read(val)
1467 require.NoError(t, txn.SetEntry(NewEntry([]byte(key), val)))
1468 print(&count)
1469 }
1470 return nil
1471 }))
1472
1473 count = 0
1474 fmt.Println("\nWrites done. Iteration and updates starting...")
1475 err = db.Update(func(txn *Txn) error {
1476 opt := DefaultIteratorOptions
1477 opt.PrefetchValues = false
1478 it := txn.NewIterator(opt)
1479 defer it.Close()
1480 for it.Rewind(); it.Valid(); it.Next() {
1481 item := it.Item()
1482
1483 // Using Value() would cause deadlock.
1484 // item.Value()
1485 out, err := item.ValueCopy(nil)
1486 require.NoError(t, err)
1487 require.Equal(t, len(val), len(out))
1488
1489 key := y.Copy(item.Key())
1490 rand.Read(val)
1491 require.NoError(t, txn.SetEntry(NewEntry(key, val)))
1492 print(&count)
1493 }
1494 return nil
1495 })
1496 require.NoError(t, err)
1497}
1498
1499func TestSequence(t *testing.T) {
1500 key0 := []byte("seq0")

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
CopyFunction · 0.92
removeDirFunction · 0.85
OpenFunction · 0.85
DefaultOptionsFunction · 0.85
NewEntryFunction · 0.85
WithValueLogFileSizeMethod · 0.80
PrintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…