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

Function TestHintFileIntegration_MultipleMerges

hintfile_integration_test.go:188–273  ·  view source on GitHub ↗

TestHintFileIntegration_MultipleMerges tests multiple merge operations

(t *testing.T)

Source from the content-addressed store, hash-verified

186
187// TestHintFileIntegration_MultipleMerges tests multiple merge operations
188func TestHintFileIntegration_MultipleMerges(t *testing.T) {
189 runForMergeModes(t, func(t *testing.T, mode mergeTestMode) {
190 bucket := "bucket"
191 opts := DefaultOptions
192 opts.SegmentSize = 32 * KB // Smaller segment size to trigger more merges
193 opts.Dir = filepath.Join(t.TempDir(), fmt.Sprintf("test-hintfile-multi-merge-%s", mode.name))
194 opts.EnableHintFile = true
195 opts.EnableMergeV2 = mode.enableMergeV2
196
197 removeDir(opts.Dir)
198
199 db, err := Open(opts)
200 require.NoError(t, err)
201 txCreateBucket(t, db, DataStructureBTree, bucket, nil)
202
203 // Perform multiple rounds of write->delete->merge
204 for round := 0; round < 3; round++ {
205 // Write data
206 start := round * 500
207 end := (round + 1) * 500
208 for i := start; i < end; i++ {
209 txPut(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), Persistent, nil, nil)
210 }
211
212 // Delete some data
213 for i := start; i < start+100; i++ {
214 txDel(t, db, bucket, testutils.GetTestBytes(i), nil)
215 }
216
217 // Perform merge
218 require.NoError(t, db.Merge())
219
220 // Verify hint files are created for all merged files
221 sets := collectMergeFileSets(t, opts.Dir)
222 idsToCheck := dataFileIDsForMode(mode, sets)
223 require.Greater(t, len(idsToCheck), 0)
224
225 // Check that hint files exist for all merged files
226 for _, fid := range idsToCheck {
227 hintPath := getHintPath(fid, opts.Dir)
228 _, err = os.Stat(hintPath)
229 require.NoError(t, err, "Hint file should exist after merge for file %d", fid)
230 }
231 }
232
233 // Verify all data is correct
234 for round := 0; round < 3; round++ {
235 start := round * 500
236 end := (round + 1) * 500
237
238 // Check deleted data
239 for i := start; i < start+100; i++ {
240 txGet(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), ErrKeyNotFound)
241 }
242
243 // Check remaining data
244 for i := start + 100; i < end; i++ {
245 txGet(t, db, bucket, testutils.GetTestBytes(i), testutils.GetTestBytes(i), nil)

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
txDelFunction · 0.85
collectMergeFileSetsFunction · 0.85
dataFileIDsForModeFunction · 0.85
getHintPathFunction · 0.85
txGetFunction · 0.85
MergeMethod · 0.80

Tested by

no test coverage detected