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

Function TestHintFileIntegration_ConcurrentOperations

hintfile_integration_test.go:446–516  ·  view source on GitHub ↗

TestHintFileIntegration_ConcurrentOperations tests hint files with concurrent operations

(t *testing.T)

Source from the content-addressed store, hash-verified

444
445// TestHintFileIntegration_ConcurrentOperations tests hint files with concurrent operations
446func TestHintFileIntegration_ConcurrentOperations(t *testing.T) {
447 if testing.Short() {
448 t.Skip("Skipping concurrent test in short mode")
449 }
450
451 runForMergeModes(t, func(t *testing.T, mode mergeTestMode) {
452 opts := DefaultOptions
453 opts.SegmentSize = 64 * KB
454 opts.Dir = filepath.Join(t.TempDir(), fmt.Sprintf("test-hintfile-concurrent-%s", mode.name))
455 opts.EnableHintFile = true
456 opts.EnableMergeV2 = mode.enableMergeV2
457
458 removeDir(opts.Dir)
459
460 db, err := Open(opts)
461 require.NoError(t, err)
462
463 bucket := "bucket"
464 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
465
466 // Perform concurrent writes
467 done := make(chan bool, 20)
468 for i := 0; i < 20; i++ {
469 go func(id int) {
470 for j := 0; j < 100; j++ {
471 key := testutils.GetTestBytes(id*100 + j)
472 value := testutils.GetTestBytes(id*100 + j)
473 txPut(t, db, bucket, key, value, Persistent, nil, nil)
474 }
475 done <- true
476 }(i)
477 }
478
479 // Wait for all writes to complete
480 for i := 0; i < 20; i++ {
481 <-done
482 }
483
484 // Perform merge
485 require.NoError(t, db.Merge())
486
487 // Verify hint files are created for all merged files
488 sets := collectMergeFileSets(t, opts.Dir)
489 idsToCheck := dataFileIDsForMode(mode, sets)
490 require.Greater(t, len(idsToCheck), 0)
491
492 for _, fid := range idsToCheck {
493 hintPath := getHintPath(fid, opts.Dir)
494 _, err = os.Stat(hintPath)
495 require.NoError(t, err, "Hint file should exist after merge for file %d", fid)
496 }
497
498 require.NoError(t, db.Close())
499
500 // Restart and verify all data
501 db, err = Open(opts)
502 require.NoError(t, err)
503

Callers

nothing calls this directly

Calls 13

GetTestBytesFunction · 0.92
runForMergeModesFunction · 0.85
removeDirFunction · 0.85
OpenFunction · 0.85
txCreateBucketFunction · 0.85
txPutFunction · 0.85
collectMergeFileSetsFunction · 0.85
dataFileIDsForModeFunction · 0.85
getHintPathFunction · 0.85
txGetFunction · 0.85
MergeMethod · 0.80
SkipMethod · 0.65

Tested by

no test coverage detected