Skip to content

Commit

Permalink
storage: don't cache benchmark fixtures in metamorphic builds
Browse files Browse the repository at this point in the history
In CI, we sometimes run benchmarks in metamorphic builds to ensure the
benchmarks pass. We don't want to cache the fixtures generated by these runs,
because we may end up caching fixtures that reflect metamorphic values. This
can lead to very non-deterministic behavior in the benchmarks depending on what
metamorphic settings were active when the fixture was generated.

Epic: none
Release note: none
Informs #135114.
  • Loading branch information
jbowens committed Nov 13, 2024
1 parent 4b1ca13 commit 0dcc3fa
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/storage/bench_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/encoding"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/metamorphic"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/pebble/vfs"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -69,9 +70,23 @@ func getInitialStateEngine(
ctx context.Context, b *testing.B, initial initialState, inMemory bool,
) Engine {
name := strings.Join(initial.Key(), "-")
dir := testfixtures.ReuseOrGenerate(b, name, func(dir string) {

// In CI, we sometimes run benchmarks in metamorphic builds to ensure the
// benchmarks pass. We don't want to cache the fixtures generated by these
// runs, because we may end up caching fixtures that reflect metamorphic
// values. This can lead to very non-deterministic behavior in the
// benchmarks depending on what metamorphic settings were active when the
// fixture was generated.
var dir string
if metamorphic.IsMetamorphicBuild() {
b.Log("running in metamorphic build; ignoring existing fixtures and not caching new ones")
dir = b.TempDir()
buildInitialState(ctx, b, initial, dir)
})
} else {
dir = testfixtures.ReuseOrGenerate(b, name, func(dir string) {
buildInitialState(ctx, b, initial, dir)
})
}
dataDir := filepath.Join(dir, "data")

opts := append([]ConfigOption{
Expand Down

0 comments on commit 0dcc3fa

Please sign in to comment.