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

Function TestDB_HintFileMissingFallback

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

Source from the content-addressed store, hash-verified

2230}
2231
2232func TestDB_HintFileMissingFallback(t *testing.T) {
2233 bucket := "bucket"
2234 opts := DefaultOptions
2235 opts.SegmentSize = KB
2236 opts.Dir = filepath.Join(t.TempDir(), "test-hintfile-missing")
2237 opts.EnableHintFile = true
2238
2239 // Clean the test directory at the start
2240 removeDir(opts.Dir)
2241
2242 // Create a database with some data
2243 db, err := Open(opts)
2244 require.NoError(t, err)
2245 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
2246
2247 // Add some data
2248 n := 300
2249 for i := 0; i < n; i++ {
2250 txPut(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), Persistent, nil, nil)
2251 }
2252
2253 // Perform merge to create hint files
2254 require.NoError(t, db.Merge())
2255
2256 // Close the database
2257 require.NoError(t, db.Close())
2258
2259 // Remove hint files to simulate missing hint files
2260 fileIDs := enumerateDataFilesInDir(opts.Dir)
2261 for _, fileID := range fileIDs {
2262 hintPath := getHintPath(fileID, opts.Dir)
2263 _ = os.Remove(hintPath)
2264 }
2265
2266 // Reopen the database - it should fall back to scanning data files
2267 db, err = Open(opts)
2268 require.NoError(t, err)
2269
2270 // Verify all data is correctly recovered
2271 for i := 0; i < n; i++ {
2272 txGet(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), nil)
2273 }
2274
2275 // Verify record count
2276 dbCnt, err := db.getRecordCount()
2277 require.NoError(t, err)
2278 require.Equal(t, int64(n), dbCnt)
2279
2280 require.NoError(t, db.Close())
2281 removeDir(opts.Dir)
2282}
2283
2284// enumerateDataFilesInDir returns all data file IDs in the directory
2285func enumerateDataFilesInDir(dir string) []int64 {

Callers

nothing calls this directly

Calls 12

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
getRecordCountMethod · 0.80
CloseMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected