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

Function TestDropPrefixWithPendingTxn

managed_db_test.go:427–497  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

425}
426
427func TestDropPrefixWithPendingTxn(t *testing.T) {
428 dir, err := ioutil.TempDir("", "badger-test")
429 require.NoError(t, err)
430 defer removeDir(dir)
431 opts := getTestOptions(dir)
432 opts.ValueLogFileSize = 5 << 20
433 db, err := Open(opts)
434 require.NoError(t, err)
435 defer func() {
436 require.NoError(t, db.Close())
437 }()
438
439 N := uint64(10000)
440 populate := func(db *DB) {
441 writer := db.NewWriteBatch()
442 for i := uint64(0); i < N; i++ {
443 require.NoError(t, writer.Set([]byte(key("key", int(i))), val(true)))
444 }
445 require.NoError(t, writer.Flush())
446 }
447
448 populate(db)
449 require.Equal(t, int(N), numKeys(db))
450
451 txn := db.NewTransaction(true)
452
453 var wg sync.WaitGroup
454 wg.Add(2)
455 go func() {
456 defer wg.Done()
457 itr := txn.NewIterator(DefaultIteratorOptions)
458 defer itr.Close()
459
460 var keys []string
461 for {
462 var count int
463 for itr.Rewind(); itr.Valid(); itr.Next() {
464 count++
465 item := itr.Item()
466 keys = append(keys, string(item.KeyCopy(nil)))
467 _, err := item.ValueCopy(nil)
468 if err != nil {
469 t.Logf("Got error during value copy: %v", err)
470 return
471 }
472 }
473 t.Logf("Got number of keys: %d\n", count)
474 for _, key := range keys {
475 item, err := txn.Get([]byte(key))
476 if err != nil {
477 t.Logf("Got error during key lookup: %v", err)
478 return
479 }
480 if _, err := item.ValueCopy(nil); err != nil {
481 t.Logf("Got error during second value copy: %v", err)
482 return
483 }
484 }

Callers

nothing calls this directly

Calls 15

SetMethod · 0.95
FlushMethod · 0.95
CloseMethod · 0.95
RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
removeDirFunction · 0.85
getTestOptionsFunction · 0.85
OpenFunction · 0.85
valFunction · 0.85
numKeysFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…