forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
122648: workload: patch tpcc nondeterministic behavior with using set seed r=msbutler a=kev-cao The tpcc workload would have non-deterministic behavior when using a set seed as parts of the workload would seed the random generators using unix time instead of the provided seed. Additionally, queries were time based, so the time the workload would run would affect query output. To fix this, added the option to provide a fake time that would artificially increase. Epic: none Release note: none Co-authored-by: Kevin Cao <[email protected]>
- Loading branch information
Showing
9 changed files
with
108 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ go_library( | |
"random.go", | ||
"result.go", | ||
"stock_level.go", | ||
"timeutil.go", | ||
"tpcc.go", | ||
"worker.go", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package tpcc | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/util/syncutil" | ||
"github.com/cockroachdb/cockroach/pkg/util/timeutil" | ||
"golang.org/x/exp/rand" | ||
) | ||
|
||
type tpccTime struct { | ||
syncutil.Mutex | ||
fakeTime time.Time | ||
stepMax time.Duration | ||
rng *rand.Rand | ||
} | ||
|
||
func (t *tpccTime) Now() time.Time { | ||
if t.fakeTime.IsZero() { | ||
return timeutil.Now() | ||
} | ||
|
||
t.Lock() | ||
defer t.Unlock() | ||
t.fakeTime = t.fakeTime.Add( | ||
time.Duration(t.rng.Float64()*t.stepMax.Seconds()) * time.Second, | ||
) | ||
return t.fakeTime | ||
} | ||
|
||
func newTpccTime(fakeStartTime time.Time, stepMax time.Duration, seed uint64) *tpccTime { | ||
rng := rand.New(new(rand.LockedSource)) | ||
rng.Seed(seed) | ||
|
||
return &tpccTime{ | ||
fakeTime: fakeStartTime, | ||
stepMax: stepMax, | ||
rng: rng, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters