Repository: prometheus/prometheus
File: tsdb/db_test.go (Go)

Code before:
		mmapDir := mmappedChunksDir(db.head.opts.ChunkDirRoot)
		files, err := os.ReadDir(mmapDir)
		require.NoError(t, err)

		fnames := make([]string, 0, len(files))
		for _, f := range files {
			fnames = append(fnames, f.Name())
		}

		for _, f := range contains {
			require.Contains(t, fnames, f)
		}
		for _, f := range notContains {
			require.NotContains(t, fnames, f)
		}
	}

	// Add in-order samples until ready for compaction.
	addSamples(301, 500)

	// Check that m-map files gets deleted properly after compactions.

	db.head.mmapHeadChunks()
	checkMmapFileContents([]string{"000001", "000002"}, nil)

	// NOTE: We are investigating flaky errors from this compaction on x383 architecture. Compaction panics due to chunk
	// mapper fatal error. Recover here to understand the error cause. Leaving panic recovery to test causes deadlock
	// as t.Cleanup tries to close DB with open locks.
	// See https://github.com/prometheus/prometheus/issues/17941#issuecomment-3846381263
	require.NotPanics(t, func() {
		require.NoError(t, db.Compact(ctx))
	})

	checkMmapFileContents([]string{"000002"}, []string{"000001"})
	require.Nil(t, ms.ooo, "OOO mmap chunk was not compacted")

	addSamples(501, 650)
	db.head.mmapHeadChunks()
	checkMmapFileContents([]string{"000002", "000003"}, []string{"000001"})
	require.NoError(t, db.Compact(ctx))
	checkMmapFileContents(nil, []string{"000001", "000002", "000003"})

	// Verify that WBL is empty.
	files, err := os.ReadDir(db.head.wbl.Dir())
	require.NoError(t, err)
	require.Len(t, files, 1) // Last empty file after compaction.
	finfo, err := files[0].Info()
	require.NoError(t, err)
	require.Equal(t, int64(0), finfo.Size())
}


Review comment (suggestion):
x86?
```suggestion
	// NOTE: We are investigating flaky errors from this compaction on x86 architecture. Compaction panics due to chunk
```

Code after:
		mmapDir := mmappedChunksDir(db.head.opts.ChunkDirRoot)
		files, err := os.ReadDir(mmapDir)
		require.NoError(t, err)

		fnames := make([]string, 0, len(files))
		for _, f := range files {
			fnames = append(fnames, f.Name())
		}

		for _, f := range contains {
			require.Contains(t, fnames, f)
		}
		for _, f := range notContains {
			require.NotContains(t, fnames, f)
		}
	}

	// Add in-order samples until ready for compaction.
	addSamples(301, 500)

	// Check that m-map files gets deleted properly after compactions.

	db.head.mmapHeadChunks()
	checkMmapFileContents([]string{"000001", "000002"}, nil)

	// NOTE: We are investigating flaky errors from this compaction on i386 architecture. Compaction panics due to chunk
	// mapper fatal error. Recover here to understand the error cause. Leaving panic recovery to test causes deadlock
	// as t.Cleanup tries to close DB with open locks.
	// See https://github.com/prometheus/prometheus/issues/17941#issuecomment-3846381263
	require.NotPanics(t, func() {
		require.NoError(t, db.Compact(ctx))
	})

	checkMmapFileContents([]string{"000002"}, []string{"000001"})
	require.Nil(t, ms.ooo, "OOO mmap chunk was not compacted")

	addSamples(501, 650)
	db.head.mmapHeadChunks()
	checkMmapFileContents([]string{"000002", "000003"}, []string{"000001"})

	// NOTE: We are investigating flaky errors from this compaction on i386 architecture. Compaction panics due to chunk
	// mapper fatal error. Recover here to understand the error cause. Leaving panic recovery to test causes deadlock
	// as t.Cleanup tries to close DB with open locks.
	// See https://github.com/prometheus/prometheus/issues/17941#issuecomment-3846381263
	require.NotPanics(t, func() {
		require.NoError(t, db.Compact(ctx))
	})
	checkMmapFileContents(nil, []string{"000001", "000002", "000003"})

	// Verify that WBL is empty.
	files, err := os.ReadDir(db.head.wbl.Dir())