Skip to content

Commit a59328e

Browse files
craig[bot]stevendanna
andcommitted
157210: util,log: make util.EveryN generic r=yuzefovich a=stevendanna This changes util.EveryN to a generic function and then - modifies log.EveryN to allow use a crtime.Mono instead of a time.Time. - updates most callers that were easy to update to use util.EveryMono We might consider removing the time.Time version of EveryN, but it is still useful in a couple of places. Epic: none Release note: None Co-authored-by: Steven Danna <[email protected]>
2 parents 4c8e2ec + cdc3b58 commit a59328e

File tree

27 files changed

+89
-50
lines changed

27 files changed

+89
-50
lines changed

pkg/backup/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ go_library(
157157
"//pkg/util/tracing",
158158
"//pkg/util/tracing/tracingpb",
159159
"//pkg/util/uuid",
160+
"@com_github_cockroachdb_crlib//crtime",
160161
"@com_github_cockroachdb_errors//:errors",
161162
"@com_github_cockroachdb_logtags//:logtags",
162163
"@com_github_cockroachdb_pebble//:pebble",

pkg/backup/restore_job.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import (
7979
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
8080
"github.com/cockroachdb/cockroach/pkg/util/tracing"
8181
"github.com/cockroachdb/cockroach/pkg/util/uuid"
82+
"github.com/cockroachdb/crlib/crtime"
8283
"github.com/cockroachdb/errors"
8384
"github.com/cockroachdb/pebble"
8485
)
@@ -215,7 +216,7 @@ func restoreWithRetry(
215216
// dying), so if we receive a retryable error, re-plan and retry the restore.
216217
retryOpts, progThreshold := getRetryOptionsAndProgressThreshold(execCtx)
217218
logRate := restoreRetryLogRate.Get(&execCtx.ExecCfg().Settings.SV)
218-
logThrottler := util.Every(logRate)
219+
logThrottler := util.EveryMono(logRate)
219220
var (
220221
res roachpb.RowCount
221222
err error
@@ -255,7 +256,7 @@ func restoreWithRetry(
255256

256257
log.Dev.Warningf(ctx, "encountered retryable error: %+v", err)
257258

258-
if logThrottler.ShouldProcess(timeutil.Now()) {
259+
if logThrottler.ShouldProcess(crtime.NowMono()) {
259260
// We throttle the logging of errors to the jobs messages table to avoid
260261
// flooding the table during the hot loop of a retry.
261262
if err := execCtx.ExecCfg().InternalDB.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {

pkg/ccl/changefeedccl/cdcevent/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ go_library(
4343
"//pkg/util/json",
4444
"//pkg/util/log",
4545
"//pkg/util/protoutil",
46+
"@com_github_cockroachdb_crlib//crtime",
4647
"@com_github_cockroachdb_errors//:errors",
4748
"@com_github_cockroachdb_redact//:redact",
4849
],

pkg/ccl/changefeedccl/cdcevent/rowfetcher_cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/cockroachdb/cockroach/pkg/util/encoding"
2929
"github.com/cockroachdb/cockroach/pkg/util/hlc"
3030
"github.com/cockroachdb/cockroach/pkg/util/log"
31+
"github.com/cockroachdb/crlib/crtime"
3132
"github.com/cockroachdb/errors"
3233
)
3334

@@ -318,7 +319,7 @@ func (c *rowFetcherCache) RowFetcherForColumnFamily(
318319
Alloc: &c.a,
319320
Spec: &spec,
320321
TraceKV: c.rfArgs.traceKV,
321-
TraceKVEvery: &util.EveryN{N: c.rfArgs.traceKVLogFrequency},
322+
TraceKVEvery: &util.EveryN[crtime.Mono]{N: c.rfArgs.traceKVLogFrequency},
322323
},
323324
); err != nil {
324325
return nil, nil, err

pkg/ccl/changefeedccl/changefeed_processors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ const (
11161116
)
11171117

11181118
// slowLogEveryN rate-limits the logging of slow spans
1119-
var slowLogEveryN = log.Every(slowSpanMaxFrequency)
1119+
var slowLogEveryN = util.Every(slowSpanMaxFrequency)
11201120

11211121
// jobState encapsulates changefeed job state.
11221122
type jobState struct {
@@ -2434,7 +2434,7 @@ type saveRateConfig struct {
24342434
// duration it takes to save progress.
24352435
type saveRateLimiter struct {
24362436
config saveRateConfig
2437-
warnEveryN util.EveryN
2437+
warnEveryN util.EveryN[time.Time]
24382438

24392439
clock timeutil.TimeSource
24402440

pkg/cmd/roachtest/roachtestutil/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func SetDefaultAdminUIPort(c cluster.Cluster, opts *install.StartOpts) {
5959
// recently a given log message has been emitted so that it can determine
6060
// whether it's worth logging again.
6161
type EveryN struct {
62-
util.EveryN
62+
util.EveryN[time.Time]
6363
}
6464

6565
// Every is a convenience constructor for an EveryN object that allows a log

pkg/kv/kvserver/raft_log_queue.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
2727
"github.com/cockroachdb/cockroach/pkg/util/log"
2828
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
29+
"github.com/cockroachdb/crlib/crtime"
2930
"github.com/cockroachdb/errors"
3031
"github.com/cockroachdb/redact"
3132
)
@@ -147,7 +148,7 @@ type raftLogQueue struct {
147148
*baseQueue
148149
db *kv.DB
149150

150-
logSnapshots util.EveryN
151+
logSnapshots util.EveryN[crtime.Mono]
151152
}
152153

153154
var _ queueImpl = &raftLogQueue{}
@@ -162,7 +163,7 @@ var _ queueImpl = &raftLogQueue{}
162163
func newRaftLogQueue(store *Store, db *kv.DB) *raftLogQueue {
163164
rlq := &raftLogQueue{
164165
db: db,
165-
logSnapshots: util.Every(10 * time.Second),
166+
logSnapshots: util.EveryMono(10 * time.Second),
166167
}
167168
rlq.baseQueue = newBaseQueue(
168169
"raftlog", rlq, store,
@@ -689,7 +690,7 @@ func (rlq *raftLogQueue) process(
689690
return false, nil
690691
}
691692

692-
if n := decision.NumNewRaftSnapshots(); log.V(1) || n > 0 && rlq.logSnapshots.ShouldProcess(timeutil.Now()) {
693+
if n := decision.NumNewRaftSnapshots(); log.V(1) || n > 0 && rlq.logSnapshots.ShouldProcess(crtime.NowMono()) {
693694
log.KvExec.Infof(ctx, "%v", redact.Safe(decision.String()))
694695
log.KvDistribution.Infof(ctx, "%v", redact.Safe(decision.String()))
695696
} else {

pkg/kv/kvserver/replica.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import (
5959
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
6060
"github.com/cockroachdb/cockroach/pkg/util/tracing"
6161
"github.com/cockroachdb/cockroach/pkg/util/uuid"
62+
"github.com/cockroachdb/crlib/crtime"
6263
"github.com/cockroachdb/errors"
6364
"github.com/cockroachdb/redact"
6465
"github.com/kr/pretty"
@@ -1056,7 +1057,7 @@ type Replica struct {
10561057
// information and without explicit throttling some replicas will offer once
10571058
// per applied Raft command, which is silly and also clogs up the queues'
10581059
// semaphores.
1059-
splitQueueThrottle, mergeQueueThrottle util.EveryN
1060+
splitQueueThrottle, mergeQueueThrottle util.EveryN[crtime.Mono]
10601061

10611062
// loadBasedSplitter keeps information about load-based splitting.
10621063
loadBasedSplitter split.Decider

pkg/kv/kvserver/replica_app_batch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/cockroachdb/cockroach/pkg/util/log"
2121
"github.com/cockroachdb/cockroach/pkg/util/log/logcrash"
2222
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
23+
"github.com/cockroachdb/crlib/crtime"
2324
"github.com/cockroachdb/errors"
2425
"github.com/cockroachdb/redact"
2526
)
@@ -688,7 +689,7 @@ func (b *replicaAppBatch) ApplyToStateMachine(ctx context.Context) error {
688689
// Record the number of keys written to the replica.
689690
b.r.loadStats.RecordWriteKeys(float64(b.ab.numMutations))
690691

691-
now := timeutil.Now()
692+
now := crtime.NowMono()
692693
if needsSplitBySize && r.splitQueueThrottle.ShouldProcess(now) {
693694
r.store.splitQueue.MaybeAddAsync(ctx, r, r.store.Clock().NowAsClockTimestamp())
694695
}

pkg/kv/kvserver/replica_init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ func newUninitializedReplicaWithoutRaftGroup(store *Store, id roachpb.FullReplic
242242
store.TestingKnobs().DisableSyncLogWriteToss,
243243
}
244244

245-
r.splitQueueThrottle = util.Every(splitQueueThrottleDuration)
246-
r.mergeQueueThrottle = util.Every(mergeQueueThrottleDuration)
245+
r.splitQueueThrottle = util.EveryMono(splitQueueThrottleDuration)
246+
r.mergeQueueThrottle = util.EveryMono(mergeQueueThrottleDuration)
247247

248248
onTrip := func() {
249249
telemetry.Inc(telemetryTripAsync)

0 commit comments

Comments
 (0)