MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / TestDB_HintFileDisabled

Function TestDB_HintFileDisabled

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

Source from the content-addressed store, hash-verified

2542}
2543
2544func TestDB_HintFileDisabled(t *testing.T) {
2545 bucket := "bucket"
2546 opts := DefaultOptions
2547 opts.SegmentSize = KB
2548 opts.Dir = filepath.Join(t.TempDir(), "test-hintfile-disabled-recovery")
2549 opts.EnableHintFile = false // Disable hint file
2550
2551 // Clean the test directory at the start
2552 removeDir(opts.Dir)
2553
2554 // Create a database with some data
2555 db, err := Open(opts)
2556 require.NoError(t, err)
2557 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
2558
2559 // Add some data
2560 n := 100
2561 for i := 0; i < n; i++ {
2562 txPut(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), Persistent, nil, nil)
2563 }
2564
2565 // Perform merge - should not create hint files
2566 require.NoError(t, db.Merge())
2567
2568 // Close the database
2569 require.NoError(t, db.Close())
2570
2571 // Verify no hint files are created
2572 fileIDs := enumerateDataFilesInDir(opts.Dir)
2573 for _, fileID := range fileIDs {
2574 hintPath := getHintPath(fileID, opts.Dir)
2575 _, err := os.Stat(hintPath)
2576 if err == nil {
2577 t.Errorf("Hint file %s should not exist when EnableHintFile is false", hintPath)
2578 }
2579 }
2580
2581 // Reopen the database - it should scan data files
2582 db, err = Open(opts)
2583 require.NoError(t, err)
2584
2585 // Verify all data is correctly recovered
2586 for i := 0; i < n; i++ {
2587 txGet(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), nil)
2588 }
2589
2590 require.NoError(t, db.Close())
2591 removeDir(opts.Dir)
2592}
2593
2594func TestDB_Watch(t *testing.T) {
2595 t.Run("db btree watch key and receive message", func(t *testing.T) {

Callers

nothing calls this directly

Calls 10

GetTestBytesFunction · 0.92
removeDirFunction · 0.85
OpenFunction · 0.85
txCreateBucketFunction · 0.85
txPutFunction · 0.85
enumerateDataFilesInDirFunction · 0.85
getHintPathFunction · 0.85
txGetFunction · 0.85
MergeMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected