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

Function TestDB_HintFileFastRecovery

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

Source from the content-addressed store, hash-verified

2181}
2182
2183func TestDB_HintFileFastRecovery(t *testing.T) {
2184 bucket := "bucket"
2185 opts := DefaultOptions
2186 opts.SegmentSize = KB
2187 opts.Dir = filepath.Join(t.TempDir(), "test-hintfile-recovery")
2188 opts.EnableHintFile = true
2189
2190 // Clean the test directory at the start
2191 removeDir(opts.Dir)
2192
2193 for _, idxMode := range []EntryIdxMode{HintKeyValAndRAMIdxMode, HintKeyAndRAMIdxMode} {
2194 opts.EntryIdxMode = idxMode
2195
2196 // Create a database with some data
2197 db, err := Open(opts)
2198 require.NoError(t, err)
2199 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
2200
2201 // Add some data
2202 n := 500
2203 for i := 0; i < n; i++ {
2204 txPut(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), Persistent, nil, nil)
2205 }
2206
2207 // Perform merge to create hint files
2208 require.NoError(t, db.Merge())
2209
2210 // Close the database
2211 require.NoError(t, db.Close())
2212
2213 // Reopen the database - it should use hint files for fast recovery
2214 db, err = Open(opts)
2215 require.NoError(t, err)
2216
2217 // Verify all data is correctly recovered
2218 for i := 0; i < n; i++ {
2219 txGet(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), nil)
2220 }
2221
2222 // Verify record count
2223 dbCnt, err := db.getRecordCount()
2224 require.NoError(t, err)
2225 require.Equal(t, int64(n), dbCnt)
2226
2227 require.NoError(t, db.Close())
2228 removeDir(opts.Dir)
2229 }
2230}
2231
2232func TestDB_HintFileMissingFallback(t *testing.T) {
2233 bucket := "bucket"

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected